diff --git a/autocomplete_light/autocomplete/base.py b/autocomplete_light/autocomplete/base.py index 219b47426..66af30db9 100644 --- a/autocomplete_light/autocomplete/base.py +++ b/autocomplete_light/autocomplete/base.py @@ -3,9 +3,9 @@ import six from django.urls import reverse, NoReverseMatch from django.core.exceptions import ImproperlyConfigured -from django.utils.encoding import force_text +from django.utils.encoding import force_str from django.utils.html import escape -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ __all__ = ('AutocompleteInterface', 'AutocompleteBase') @@ -201,11 +201,11 @@ def choice_value(self, choice): Return the value of a choice. This simple implementation returns the textual representation. """ - return force_text(choice) + return force_str(choice) def choice_label(self, choice): """ Return the human-readable representation of a choice. This simple implementation returns the textual representation. """ - return force_text(choice) + return force_str(choice) diff --git a/autocomplete_light/autocomplete/choice_list.py b/autocomplete_light/autocomplete/choice_list.py index 85b79d412..be0cb79b0 100644 --- a/autocomplete_light/autocomplete/choice_list.py +++ b/autocomplete_light/autocomplete/choice_list.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals -from django.utils.encoding import force_text +from django.utils.encoding import force_str from .list import AutocompleteList @@ -33,7 +33,7 @@ class AutocompleteChoiceList(AutocompleteList): this against :py:attr:`choices` as an argument :py:func:`sorted`. """ def order_by(cls, choice): - return force_text(choice[1]).lower() + return force_str(choice[1]).lower() def choices_for_values(self): """ @@ -56,7 +56,7 @@ def choices_for_request(self): q = self.request.GET.get('q', '').lower().strip() for choice in self.choices: - m = force_text(choice[0]).lower() + force_text(choice[1]).lower() + m = force_str(choice[0]).lower() + force_str(choice[1]).lower() if q in m: requests_choices.append(choice) diff --git a/autocomplete_light/autocomplete/list.py b/autocomplete_light/autocomplete/list.py index 1e9c48b7a..5845f4b92 100644 --- a/autocomplete_light/autocomplete/list.py +++ b/autocomplete_light/autocomplete/list.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals -from django.utils.encoding import force_text +from django.utils.encoding import force_str __all__ = ('AutocompleteList',) @@ -31,7 +31,7 @@ class AutocompleteList(object): limit_choices = 20 def order_by(cls, choice): - return force_text(choice).lower() + return force_str(choice).lower() def choices_for_values(self): """ @@ -56,7 +56,7 @@ def choices_for_request(self): q = self.request.GET.get('q', '').lower().strip() for choice in self.choices: - if q in force_text(choice).lower(): + if q in force_str(choice).lower(): requests_choices.append(choice) return self.order_choices(requests_choices)[0:self.limit_choices] diff --git a/autocomplete_light/autocomplete/model.py b/autocomplete_light/autocomplete/model.py index 9e7d9faed..cece4285b 100644 --- a/autocomplete_light/autocomplete/model.py +++ b/autocomplete_light/autocomplete/model.py @@ -2,7 +2,7 @@ import six from django.db.models import Q -from django.utils.encoding import force_text +from django.utils.encoding import force_str from django.db import connection from ..settings import DEFAULT_SEARCH_FIELDS @@ -61,7 +61,7 @@ def choice_label(self, choice): """ Return the textual representation of the choice by default. """ - return force_text(choice) + return force_str(choice) def order_choices(self, choices): """ diff --git a/autocomplete_light/autocomplete/rest_model.py b/autocomplete_light/autocomplete/rest_model.py index a84e22845..50a131821 100644 --- a/autocomplete_light/autocomplete/rest_model.py +++ b/autocomplete_light/autocomplete/rest_model.py @@ -2,7 +2,7 @@ import six from django import http -from django.utils.encoding import force_text +from django.utils.encoding import force_str from .model import AutocompleteModel @@ -67,7 +67,7 @@ def model_for_source_url(self, url): def choices_for_request(self): choices = super(AutocompleteRestModel, self).choices_for_request() - unicodes = [force_text(choice) for choice in choices] + unicodes = [force_str(choice) for choice in choices] slots = self.limit_choices - len(choices) @@ -76,7 +76,7 @@ def choices_for_request(self): for choice in self.get_remote_choices(slots): # avoid data that's already in local - if force_text(choice) in unicodes: + if force_str(choice) in unicodes: continue choices.append(choice) diff --git a/autocomplete_light/compat.py b/autocomplete_light/compat.py index f7ef42a04..e32f89db1 100644 --- a/autocomplete_light/compat.py +++ b/autocomplete_light/compat.py @@ -1,11 +1,11 @@ from django import VERSION if VERSION < (1, 5): - from django.conf.urls.defaults import patterns, url # noqa + from django.urls.defaults import patterns, url # noqa elif VERSION < (1, 8): - from django.conf.urls import patterns, url # noqa + from django.urls import patterns, url # noqa else: - from django.conf.urls import url # noqa + from django.urls import re_path as url # noqa patterns = None @@ -20,7 +20,7 @@ from django.utils.module_loading import import_string except ImportError: from importlib import import_module - from django.utils import six + import six import sys def import_string(dotted_path): diff --git a/autocomplete_light/example_apps/security_test/templates/security_test/item_form.html b/autocomplete_light/example_apps/security_test/templates/security_test/item_form.html index f5e7d9749..f7d1e1144 100644 --- a/autocomplete_light/example_apps/security_test/templates/security_test/item_form.html +++ b/autocomplete_light/example_apps/security_test/templates/security_test/item_form.html @@ -1,4 +1,4 @@ -{% load staticfiles %} +{% load static %} {% include 'autocomplete_light/static.html' %} diff --git a/autocomplete_light/example_apps/unuseable_virtualfield/vote_models.py b/autocomplete_light/example_apps/unuseable_virtualfield/vote_models.py index 6629814c2..72dd64fc2 100644 --- a/autocomplete_light/example_apps/unuseable_virtualfield/vote_models.py +++ b/autocomplete_light/example_apps/unuseable_virtualfield/vote_models.py @@ -9,7 +9,7 @@ from django.db import IntegrityError, models, transaction from django.db.models import Count from django.db.models.query import QuerySet -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ # Django 1.5 add support for custom auth user model if django.VERSION >= (1, 5): diff --git a/autocomplete_light/forms.py b/autocomplete_light/forms.py index 26cd96f6e..904ac828a 100644 --- a/autocomplete_light/forms.py +++ b/autocomplete_light/forms.py @@ -20,8 +20,8 @@ from django.db.models import ForeignKey, ManyToManyField, OneToOneField from django.forms.models import modelform_factory as django_modelform_factory from django.forms.models import ModelFormMetaclass as DjangoModelFormMetaclass -from django.utils.encoding import force_text -from django.utils.translation import ugettext_lazy as _ +from django.utils.encoding import force_str +from django.utils.translation import gettext_lazy as _ from .contrib.taggit_field import TaggitField from .fields import (GenericModelChoiceField, GenericModelMultipleChoiceField, @@ -52,7 +52,7 @@ class SelectMultipleHelpTextRemovalMixin(forms.BaseModelForm): def __init__(self, *args, **kwargs): super(SelectMultipleHelpTextRemovalMixin, self).__init__(*args, **kwargs) - msg = force_text(M) + msg = force_str(M) for name, field in self.fields.items(): widget = field.widget diff --git a/autocomplete_light/templates/autocomplete_light/static.html b/autocomplete_light/templates/autocomplete_light/static.html index a26331bc4..c91012706 100644 --- a/autocomplete_light/templates/autocomplete_light/static.html +++ b/autocomplete_light/templates/autocomplete_light/static.html @@ -1,5 +1,4 @@ -{% load static from staticfiles %} - +{% load static %} {% include 'autocomplete_light/_ajax_csrf.html' %} diff --git a/autocomplete_light/templates/autocomplete_light/widget.html b/autocomplete_light/templates/autocomplete_light/widget.html index 3293e6fe9..45a3915b1 100644 --- a/autocomplete_light/templates/autocomplete_light/widget.html +++ b/autocomplete_light/templates/autocomplete_light/widget.html @@ -1,5 +1,5 @@ {% load i18n l10n %} -{% load staticfiles %} +{% load static %} {% load autocomplete_light_tags %} {% block widget_open %} diff --git a/autocomplete_light/tests/autocomplete/test_model.py b/autocomplete_light/tests/autocomplete/test_model.py index 01588a56e..3d4bb812f 100644 --- a/autocomplete_light/tests/autocomplete/test_model.py +++ b/autocomplete_light/tests/autocomplete/test_model.py @@ -4,7 +4,7 @@ import pytest from django import VERSION -from django.utils.encoding import force_text +from django.utils.encoding import force_str from autocomplete_light.example_apps.autocomplete_test_case_app.models import ( NonIntegerPk, SubGroup, CustomSchema, CustomIntegerPk, Caps) @@ -125,18 +125,18 @@ def get_autocomplete_html_tests(self): 'fixture': make_get_request('q=j'), 'expected': ''.join([ '%s' % ( - self.jack.pk, force_text(self.jack)), + self.jack.pk, force_str(self.jack)), '%s' % ( - self.james.pk, force_text(self.james)), + self.james.pk, force_str(self.james)), ]) }, { 'fixture': make_get_request(), 'expected': ''.join([ '%s' % ( - self.abe.pk, force_text(self.abe)), + self.abe.pk, force_str(self.abe)), '%s' % ( - self.jack.pk, force_text(self.jack)), + self.jack.pk, force_str(self.jack)), ]) }, ) diff --git a/autocomplete_light/tests/autocomplete/test_template.py b/autocomplete_light/tests/autocomplete/test_template.py index b14012270..f5292fe14 100644 --- a/autocomplete_light/tests/autocomplete/test_template.py +++ b/autocomplete_light/tests/autocomplete/test_template.py @@ -1,7 +1,7 @@ from __future__ import unicode_literals from django.template import Context, Template -from django.utils.encoding import force_text +from django.utils.encoding import force_str from ...example_apps.autocomplete_test_case_app.models import Group, User from .case import * @@ -61,9 +61,9 @@ def get_autocomplete_html_tests(self): 'expected': ''.join([ '', ]) }, @@ -72,9 +72,9 @@ def get_autocomplete_html_tests(self): 'expected': ''.join([ '', ]) }, diff --git a/autocomplete_light/tests/test_forms.py b/autocomplete_light/tests/test_forms.py index a2f987c6b..13cc11e50 100644 --- a/autocomplete_light/tests/test_forms.py +++ b/autocomplete_light/tests/test_forms.py @@ -7,7 +7,7 @@ from django.forms.models import modelform_factory from django.test import TestCase from django.utils import translation -from django.utils.encoding import force_text +from django.utils.encoding import force_str from ..example_apps.basic.forms import (DjangoCompatMeta, FkModelForm, GfkModelForm, MtmModelForm, @@ -55,13 +55,13 @@ class ModelForm(forms.ModelForm): class Meta(DjangoCompatMeta): model = MtmModel form = ModelForm() - help_text = force_text(form.fields['relation'].help_text).strip() + help_text = force_str(form.fields['relation'].help_text).strip() class ModelForm(autocomplete_light.ModelForm): class Meta(DjangoCompatMeta): model = MtmModel form = ModelForm() - my_help_text = force_text(form.fields['relation'].help_text).strip() + my_help_text = force_str(form.fields['relation'].help_text).strip() # If help_text is not empty (which is wasn't before Django 1.8 fixed # #9321), test that it's empty in autocomplete_light's ModelForm. @@ -106,7 +106,7 @@ def assertExpectedFormField(self, name='relation'): # django-taggit enforces verbose_name=_('Tags') # bug reported at: # https://github.com/alex/django-taggit/issues/177 - self.assertEqual(force_text(self.form[name].label), name.capitalize()) + self.assertEqual(force_str(self.form[name].label), name.capitalize()) self.assertTrue(isinstance(self.form.fields[name], self.field_class)) diff --git a/autocomplete_light/tests/test_views.py b/autocomplete_light/tests/test_views.py index b7b53ae68..b724c6562 100644 --- a/autocomplete_light/tests/test_views.py +++ b/autocomplete_light/tests/test_views.py @@ -4,7 +4,7 @@ import six from django.core.urlresolvers import reverse from django.test import Client, RequestFactory, TestCase -from django.utils.encoding import force_text +from django.utils.encoding import force_str try: from unittest.mock import Mock, MagicMock, patch @@ -74,9 +74,9 @@ def test_output(self): response = self.superuser.get(reverse('autocomplete_light_registry')) - self.assertIn('List of your 1 registered autocompletes', force_text(response.content)) + self.assertIn('List of your 1 registered autocompletes', force_str(response.content)) self.assertIn(reverse('autocomplete_light_autocomplete', - args=['UserAutocomplete']), force_text(response.content)) + args=['UserAutocomplete']), force_str(response.content)) class AutocompleteViewTestCase(TestCase): @@ -103,7 +103,7 @@ def test_get(self): registry.__getitem__.return_value.assert_called_with(request=request) registry.__getitem__.return_value.return_value.autocomplete_html.assert_called_with() - self.assertIn('foo', force_text(response.content)) + self.assertIn('foo', force_str(response.content)) def test_post(self): registry = MagicMock() @@ -137,8 +137,8 @@ def __str__(self): expected = ''' ''' - self.assertEqual(force_text(expected.strip()), - force_text(output.content.strip())) + self.assertEqual(force_str(expected.strip()), + force_str(output.content.strip())) self.assertEqual(output.status_code, 201) def test_is_popup(self): diff --git a/autocomplete_light/views.py b/autocomplete_light/views.py index bc8fd14a5..8576871e6 100644 --- a/autocomplete_light/views.py +++ b/autocomplete_light/views.py @@ -1,6 +1,6 @@ from autocomplete_light.exceptions import AutocompleteNotRegistered from django import http -from django.utils.encoding import force_text +from django.utils.encoding import force_str from django.views import generic from django.views.generic import base @@ -84,7 +84,7 @@ def respond_script(self, obj=None): html = [] html.append('') html = ''.join(html) diff --git a/autocomplete_light/widgets.py b/autocomplete_light/widgets.py index 7629f3341..3f3100538 100644 --- a/autocomplete_light/widgets.py +++ b/autocomplete_light/widgets.py @@ -3,7 +3,7 @@ from django import forms from django.template.loader import render_to_string from django.utils import safestring -from django.utils.translation import ugettext_lazy as _ +from django.utils.translation import gettext_lazy as _ """ The provided widgets are meant to rely on an Autocomplete class. diff --git a/docs/source/install.rst b/docs/source/install.rst index 9a08b8205..97af95a4c 100644 --- a/docs/source/install.rst +++ b/docs/source/install.rst @@ -74,10 +74,10 @@ Example: .. code-block:: python # Django 1.4 onwards: - from django.conf.urls import patterns, url, include + from django.urls import patterns, url, include # Django < 1.4: - # from django.conf.urls.default import patterns, url, include + # from django.urls.default import patterns, url, include urlpatterns = patterns('', # [...] your url patterns are here diff --git a/test_grappelli/test_grappelli/urls.py b/test_grappelli/test_grappelli/urls.py index ea170c1a4..8d982865a 100644 --- a/test_grappelli/test_grappelli/urls.py +++ b/test_grappelli/test_grappelli/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import patterns, include, url +from django.urls import patterns, include, url import autocomplete_light autocomplete_light.autodiscover() # Uncomment the next two lines to enable the admin: diff --git a/test_project/bootstrap_modal/urls.py b/test_project/bootstrap_modal/urls.py index 7086952a4..d70e17bbf 100644 --- a/test_project/bootstrap_modal/urls.py +++ b/test_project/bootstrap_modal/urls.py @@ -1,7 +1,7 @@ -from django.conf.urls import url +from django.urls import re_path from django.views.generic.base import TemplateView from autocomplete_light.compat import urls, url urlpatterns = urls([ - url(r'^$', TemplateView.as_view(template_name="bootstrap_modal/modal.html"), name="bootstrap_modal"), + re_path(r'^$', TemplateView.as_view(template_name="bootstrap_modal/modal.html"), name="bootstrap_modal"), ]) diff --git a/test_project/navigation_autocomplete/urls.py b/test_project/navigation_autocomplete/urls.py index 7ea927eae..1c8574626 100644 --- a/test_project/navigation_autocomplete/urls.py +++ b/test_project/navigation_autocomplete/urls.py @@ -1,8 +1,8 @@ -from django.conf.urls import url +from django.urls import re_path from autocomplete_light.compat import url, urls from .views import navigation_autocomplete urlpatterns = urls([ - url(r'^$', navigation_autocomplete, name='navigation_autocomplete'), + re_path(r'^$', navigation_autocomplete, name='navigation_autocomplete'), ]) diff --git a/test_project/test_project/urls.py b/test_project/test_project/urls.py index 6fcaa2d99..3688647ec 100644 --- a/test_project/test_project/urls.py +++ b/test_project/test_project/urls.py @@ -1,6 +1,6 @@ import django -from django.conf.urls import include +from django.urls import include from django.views import generic from django.contrib import admin from autocomplete_light.compat import url, urls diff --git a/test_remote_project/test_remote_project/urls.py b/test_remote_project/test_remote_project/urls.py index 565409fca..4a5dbeee9 100644 --- a/test_remote_project/test_remote_project/urls.py +++ b/test_remote_project/test_remote_project/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import patterns, include, url +from django.urls import patterns, include, url import autocomplete_light autocomplete_light.autodiscover()