From 8b3995ac48916dcc5fffee3b5085312beb18befd Mon Sep 17 00:00:00 2001 From: Mikhail Podgurskiy Date: Thu, 7 Apr 2016 17:30:51 +0600 Subject: [PATCH] Add django 1.8/1.9 compatibility. Drop unsupported django versions support --- .travis.yml | 16 ++---- parsley/tests/forms.py | 1 + parsley/widgets.py | 22 +++++--- runtests.py | 4 +- setup.py | 4 +- tox.ini | 116 ++++------------------------------------- 6 files changed, 32 insertions(+), 131 deletions(-) diff --git a/.travis.yml b/.travis.yml index c821800..89e7f1a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,14 +3,11 @@ language: python python: - 2.7 - 3.4 + - 3.5 env: - - DJANGO='Django>=1.3,<1.4' - - DJANGO='Django>=1.4,<1.5' - - DJANGO='Django>=1.5,<1.6' - - DJANGO='Django>=1.6,<1.7' -# - DJANGO='Django>=1.7,<1.8' -# - DJANGO='https://github.com/django/django/tarball/stable/1.8.x' + - DJANGO='Django>=1.8,<1.9' + - DJANGO='Django>=1.9,<1.10' install: - pip install --use-mirrors $DJANGO @@ -19,10 +16,3 @@ install: script: coverage run setup.py test after_success: coveralls - -matrix: - exclude: - - python: 3.4 - env: DJANGO='Django>=1.3,<1.4' - - python: 3.4 - env: DJANGO='Django>=1.4,<1.5' diff --git a/parsley/tests/forms.py b/parsley/tests/forms.py index f886a43..6ac41c8 100644 --- a/parsley/tests/forms.py +++ b/parsley/tests/forms.py @@ -70,6 +70,7 @@ class FormWithWidgets(forms.Form): class StudentModelForm(forms.ModelForm): class Meta: model = Student + fields = '__all__' def __init__(self, *args, **kwargs): super(StudentModelForm, self).__init__(*args, **kwargs) diff --git a/parsley/widgets.py b/parsley/widgets.py index d45a7ee..1de904a 100644 --- a/parsley/widgets.py +++ b/parsley/widgets.py @@ -1,10 +1,16 @@ class ParsleyChoiceFieldRendererMixin(object): - def __iter__(self): - for i, choice in enumerate(self.choices): - yield self[i] + def __init__(self, name, value, attrs, choices): + self.name = name + self.value = value + self.attrs = attrs + self._choices = choices - def __getitem__(self, idx): - choice = self.choices[idx] - if idx == len(self.choices) - 1: - self.attrs["{prefix}-required".format(prefix=self.parsley_namespace)] = "true" - return super(ParsleyChoiceFieldRendererMixin, self).__getitem__(idx) + @property + def choices(self): + def choices_iter(): + choices_list = self._choices + for idx, choice in enumerate(choices_list): + if idx == len(choices_list) - 1: + self.attrs["{prefix}-required".format(prefix=self.parsley_namespace)] = "true" + yield choice + return choices_iter() diff --git a/runtests.py b/runtests.py index 3fdb1be..30913cb 100755 --- a/runtests.py +++ b/runtests.py @@ -27,7 +27,7 @@ if hasattr(django, 'setup'): django.setup() -from django.test.simple import DjangoTestSuiteRunner +from django.test.runner import DiscoverRunner def runtests(*test_args, **kwargs): @@ -35,7 +35,7 @@ def runtests(*test_args, **kwargs): test_args = ['parsley'] parent = dirname(abspath(__file__)) sys.path.insert(0, parent) - test_runner = DjangoTestSuiteRunner( + test_runner = DiscoverRunner( verbosity=kwargs.get('verbosity', 1), interactive=kwargs.get('interactive', False), failfast=kwargs.get('failfast')) diff --git a/setup.py b/setup.py index e3d0a4a..f981fdb 100644 --- a/setup.py +++ b/setup.py @@ -123,7 +123,7 @@ def find_package_data( "Framework :: Django", ], zip_safe=False, - install_requires=["Django>=1.3,<=1.8"], - tests_require=["Django>=1.3,<=1.7", "six"], + install_requires=["Django>=1.8"], + tests_require=["Django>=1.8", "six"], test_suite='runtests.runtests', ) diff --git a/tox.ini b/tox.ini index 68342b0..edc3c6b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,111 +1,15 @@ [tox] -envlist = - py26-1.3, py26-1.4, py26-1.5, py26-1.6, - py27-1.3, py27-1.4, py27-1.5, py27-1.6, py27-trunk, - py32-1.5, py32-1.6, py32-trunk, - py33-1.5, py33-1.6, py33-trunk, +envlist = py{27,34,35}-dj{18,19} +skipsdist = True [testenv] commands = coverage run -a setup.py test - - -[testenv:py26-1.3] -basepython = python2.6 -deps = - django == 1.3.7 - coverage == 3.6 - -[testenv:py26-1.4] -basepython = python2.6 -deps = - django == 1.4.2 - coverage == 3.6 - -[testenv:py26-1.5] -basepython = python2.6 -deps = - django == 1.5 - coverage == 3.6 - -[testenv:py26-1.6] -basepython = python2.6 -deps = - https://github.com/django/django/tarball/stable/1.6.x - coverage == 3.6 - -[testenv:py26-trunk] -basepython = python2.6 -deps = - https://github.com/django/django/tarball/master - coverage == 3.6 - - -[testenv:py27-1.3] -basepython = python2.7 -deps = - django == 1.3.7 - coverage == 3.6 - -[testenv:py27-1.4] -basepython = python2.7 -deps = - django == 1.4.2 - coverage == 3.6 - -[testenv:py27-1.5] -basepython = python2.7 -deps = - django == 1.5 - coverage == 3.6 - -[testenv:py27-1.6] -basepython = python2.7 -deps = - https://github.com/django/django/tarball/stable/1.6.x - coverage == 3.6 - -[testenv:py27-trunk] -basepython = python2.7 -deps = - https://github.com/django/django/tarball/master - coverage == 3.6 - - -[testenv:py32-1.5] -basepython = python3.2 -deps = - django == 1.5 - coverage == 3.6 - -[testenv:py32-1.6] -basepython = python3.2 -deps = - https://github.com/django/django/tarball/stable/1.6.x - coverage == 3.6 - -[testenv:py32-trunk] -basepython = python3.2 -deps = - https://github.com/django/django/tarball/master - coverage == 3.6 - - - -[testenv:py33-1.5] -basepython = python3.3 -deps = - django == 1.5 - coverage == 3.6 - -[testenv:py33-1.6] -basepython = python3.3 -deps = - https://github.com/django/django/tarball/stable/1.6.x - coverage == 3.6 - -[testenv:py33-trunk] -basepython = python3.3 -deps = - https://github.com/django/django/tarball/master - coverage == 3.6 +basepython = + py27: python2.7 + py34: python3.4 + py35: python3.5 +deps = + coverage>=4 + dj18: django==1.8.13 + dj19: django==1.9.7