Skip to content

Commit

Permalink
Merge pull request #147 from elwoodxblues/fix-django-1.11-compatibilty
Browse files Browse the repository at this point in the history
Fix compatibility issues with Django 1.11
  • Loading branch information
Marcin Gębala authored Oct 4, 2017
2 parents 3f8c7b0 + 76ec75a commit afa3660
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 76 deletions.
59 changes: 29 additions & 30 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
language: python
sudo: false
install:
- pip install tox codecov
script:
- tox
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
env:
- TOXENV=py27-django18
- TOXENV=py27-django110
- TOXENV=py27-django111
- TOXENV=py34-django18
- TOXENV=py34-django110
- TOXENV=py34-django111
- TOXENV=py34-django_master
- TOXENV=py35-django18
- TOXENV=py35-django110
- TOXENV=py35-django111
- TOXENV=py35-django_master
- DJANGO="1.11"
- DJANGO="2.0"
- DJANGO="master"
matrix:
allow_failures:
- env: TOXENV=py27-django111
- env: TOXENV=py34-django111
- env: TOXENV=py35-django111
- env: TOXENV=py34-django_master
- env: TOXENV=py35-django_master
after_success:
- codecov
addons:
apt:
sources:
- deadsnakes
packages:
- python3.5
- python3.5-dev
- python: "3.4"
env: DJANGO="2.0"
- python: "3.4"
env: DJANGO="master"
- python: "3.5"
env: DJANGO="2.0"
- python: "3.5"
env: DJANGO="master"
- python: "3.6"
env: DJANGO="2.0"
- python: "3.6"
env: DJANGO="master"
exclude:
- python: "2.7"
env: DJANGO="2.0"
- python: "2.7"
env: DJANGO="master"
after_success: codecov
install: pip install tox-travis codecov
script: tox
3 changes: 2 additions & 1 deletion payments/cybersource/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
class FingerprintWidget(forms.HiddenInput):

def render(self, name, value, attrs=None):
final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
final_attrs = dict(attrs or {}, type=self.input_type, name=name)
final_attrs.update(self.attrs)
final_attrs['session_id'] = value
return render_to_string(
'payments/cybersource_fingerprint.html', final_attrs)
Expand Down
10 changes: 5 additions & 5 deletions payments/stripe/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ def __init__(self, provider, payment, *args, **kwargs):
def render(self, name, value, attrs=None):
if value is None:
value = ''
final_attrs = self.build_attrs(
attrs, src="https://checkout.stripe.com/checkout.js")
final_attrs = dict(attrs or {}, src='https://checkout.stripe.com/checkout.js')
final_attrs.update(self.attrs)
del final_attrs['id']
if value != '':
# Only add the 'value' attribute if a value is non-empty.
Expand All @@ -46,6 +46,6 @@ class Media:
js = ['https://js.stripe.com/v2/',
'js/payments/stripe.js']

def build_attrs(self, extra_attrs=None, **kwargs):
extra_attrs = dict(extra_attrs or {}, id='id_stripe_token')
return super(StripeWidget, self).build_attrs(extra_attrs, **kwargs)
def __init__(self, attrs=None):
attrs = dict(attrs or {}, id='id_stripe_token')
super(StripeWidget, self).__init__(attrs)
6 changes: 5 additions & 1 deletion payments/templates/payments/credit_card_expiry_widget.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<span style="white-space: nowrap">
{{ month }} / {{ year }}
{% with widget.subwidgets.0 as month %}
{% with widget.subwidgets.1 as year %}
{% include month.template_name with widget=month %} / {% include year.template_name with widget=year %}
{% endwith %}
{% endwith %}
</span>
5 changes: 5 additions & 0 deletions payments/templates/payments/sensitive_select.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<select {% include "django/forms/widgets/attrs.html" %}>{% for group_name, group_choices, group_index in widget.optgroups %}{% if group_name %}
<optgroup label="{{ group_name }}">{% endif %}{% for option in group_choices %}
{% include option.template_name with widget=option %}{% endfor %}{% if group_name %}
</optgroup>{% endif %}{% endfor %}
</select>
1 change: 1 addition & 0 deletions payments/templates/payments/sensitive_text_input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<input type="{{ widget.type }}" {% if widget.value != None %} value="{{ widget.value|stringformat:'s' }}"{% endif %}{% include "django/forms/widgets/attrs.html" %} />
40 changes: 5 additions & 35 deletions payments/widgets.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
import re

from django import VERSION as DJANGO_VERSION
from django.forms.utils import flatatt
from django.forms.widgets import TextInput, MultiWidget, Select
from django.template.loader import render_to_string
from django.utils.encoding import force_text
from django.utils.html import format_html
from django.utils.safestring import mark_safe


class CreditCardNumberWidget(TextInput):
Expand All @@ -28,43 +22,19 @@ def render(self, name, value, attrs=None):
# http://www.djangosnippets.org/snippets/907/
class CreditCardExpiryWidget(MultiWidget):
"""MultiWidget for representing credit card expiry date."""

template_name = 'payments/credit_card_expiry_widget.html'

def decompress(self, value):
if value:
return [value.month, value.year]
else:
return [None, None]

def format_output(self, rendered_widgets):
ctx = {'month': rendered_widgets[0], 'year': rendered_widgets[1]}
return render_to_string('payments/credit_card_expiry_widget.html', ctx)


class SensitiveTextInput(TextInput):

def render(self, name, value, attrs=None):
# Explicitly skip parent implementation and exclude
# 'name' from attrs
if value is None:
value = ''
final_attrs = self.build_attrs(attrs, type=self.input_type)
if value != '':
# Only add the 'value' attribute if a value is non-empty.
final_attrs['value'] = force_text(self.format_value(value))
return format_html('<input{} />', flatatt(final_attrs))
template_name = 'payments/sensitive_text_input.html'


class SensitiveSelect(Select):

def render(self, name, value, attrs=None):
if value is None:
value = ''
final_attrs = self.build_attrs(attrs)
output = [format_html('<select{}>', flatatt(final_attrs))]
if DJANGO_VERSION <= (1, 10, 0):
options = self.render_options([], [value])
else:
options = self.render_options([value])
if options:
output.append(options)
output.append('</select>')
return mark_safe('\n'.join(output))
template_name = 'payments/sensitive_select.html'
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

REQUIREMENTS = [
'braintree>=3.14.0',
'Django>=1.5',
'Django>=1.11',
'cryptography>=1.1.0',
'PyJWT>=1.3.0',
'requests>=1.2.0',
Expand Down Expand Up @@ -69,6 +69,7 @@ def run_tests(self):
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Framework :: Django',
'Topic :: Software Development :: Libraries :: Application Frameworks',
'Topic :: Software Development :: Libraries :: Python Modules'],
Expand Down
19 changes: 16 additions & 3 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
[tox]
envlist = py{27,34,35}-django{18,110,111} py{34,35}-django_master
envlist = py27-django111, py{34,35,36}-django{111,20,_master}

[testenv]
usedevelop=True
deps=
coverage
django18: django>=1.8,<1.9a0
django110: django>=1.10,<1.11a0
django111: django>=1.11a1,<1.12
django20: Django>=2.0a1,<2.1
django_master: https://github.com/django/django/archive/master.tar.gz
mock
pytest
Expand All @@ -17,3 +16,17 @@ commands=coverage run setup.py test
[pytest]
testpaths = payments
DJANGO_SETTINGS_MODULE = test_settings

[travis]
python =
2.7: py27
3.4: py34
3.5: py35
3.6: py36
unignore_outcomes = True

[travis:env]
DJANGO =
1.11: django111
2.0: django2.0
master: django_master

0 comments on commit afa3660

Please sign in to comment.