Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
crucialfelix committed Dec 28, 2019
2 parents d222500 + 5bfd60a commit 582f357
Show file tree
Hide file tree
Showing 33 changed files with 176 additions and 208 deletions.
22 changes: 14 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
language: python
cache:
directories:
- $HOME/.cache/pip
- /opt/python
sudo: false
env:
- TOX_ENV=py27-flake8
- TOX_ENV=py36-flake8
- TOX_ENV=py37-flake8
- TOX_ENV=py27-dj18
- TOX_ENV=py27-dj19
- TOX_ENV=py27-dj110
- TOX_ENV=py27-dj111
- TOX_ENV=py36-dj18
- TOX_ENV=py36-dj19
- TOX_ENV=py36-dj110
- TOX_ENV=py36-dj111
- TOX_ENV=py36-dj20
- TOX_ENV=py36-dj21
- TOX_ENV=py37-dj18
- TOX_ENV=py37-dj19
- TOX_ENV=py37-dj110
- TOX_ENV=py37-dj111
- TOX_ENV=py37-dj20
- TOX_ENV=py37-dj21
before_install:
- pyenv global system 3.6
- pyenv install 2.7 --skip-existing
- pyenv install 3.7 --skip-existing
- pyenv global system 3.7
install:
- pip install -r requirements-test.txt
script:
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [1.8.0]

Added/fixed support for Django 2.2

## [1.6.1](https://github.com/crucialfelix/django-ajax-selects/tree/1.6.1) (2017-09-09)
[Full Changelog](https://github.com/crucialfelix/django-ajax-selects/compare/1.6.0...1.6.1)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ Read the full documention here: [outside of the admin](http://django-ajax-select

## Compatibility

* Django >=1.8, <=2.1
* Python >=2.7, 3.3+
* Django >=1.8, <3.0
* Python >=2.7, >=3.5

## Contributors

Expand Down
2 changes: 1 addition & 1 deletion ajax_select/admin.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from django.contrib import admin

from ajax_select.fields import autoselect_fields_check_can_add


class AjaxSelectAdmin(admin.ModelAdmin):

""" in order to get + popup functions subclass this or do the same hook inside of your get_form """

def get_form(self, request, obj=None, **kwargs):
Expand Down
1 change: 0 additions & 1 deletion ajax_select/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class AjaxSelectConfig(AppConfig):

"""
Django 1.7+ enables initializing installed applications
and autodiscovering modules.
Expand Down
61 changes: 27 additions & 34 deletions ajax_select/fields.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import unicode_literals

import json

from django import forms
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
Expand All @@ -10,10 +9,10 @@
from django.template.defaultfilters import force_escape
from django.template.loader import render_to_string
from django.utils.encoding import force_text
from django.utils.module_loading import import_string
from django.utils.safestring import mark_safe
from django.utils.six import text_type
from django.utils.translation import ugettext as _
from django.utils.module_loading import import_string

from ajax_select.registry import registry

Expand All @@ -23,20 +22,19 @@
# < django 1.10
from django.core.urlresolvers import reverse


as_default_help = 'Enter text to search.'


def _media(self):
# unless AJAX_SELECT_BOOTSTRAP == False
# then load jquery and jquery ui + default css
# where needed
js = ('ajax_select/js/bootstrap.js', 'ajax_select/js/ajax_select.js')
try:
if not settings.AJAX_SELECT_BOOTSTRAP:
js = ('ajax_select/js/ajax_select.js',)
except AttributeError:
pass
js = ['admin/js/jquery.init.js']

# Unless AJAX_SELECT_BOOTSTRAP == False
# then load include bootstrap which will load jquery and jquery ui + default css as needed
if getattr(settings, "AJAX_SELECT_BOOTSTRAP", True):
js.append('ajax_select/js/bootstrap.js')

js.append('ajax_select/js/ajax_select.js')

return forms.Media(css={'all': ('ajax_select/css/ajax_select.css',)}, js=js)


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


class AutoCompleteSelectWidget(forms.widgets.TextInput):

"""
Widget to search for a model and return it as text for use in a CharField.
"""
Expand Down Expand Up @@ -106,7 +103,7 @@ def render(self, name, value, attrs=None, renderer=None, **_kwargs):
'add_link': self.add_link,
}
context.update(
make_plugin_options(lookup, self.channel, self.plugin_options, initial))
make_plugin_options(lookup, self.channel, self.plugin_options, initial))
templates = (
'ajax_select/autocompleteselect_%s.html' % self.channel,
'ajax_select/autocompleteselect.html')
Expand All @@ -121,7 +118,6 @@ def id_for_label(self, id_):


class AutoCompleteSelectField(forms.fields.CharField):

"""Form field to select a Model for a ForeignKey db field."""

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

widget_kwargs = dict(
channel=channel,
help_text=kwargs.get('help_text', _(as_default_help)),
show_help_text=kwargs.pop('show_help_text', True),
plugin_options=kwargs.pop('plugin_options', {})
channel=channel,
help_text=kwargs.get('help_text', _(as_default_help)),
show_help_text=kwargs.pop('show_help_text', True),
plugin_options=kwargs.pop('plugin_options', {})
)
widget_kwargs.update(kwargs.pop('widget_options', {}))
kwargs["widget"] = AutoCompleteSelectWidget(**widget_kwargs)
super(AutoCompleteSelectField, self).__init__(
max_length=255, *args, **kwargs)
max_length=255, *args, **kwargs)

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


class AutoCompleteSelectMultipleWidget(forms.widgets.SelectMultiple):

"""
Widget to select multiple models for a ManyToMany db field.
"""
Expand Down Expand Up @@ -231,15 +226,15 @@ def render(self, name, value, attrs=None, renderer=None, **_kwargs):
'current': value,
'current_ids': current_ids,
'current_reprs': mark_safe(
json.dumps(initial, cls=json_encoder)
json.dumps(initial, cls=json_encoder)
),
'help_text': help_text,
'extra_attrs': mark_safe(flatatt(final_attrs)),
'func_slug': self.html_id.replace("-", ""),
'add_link': self.add_link,
}
context.update(
make_plugin_options(lookup, self.channel, self.plugin_options, initial))
make_plugin_options(lookup, self.channel, self.plugin_options, initial))
templates = ('ajax_select/autocompleteselectmultiple_%s.html' % self.channel,
'ajax_select/autocompleteselectmultiple.html')
out = render_to_string(templates, context)
Expand All @@ -254,7 +249,6 @@ def id_for_label(self, id_):


class AutoCompleteSelectMultipleField(forms.fields.CharField):

"""
Form field to select multiple models for a ManyToMany db field.
"""
Expand Down Expand Up @@ -286,7 +280,7 @@ def __init__(self, channel, *args, **kwargs):
django_default_help = _(dh).translate(settings.LANGUAGE_CODE)
if django_default_help in translated:
cleaned_help = translated.replace(
django_default_help, '').strip()
django_default_help, '').strip()
# probably will not show up in translations
if cleaned_help:
help_text = cleaned_help
Expand Down Expand Up @@ -327,11 +321,11 @@ def has_changed(self, initial_value, data_value):
dvs = [text_type(v) for v in (data_value or [])]
return ivs != dvs


###############################################################################


class AutoCompleteWidget(forms.TextInput):

"""
Widget to select a search result and enter the result as raw text in the
text input field. The user may also simply enter text and ignore any
Expand Down Expand Up @@ -376,14 +370,13 @@ def render(self, name, value, attrs=None, renderer=None, **_kwargs):
'func_slug': self.html_id.replace("-", ""),
}
context.update(
make_plugin_options(lookup, self.channel, self.plugin_options, initial))
make_plugin_options(lookup, self.channel, self.plugin_options, initial))
templates = ('ajax_select/autocomplete_%s.html' % self.channel,
'ajax_select/autocomplete.html')
return mark_safe(render_to_string(templates, context))


class AutoCompleteField(forms.CharField):

"""
A CharField that uses an AutoCompleteWidget to lookup matching
and stores the result as plain text.
Expand All @@ -394,9 +387,9 @@ def __init__(self, channel, *args, **kwargs):
self.channel = channel

widget_kwargs = dict(
help_text=kwargs.get('help_text', _(as_default_help)),
show_help_text=kwargs.pop('show_help_text', True),
plugin_options=kwargs.pop('plugin_options', {})
help_text=kwargs.get('help_text', _(as_default_help)),
show_help_text=kwargs.pop('show_help_text', True),
plugin_options=kwargs.pop('plugin_options', {})
)
widget_kwargs.update(kwargs.pop('widget_options', {}))
if 'attrs' in kwargs:
Expand Down Expand Up @@ -431,7 +424,7 @@ def _check_can_add(self, user, related_model):
app_label = related_model._meta.app_label
model = related_model._meta.object_name.lower()
self.widget.add_link = reverse(
'admin:%s_%s_add' % (app_label, model)) + '?_popup=1'
'admin:%s_%s_add' % (app_label, model)) + '?_popup=1'


def autoselect_fields_check_can_add(form, model, user):
Expand Down Expand Up @@ -466,7 +459,7 @@ def make_plugin_options(lookup, channel_name, widget_plugin_options, initial):
return {
'plugin_options': mark_safe(json.dumps(po, cls=json_encoder)),
'data_plugin_options': force_escape(
json.dumps(po, cls=json_encoder)
json.dumps(po, cls=json_encoder)
)
}

Expand Down
12 changes: 6 additions & 6 deletions ajax_select/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ def make_ajax_field(related_model, fieldname_on_model, channel, show_help_text=F
kwargs['show_help_text'] = show_help_text
if isinstance(field, ManyToManyField):
f = AutoCompleteSelectMultipleField(
channel,
**kwargs)
channel,
**kwargs)
elif isinstance(field, ForeignKey):
f = AutoCompleteSelectField(
channel,
**kwargs)
channel,
**kwargs)
else:
f = AutoCompleteField(
channel,
**kwargs)
channel,
**kwargs)
return f
1 change: 0 additions & 1 deletion ajax_select/lookup_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class LookupChannel(object):

"""
Subclass this, setting the model and implementing methods to taste.
Expand Down
4 changes: 1 addition & 3 deletions ajax_select/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@


class LookupChannelRegistry(object):

"""
Registry for LookupChannels activated for your django project.
Expand Down Expand Up @@ -57,7 +56,7 @@ def get(self, channel):
lookup_spec = self._registry[channel]
except KeyError:
raise ImproperlyConfigured(
"No ajax_select LookupChannel named %(channel)r is registered." % {'channel': channel})
"No ajax_select LookupChannel named %(channel)r is registered." % {'channel': channel})

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

class MadeLookupChannel(LookupChannel):

model = get_model(app_label, model_name)
search_field = arg_search_field

Expand Down
1 change: 1 addition & 0 deletions ajax_select/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.conf.urls import url

from ajax_select import views

urlpatterns = [
Expand Down
2 changes: 1 addition & 1 deletion ajax_select/views.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import json
from django.http import HttpResponse
from django.utils.encoding import force_text

from ajax_select import registry


def ajax_lookup(request, channel):

"""Load the named lookup channel and lookup matching models.
GET or POST should contain 'term'
Expand Down

0 comments on commit 582f357

Please sign in to comment.