Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop unsupported versions and Add new versions #90

Merged
merged 5 commits into from
Sep 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 8 additions & 61 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,80 +1,27 @@
language: python

python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
env:
- DJANGO_VERSION='Django>=1.4,<1.5'
- DJANGO_VERSION='Django>=1.5,<1.6'
- DJANGO_VERSION='Django>=1.6,<1.7'
- DJANGO_VERSION='Django>=1.7,<1.8'
- DJANGO_VERSION='Django>=1.8,<1.9'
- DJANGO_VERSION='Django>=1.9,<1.10'
- DJANGO_VERSION='Django>=1.10,<1.11'
- DJANGO_VERSION='Django>=1.11,<2.0'
- DJANGO_VERSION='Django>=2.0,<2.1'
- DJANGO_VERSION='Django>=2.1,<2.2'
- DJANGO_VERSION='https://github.com/django/django/archive/master.tar.gz'
matrix:
exclude:
- python: "2.6"
env: DJANGO_VERSION='Django>=1.7,<1.8'
- python: "2.6"
env: DJANGO_VERSION='Django>=1.8,<1.9'
- python: "2.6"
env: DJANGO_VERSION='Django>=1.9,<1.10'
- python: "2.6"
env: DJANGO_VERSION='Django>=1.10,<1.11'
- python: "2.6"
env: DJANGO_VERSION='Django>=1.11,<2.0'
- python: "2.6"
env: DJANGO_VERSION='https://github.com/django/django/archive/master.tar.gz'
- python: "2.7"
env: DJANGO_VERSION='https://github.com/django/django/archive/master.tar.gz'
- python: "3.3"
env: DJANGO_VERSION='Django>=1.4,<1.5'
- python: "3.3"
env: DJANGO_VERSION='Django>=1.5,<1.6'
- python: "3.3"
env: DJANGO_VERSION='Django>=1.9,<1.10'
- python: "3.3"
env: DJANGO_VERSION='Django>=1.10,<1.11'
- python: "3.3"
env: DJANGO_VERSION='Django>=1.11,<2.0'
- python: "3.3"
env: DJANGO_VERSION='Django>=2.0,<2.1'
- python: "2.7"
env: DJANGO_VERSION='Django>=2.1,<2.2'
- python: "2.7"
env: DJANGO_VERSION='https://github.com/django/django/archive/master.tar.gz'
- python: "3.4"
env: DJANGO_VERSION='Django>=1.4,<1.5'
- python: "3.4"
env: DJANGO_VERSION='Django>=1.5,<1.6'
- python: "3.4"
env: DJANGO_VERSION='Django>=1.6,<1.7'
- python: "3.4"
env: DJANGO_VERSION='Django>=2.1,<2.2'
- python: "2.7"
env: DJANGO_VERSION='https://github.com/django/django/archive/master.tar.gz'
- python: "3.5"
env: DJANGO_VERSION='Django>=1.4,<1.5'
- python: "3.5"
env: DJANGO_VERSION='Django>=1.5,<1.6'
- python: "3.5"
env: DJANGO_VERSION='Django>=1.6,<1.7'
- python: "3.5"
env: DJANGO_VERSION='Django>=1.7,<1.8'
- python: "3.6"
env: DJANGO_VERSION='Django>=1.4,<1.5'
- python: "3.6"
env: DJANGO_VERSION='Django>=1.5,<1.6'
- python: "3.6"
env: DJANGO_VERSION='Django>=1.6,<1.7'
- python: "3.6"
env: DJANGO_VERSION='Django>=1.7,<1.8'
- python: "3.6"
env: DJANGO_VERSION='Django>=1.8,<1.9'
- python: "3.6"
env: DJANGO_VERSION='Django>=1.9,<1.10'
- python: "3.6"
env: DJANGO_VERSION='Django>=1.10,<1.11'
allow_failures:
- env: DJANGO_VERSION='https://github.com/django/django/archive/master.tar.gz'

Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ A new model field and form field. With this you can get a multiple select from a

This egg is inspired by this `snippet <http://djangosnippets.org/snippets/1200/>`_.

Supported Python versions: 2.6, 2.7, 3.3+
Supported Python versions: 2.7, 3.4+

Supported Django versions: 1.4-1.11+
Supported Django versions: 1.11-2.0+

Installation
============
Expand Down
32 changes: 8 additions & 24 deletions example/app/test_msf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,8 @@
u = str


if VERSION < (1, 9):
def get_field(model, name):
return model._meta.get_field_by_name(name)[0]
else:
def get_field(model, name):
return model._meta.get_field(name)
def get_field(model, name):
return model._meta.get_field(name)


class MultiSelectTestCase(TestCase):
Expand Down Expand Up @@ -77,12 +73,8 @@ def test_values_list(self):
# call Field.from_db_field, it simply returns a Python representation
# of the data in the database (which in our case is a string of
# comma-separated values). The bug was fixed in Django 1.8+.
if VERSION >= (1, 6) and VERSION < (1, 8):
self.assertStringEqual(tag_list_list, [u('sex,work,happy')])
self.assertStringEqual(categories_list_list, [u('1,3,5')])
else:
self.assertListEqual(tag_list_list, [['sex', 'work', 'happy']])
self.assertListEqual(categories_list_list, [['1', '3', '5']])
self.assertListEqual(tag_list_list, [['sex', 'work', 'happy']])
self.assertListEqual(categories_list_list, [['1', '3', '5']])

def test_form(self):
form_class = modelform_factory(Book, fields=('title', 'tags', 'categories'))
Expand Down Expand Up @@ -139,26 +131,18 @@ def test_named_groups_form(self):
self.assertEqual(len(form_class.base_fields), 1)
form = form_class(initial={'published_in': ['BC', 'AK']})

expected_html = u("""<p><label for="id_published_in_0">Province or State:</label> <ul id="id_published_in"><li>Canada - Provinces<ul id="id_published_in_0"><li><label for="id_published_in_0_0"><input id="id_published_in_0_0" name="published_in" type="checkbox" value="AB" /> Alberta</label></li>\n"""
expected_html = u("""<p><label>Province or State:</label> <ul id="id_published_in"><li>Canada - Provinces<ul id="id_published_in_0"><li><label for="id_published_in_0_0"><input id="id_published_in_0_0" name="published_in" type="checkbox" value="AB" /> Alberta</label></li>\n"""
"""<li><label for="id_published_in_0_1"><input checked="checked" id="id_published_in_0_1" name="published_in" type="checkbox" value="BC" /> British Columbia</label></li></ul></li>\n"""
"""<li>USA - States<ul id="id_published_in_1"><li><label for="id_published_in_1_0"><input checked="checked" id="id_published_in_1_0" name="published_in" type="checkbox" value="AK" /> Alaska</label></li>\n"""
"""<li><label for="id_published_in_1_1"><input id="id_published_in_1_1" name="published_in" type="checkbox" value="AL" /> Alabama</label></li>\n"""
"""<li><label for="id_published_in_1_2"><input id="id_published_in_1_2" name="published_in" type="checkbox" value="AZ" /> Arizona</label></li></ul></li></ul></p>""")

actual_html = form.as_p()

if (1, 11) <= VERSION < (2, 0):
# Django 1.11+ does not assign 'for' attributes on labels if they
# are group labels
expected_html = expected_html.replace('label for="id_published_in_0"', 'label')

if VERSION < (1, 6):
# Django 1.6 renders the Python repr() for each group (eg: tuples
# with HTML entities), so we skip the test for that version
self.assertEqual(expected_html.replace('\n', ''), actual_html.replace('\n', ''))
if VERSION >= (2, 0):
expected_html = expected_html.replace('input checked="checked"', 'input checked')

if VERSION >= (1, 7):
self.assertHTMLEqual(expected_html, actual_html)
self.assertHTMLEqual(expected_html, actual_html)


class MultiSelectUtilsTestCase(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion example/app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from django.contrib.auth import login
from django.contrib.auth import get_user_model

from django.core.urlresolvers import reverse
from django.urls import reverse
from django.http import HttpResponseRedirect


Expand Down
40 changes: 15 additions & 25 deletions example/example/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,33 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this software. If not, see <http://www.gnu.org/licenses/>.

from django import VERSION
from django.conf import settings
try:
from django.conf.urls import include, url

# Compatibility for Django > 1.8
def patterns(prefix, *args):
if VERSION < (1, 9):
from django.conf.urls import patterns as django_patterns
return django_patterns(prefix, *args)
elif prefix != '':
raise NotImplementedError("You need to update your URLConf for "
"Django 1.10, or tweak it to remove the "
"prefix parameter")
else:
return list(args)
except ImportError: # Django < 1.4
from django.conf.urls.defaults import include, patterns, url

except ImportError:
from django.urls import include, url
from django.contrib import admin
from django.views.static import serve


admin.autodiscover()

js_info_dict = {
'packages': ('django.conf',),
}

urlpatterns = patterns(
'',
urlpatterns = [
url(r'^', include('app.urls')),
url(r'^admin/', include(admin.site.urls)),
)
url(r'^admin/', admin.site.urls),
]

urlpatterns += patterns(
'',
url(r'^%s(?P<path>.*)$' % settings.MEDIA_URL[1:],
urlpatterns += [
url(
r'^%s(?P<path>.*)$' % settings.MEDIA_URL[1:],
serve,
{'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
)
{
'document_root': settings.MEDIA_ROOT,
'show_indexes': True,
},
),
]
7 changes: 2 additions & 5 deletions example/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,16 @@
import os
import sys

import django

from django.conf import ENVIRONMENT_VARIABLE
from django.core import management
from django.core.wsgi import get_wsgi_application


if len(sys.argv) == 1:
os.environ[ENVIRONMENT_VARIABLE] = 'example.settings'
else:
os.environ[ENVIRONMENT_VARIABLE] = sys.argv[1]

if django.VERSION[0] == 1 and django.VERSION[1] >= 7:
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
application = get_wsgi_application()

management.call_command('test', 'app')
16 changes: 11 additions & 5 deletions multiselectfield/db/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def get_choices_selected(self, arr_choices):
return choices_selected

def value_to_string(self, obj):
value = self._get_val_from_obj(obj)
value = super(MultiSelectField, self).value_from_object(obj)
return self.get_prep_value(value)

def validate(self, value, model_instance):
Expand Down Expand Up @@ -147,10 +147,16 @@ def to_python(self, value):
return value if isinstance(value, list) else MSFList(choices, value.split(','))
return MSFList(choices, [])

def from_db_value(self, value, expression, connection, context):
if value is None:
return value
return self.to_python(value)
if VERSION < (2, ):
def from_db_value(self, value, expression, connection, context):
if value is None:
return value
return self.to_python(value)
else:
def from_db_value(self, value, expression, connection):
if value is None:
return value
return self.to_python(value)

def contribute_to_class(self, cls, name):
super(MultiSelectField, self).contribute_to_class(cls, name)
Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,26 @@ def read(*rnames):
'Framework :: Django',
'License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.6',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.3',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
],
license="LGPL 3",
keywords="django,multiple,select,field,choices",
url='https://github.com/goinnn/django-multiselectfield',
packages=find_packages(),
include_package_data=True,
tests_require=[
'django>=1.4',
'django>=1.11',
'tox',
'coverage',
'flake8',
],
install_requires=[
'django>=1.4',
'django>=1.11',
],
zip_safe=False,
)
Loading