Skip to content

Commit 582f357

Browse files
committed
Merge branch 'develop'
2 parents d222500 + 5bfd60a commit 582f357

33 files changed

+176
-208
lines changed

.travis.yml

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
language: python
2+
cache:
3+
directories:
4+
- $HOME/.cache/pip
5+
- /opt/python
26
sudo: false
37
env:
48
- TOX_ENV=py27-flake8
5-
- TOX_ENV=py36-flake8
9+
- TOX_ENV=py37-flake8
610
- TOX_ENV=py27-dj18
711
- TOX_ENV=py27-dj19
812
- TOX_ENV=py27-dj110
913
- TOX_ENV=py27-dj111
10-
- TOX_ENV=py36-dj18
11-
- TOX_ENV=py36-dj19
12-
- TOX_ENV=py36-dj110
13-
- TOX_ENV=py36-dj111
14-
- TOX_ENV=py36-dj20
15-
- TOX_ENV=py36-dj21
14+
- TOX_ENV=py37-dj18
15+
- TOX_ENV=py37-dj19
16+
- TOX_ENV=py37-dj110
17+
- TOX_ENV=py37-dj111
18+
- TOX_ENV=py37-dj20
19+
- TOX_ENV=py37-dj21
1620
before_install:
17-
- pyenv global system 3.6
21+
- pyenv install 2.7 --skip-existing
22+
- pyenv install 3.7 --skip-existing
23+
- pyenv global system 3.7
1824
install:
1925
- pip install -r requirements-test.txt
2026
script:

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## [1.8.0]
4+
5+
Added/fixed support for Django 2.2
6+
37
## [1.6.1](https://github.com/crucialfelix/django-ajax-selects/tree/1.6.1) (2017-09-09)
48
[Full Changelog](https://github.com/crucialfelix/django-ajax-selects/compare/1.6.0...1.6.1)
59

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ Read the full documention here: [outside of the admin](http://django-ajax-select
7777

7878
## Compatibility
7979

80-
* Django >=1.8, <=2.1
81-
* Python >=2.7, 3.3+
80+
* Django >=1.8, <3.0
81+
* Python >=2.7, >=3.5
8282

8383
## Contributors
8484

ajax_select/admin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from django.contrib import admin
2+
23
from ajax_select.fields import autoselect_fields_check_can_add
34

45

56
class AjaxSelectAdmin(admin.ModelAdmin):
6-
77
""" in order to get + popup functions subclass this or do the same hook inside of your get_form """
88

99
def get_form(self, request, obj=None, **kwargs):

ajax_select/apps.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
class AjaxSelectConfig(AppConfig):
5-
65
"""
76
Django 1.7+ enables initializing installed applications
87
and autodiscovering modules.

ajax_select/fields.py

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import unicode_literals
22

33
import json
4-
54
from django import forms
65
from django.conf import settings
76
from django.contrib.contenttypes.models import ContentType
@@ -10,10 +9,10 @@
109
from django.template.defaultfilters import force_escape
1110
from django.template.loader import render_to_string
1211
from django.utils.encoding import force_text
12+
from django.utils.module_loading import import_string
1313
from django.utils.safestring import mark_safe
1414
from django.utils.six import text_type
1515
from django.utils.translation import ugettext as _
16-
from django.utils.module_loading import import_string
1716

1817
from ajax_select.registry import registry
1918

@@ -23,20 +22,19 @@
2322
# < django 1.10
2423
from django.core.urlresolvers import reverse
2524

26-
2725
as_default_help = 'Enter text to search.'
2826

2927

3028
def _media(self):
31-
# unless AJAX_SELECT_BOOTSTRAP == False
32-
# then load jquery and jquery ui + default css
33-
# where needed
34-
js = ('ajax_select/js/bootstrap.js', 'ajax_select/js/ajax_select.js')
35-
try:
36-
if not settings.AJAX_SELECT_BOOTSTRAP:
37-
js = ('ajax_select/js/ajax_select.js',)
38-
except AttributeError:
39-
pass
29+
js = ['admin/js/jquery.init.js']
30+
31+
# Unless AJAX_SELECT_BOOTSTRAP == False
32+
# then load include bootstrap which will load jquery and jquery ui + default css as needed
33+
if getattr(settings, "AJAX_SELECT_BOOTSTRAP", True):
34+
js.append('ajax_select/js/bootstrap.js')
35+
36+
js.append('ajax_select/js/ajax_select.js')
37+
4038
return forms.Media(css={'all': ('ajax_select/css/ajax_select.css',)}, js=js)
4139

4240

@@ -48,7 +46,6 @@ def _media(self):
4846

4947

5048
class AutoCompleteSelectWidget(forms.widgets.TextInput):
51-
5249
"""
5350
Widget to search for a model and return it as text for use in a CharField.
5451
"""
@@ -106,7 +103,7 @@ def render(self, name, value, attrs=None, renderer=None, **_kwargs):
106103
'add_link': self.add_link,
107104
}
108105
context.update(
109-
make_plugin_options(lookup, self.channel, self.plugin_options, initial))
106+
make_plugin_options(lookup, self.channel, self.plugin_options, initial))
110107
templates = (
111108
'ajax_select/autocompleteselect_%s.html' % self.channel,
112109
'ajax_select/autocompleteselect.html')
@@ -121,7 +118,6 @@ def id_for_label(self, id_):
121118

122119

123120
class AutoCompleteSelectField(forms.fields.CharField):
124-
125121
"""Form field to select a Model for a ForeignKey db field."""
126122

127123
channel = None
@@ -130,15 +126,15 @@ def __init__(self, channel, *args, **kwargs):
130126
self.channel = channel
131127

132128
widget_kwargs = dict(
133-
channel=channel,
134-
help_text=kwargs.get('help_text', _(as_default_help)),
135-
show_help_text=kwargs.pop('show_help_text', True),
136-
plugin_options=kwargs.pop('plugin_options', {})
129+
channel=channel,
130+
help_text=kwargs.get('help_text', _(as_default_help)),
131+
show_help_text=kwargs.pop('show_help_text', True),
132+
plugin_options=kwargs.pop('plugin_options', {})
137133
)
138134
widget_kwargs.update(kwargs.pop('widget_options', {}))
139135
kwargs["widget"] = AutoCompleteSelectWidget(**widget_kwargs)
140136
super(AutoCompleteSelectField, self).__init__(
141-
max_length=255, *args, **kwargs)
137+
max_length=255, *args, **kwargs)
142138

143139
def clean(self, value):
144140
if value:
@@ -150,7 +146,7 @@ def clean(self, value):
150146
# out of the scope of this field to do anything more than
151147
# tell you it doesn't exist
152148
raise forms.ValidationError(
153-
"%s cannot find object: %s" % (lookup, value))
149+
"%s cannot find object: %s" % (lookup, value))
154150
return objs[0]
155151
else:
156152
if self.required:
@@ -171,7 +167,6 @@ def has_changed(self, initial, data):
171167

172168

173169
class AutoCompleteSelectMultipleWidget(forms.widgets.SelectMultiple):
174-
175170
"""
176171
Widget to select multiple models for a ManyToMany db field.
177172
"""
@@ -231,15 +226,15 @@ def render(self, name, value, attrs=None, renderer=None, **_kwargs):
231226
'current': value,
232227
'current_ids': current_ids,
233228
'current_reprs': mark_safe(
234-
json.dumps(initial, cls=json_encoder)
229+
json.dumps(initial, cls=json_encoder)
235230
),
236231
'help_text': help_text,
237232
'extra_attrs': mark_safe(flatatt(final_attrs)),
238233
'func_slug': self.html_id.replace("-", ""),
239234
'add_link': self.add_link,
240235
}
241236
context.update(
242-
make_plugin_options(lookup, self.channel, self.plugin_options, initial))
237+
make_plugin_options(lookup, self.channel, self.plugin_options, initial))
243238
templates = ('ajax_select/autocompleteselectmultiple_%s.html' % self.channel,
244239
'ajax_select/autocompleteselectmultiple.html')
245240
out = render_to_string(templates, context)
@@ -254,7 +249,6 @@ def id_for_label(self, id_):
254249

255250

256251
class AutoCompleteSelectMultipleField(forms.fields.CharField):
257-
258252
"""
259253
Form field to select multiple models for a ManyToMany db field.
260254
"""
@@ -286,7 +280,7 @@ def __init__(self, channel, *args, **kwargs):
286280
django_default_help = _(dh).translate(settings.LANGUAGE_CODE)
287281
if django_default_help in translated:
288282
cleaned_help = translated.replace(
289-
django_default_help, '').strip()
283+
django_default_help, '').strip()
290284
# probably will not show up in translations
291285
if cleaned_help:
292286
help_text = cleaned_help
@@ -327,11 +321,11 @@ def has_changed(self, initial_value, data_value):
327321
dvs = [text_type(v) for v in (data_value or [])]
328322
return ivs != dvs
329323

324+
330325
###############################################################################
331326

332327

333328
class AutoCompleteWidget(forms.TextInput):
334-
335329
"""
336330
Widget to select a search result and enter the result as raw text in the
337331
text input field. The user may also simply enter text and ignore any
@@ -376,14 +370,13 @@ def render(self, name, value, attrs=None, renderer=None, **_kwargs):
376370
'func_slug': self.html_id.replace("-", ""),
377371
}
378372
context.update(
379-
make_plugin_options(lookup, self.channel, self.plugin_options, initial))
373+
make_plugin_options(lookup, self.channel, self.plugin_options, initial))
380374
templates = ('ajax_select/autocomplete_%s.html' % self.channel,
381375
'ajax_select/autocomplete.html')
382376
return mark_safe(render_to_string(templates, context))
383377

384378

385379
class AutoCompleteField(forms.CharField):
386-
387380
"""
388381
A CharField that uses an AutoCompleteWidget to lookup matching
389382
and stores the result as plain text.
@@ -394,9 +387,9 @@ def __init__(self, channel, *args, **kwargs):
394387
self.channel = channel
395388

396389
widget_kwargs = dict(
397-
help_text=kwargs.get('help_text', _(as_default_help)),
398-
show_help_text=kwargs.pop('show_help_text', True),
399-
plugin_options=kwargs.pop('plugin_options', {})
390+
help_text=kwargs.get('help_text', _(as_default_help)),
391+
show_help_text=kwargs.pop('show_help_text', True),
392+
plugin_options=kwargs.pop('plugin_options', {})
400393
)
401394
widget_kwargs.update(kwargs.pop('widget_options', {}))
402395
if 'attrs' in kwargs:
@@ -431,7 +424,7 @@ def _check_can_add(self, user, related_model):
431424
app_label = related_model._meta.app_label
432425
model = related_model._meta.object_name.lower()
433426
self.widget.add_link = reverse(
434-
'admin:%s_%s_add' % (app_label, model)) + '?_popup=1'
427+
'admin:%s_%s_add' % (app_label, model)) + '?_popup=1'
435428

436429

437430
def autoselect_fields_check_can_add(form, model, user):
@@ -466,7 +459,7 @@ def make_plugin_options(lookup, channel_name, widget_plugin_options, initial):
466459
return {
467460
'plugin_options': mark_safe(json.dumps(po, cls=json_encoder)),
468461
'data_plugin_options': force_escape(
469-
json.dumps(po, cls=json_encoder)
462+
json.dumps(po, cls=json_encoder)
470463
)
471464
}
472465

ajax_select/helpers.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ def make_ajax_field(related_model, fieldname_on_model, channel, show_help_text=F
9999
kwargs['show_help_text'] = show_help_text
100100
if isinstance(field, ManyToManyField):
101101
f = AutoCompleteSelectMultipleField(
102-
channel,
103-
**kwargs)
102+
channel,
103+
**kwargs)
104104
elif isinstance(field, ForeignKey):
105105
f = AutoCompleteSelectField(
106-
channel,
107-
**kwargs)
106+
channel,
107+
**kwargs)
108108
else:
109109
f = AutoCompleteField(
110-
channel,
111-
**kwargs)
110+
channel,
111+
**kwargs)
112112
return f

ajax_select/lookup_channel.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class LookupChannel(object):
7-
87
"""
98
Subclass this, setting the model and implementing methods to taste.
109

ajax_select/registry.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
class LookupChannelRegistry(object):
8-
98
"""
109
Registry for LookupChannels activated for your django project.
1110
@@ -57,7 +56,7 @@ def get(self, channel):
5756
lookup_spec = self._registry[channel]
5857
except KeyError:
5958
raise ImproperlyConfigured(
60-
"No ajax_select LookupChannel named %(channel)r is registered." % {'channel': channel})
59+
"No ajax_select LookupChannel named %(channel)r is registered." % {'channel': channel})
6160

6261
if (type(lookup_spec) is type) and issubclass(lookup_spec, LookupChannel):
6362
return lookup_spec()
@@ -96,7 +95,6 @@ def make_channel(self, app_model, arg_search_field):
9695
app_label, model_name = app_model.split(".")
9796

9897
class MadeLookupChannel(LookupChannel):
99-
10098
model = get_model(app_label, model_name)
10199
search_field = arg_search_field
102100

ajax_select/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from django.conf.urls import url
2+
23
from ajax_select import views
34

45
urlpatterns = [

0 commit comments

Comments
 (0)