mirror of
https://github.com/Hopiu/django-select2.git
synced 2026-05-12 07:13:10 +00:00
Drop Django 1.8 and 1.10 support
This commit is contained in:
parent
937dcac08b
commit
19e2e50921
4 changed files with 4 additions and 56 deletions
|
|
@ -17,8 +17,6 @@ python:
|
|||
- "3.6"
|
||||
env:
|
||||
matrix:
|
||||
- DJANGO=18
|
||||
- DJANGO=110
|
||||
- DJANGO=111
|
||||
- DJANGO=master
|
||||
- TOXENV=qa
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ Changelog Summary
|
|||
|
||||
* Drop Python 2 support
|
||||
* Drop Python 3.5 support
|
||||
* Drop Django 1.8 support
|
||||
* Drop Django 1.10 support
|
||||
|
||||
### v5.10.0
|
||||
* Add support for dependent select fields [321](github.com/applegrew/django-select2/pull/321/).
|
||||
|
|
|
|||
|
|
@ -53,6 +53,7 @@ from django import forms
|
|||
from django.core import signing
|
||||
from django.db.models import Q
|
||||
from django.forms.models import ModelChoiceIterator
|
||||
from django.urls import reverse
|
||||
from django.utils.encoding import force_text
|
||||
from django.utils.six.moves.cPickle import PicklingError as cPicklingError
|
||||
from django.utils.translation import get_language
|
||||
|
|
@ -60,11 +61,6 @@ from django.utils.translation import get_language
|
|||
from .cache import cache
|
||||
from .conf import settings
|
||||
|
||||
try:
|
||||
from django.urls import reverse
|
||||
except ImportError:
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
|
||||
class Select2Mixin(object):
|
||||
"""
|
||||
|
|
@ -97,12 +93,6 @@ class Select2Mixin(object):
|
|||
self.choices = list(chain([('', '')], self.choices))
|
||||
return super(Select2Mixin, self).optgroups(name, value, attrs=attrs)
|
||||
|
||||
def render_options(self, *args, **kwargs):
|
||||
"""Render options including an empty one, if the field is not required."""
|
||||
output = '<option value=""></option>' if not self.is_required and not self.allow_multiple_selected else ''
|
||||
output += super(Select2Mixin, self).render_options(*args, **kwargs)
|
||||
return output
|
||||
|
||||
def _get_media(self):
|
||||
"""
|
||||
Construct Media as a dynamic property.
|
||||
|
|
@ -276,22 +266,6 @@ class HeavySelect2Mixin(object):
|
|||
msg = "You need to overwrite \"set_to_cache\" or ensure that %s is serialisable."
|
||||
raise NotImplementedError(msg % self.__class__.__name__)
|
||||
|
||||
def render_options(self, *args):
|
||||
"""Render only selected options."""
|
||||
try:
|
||||
selected_choices, = args
|
||||
except ValueError: # Signature contained `choices` prior to Django 1.10
|
||||
choices, selected_choices = args
|
||||
choices = chain(self.choices, choices)
|
||||
else:
|
||||
choices = self.choices
|
||||
output = ['<option value=""></option>' if not self.is_required and not self.allow_multiple_selected else '']
|
||||
selected_choices = {force_text(v) for v in selected_choices}
|
||||
choices = [(k, v) for k, v in choices if force_text(k) in selected_choices]
|
||||
for option_value, option_label in choices:
|
||||
output.append(self.render_option(selected_choices, option_value, option_label))
|
||||
return '\n'.join(output)
|
||||
|
||||
|
||||
class HeavySelect2Widget(HeavySelect2Mixin, Select2Widget):
|
||||
"""
|
||||
|
|
@ -477,30 +451,6 @@ class ModelSelect2Mixin(object):
|
|||
subgroup.append(self.create_option(name, option_value, option_label, selected_choices, index))
|
||||
return groups
|
||||
|
||||
def render_options(self, *args):
|
||||
"""Render only selected options and set QuerySet from :class:`ModelChoiceIterator`."""
|
||||
try:
|
||||
selected_choices, = args
|
||||
except ValueError:
|
||||
choices, selected_choices = args
|
||||
choices = chain(self.choices, choices)
|
||||
else:
|
||||
choices = self.choices
|
||||
selected_choices = {force_text(v) for v in selected_choices}
|
||||
output = ['<option value=""></option>' if not self.is_required and not self.allow_multiple_selected else '']
|
||||
if isinstance(self.choices, ModelChoiceIterator):
|
||||
if self.queryset is None:
|
||||
self.queryset = self.choices.queryset
|
||||
selected_choices = {c for c in selected_choices
|
||||
if c not in self.choices.field.empty_values}
|
||||
choices = [(obj.pk, self.label_from_instance(obj))
|
||||
for obj in self.choices.queryset.filter(pk__in=selected_choices)]
|
||||
else:
|
||||
choices = [(k, v) for k, v in choices if force_text(k) in selected_choices]
|
||||
for option_value, option_label in choices:
|
||||
output.append(self.render_option(selected_choices, option_value, option_label))
|
||||
return '\n'.join(output)
|
||||
|
||||
def label_from_instance(self, obj):
|
||||
"""
|
||||
Return option label representation from instance.
|
||||
|
|
|
|||
4
tox.ini
4
tox.ini
|
|
@ -1,13 +1,11 @@
|
|||
[tox]
|
||||
envlist = py{36}-dj{18,110,111,master},qa,docs
|
||||
envlist = py{36}-dj{111,master},qa,docs
|
||||
[testenv]
|
||||
setenv=
|
||||
PYTHONPATH = {toxinidir}
|
||||
passenv=CI
|
||||
deps=
|
||||
-rrequirements-dev.txt
|
||||
dj18: https://github.com/django/django/archive/stable/1.8.x.tar.gz#egg=django
|
||||
dj110: https://github.com/django/django/archive/stable/1.10.x.tar.gz#egg=django
|
||||
dj111: https://github.com/django/django/archive/stable/1.11.x.tar.gz#egg=django
|
||||
djmaster: https://github.com/django/django/archive/master.tar.gz#egg=django
|
||||
commands=
|
||||
|
|
|
|||
Loading…
Reference in a new issue