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

Django 5.0 Updates #5

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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
8 changes: 4 additions & 4 deletions autocomplete_light/autocomplete/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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)
6 changes: 3 additions & 3 deletions autocomplete_light/autocomplete/choice_list.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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):
"""
Expand All @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions autocomplete_light/autocomplete/list.py
Original file line number Diff line number Diff line change
@@ -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',)

Expand Down Expand Up @@ -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):
"""
Expand All @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions autocomplete_light/autocomplete/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
"""
Expand Down
6 changes: 3 additions & 3 deletions autocomplete_light/autocomplete/rest_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions autocomplete_light/compat.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load staticfiles %}
{% load static %}

<script type="text/javascript" src="{% static 'jquery.js' %}"></script>
{% include 'autocomplete_light/static.html' %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions autocomplete_light/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions autocomplete_light/templates/autocomplete_light/static.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{% load static from staticfiles %}

{% load static %}
{% include 'autocomplete_light/_ajax_csrf.html' %}

<script type="text/javascript" src="{% static 'autocomplete_light/django_admin.js' %}"></script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% load i18n l10n %}
{% load staticfiles %}
{% load static %}
{% load autocomplete_light_tags %}

{% block widget_open %}
Expand Down
10 changes: 5 additions & 5 deletions autocomplete_light/tests/autocomplete/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -125,18 +125,18 @@ def get_autocomplete_html_tests(self):
'fixture': make_get_request('q=j'),
'expected': ''.join([
'<span data-value="%s">%s</span>' % (
self.jack.pk, force_text(self.jack)),
self.jack.pk, force_str(self.jack)),
'<span data-value="%s">%s</span>' % (
self.james.pk, force_text(self.james)),
self.james.pk, force_str(self.james)),
])
},
{
'fixture': make_get_request(),
'expected': ''.join([
'<span data-value="%s">%s</span>' % (
self.abe.pk, force_text(self.abe)),
self.abe.pk, force_str(self.abe)),
'<span data-value="%s">%s</span>' % (
self.jack.pk, force_text(self.jack)),
self.jack.pk, force_str(self.jack)),
])
},
)
Expand Down
10 changes: 5 additions & 5 deletions autocomplete_light/tests/autocomplete/test_template.py
Original file line number Diff line number Diff line change
@@ -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 *
Expand Down Expand Up @@ -61,9 +61,9 @@ def get_autocomplete_html_tests(self):
'expected': ''.join([
'<ul>',
'<li data-value="%s">%s</li>' % (
self.jack.pk, force_text(self.jack)),
self.jack.pk, force_str(self.jack)),
'<li data-value="%s">%s</li>' % (
self.james.pk, force_text(self.james)),
self.james.pk, force_str(self.james)),
'</ul>',
])
},
Expand All @@ -72,9 +72,9 @@ def get_autocomplete_html_tests(self):
'expected': ''.join([
'<ul>',
'<li data-value="%s">%s</li>' % (
self.abe.pk, force_text(self.abe)),
self.abe.pk, force_str(self.abe)),
'<li data-value="%s">%s</li>' % (
self.jack.pk, force_text(self.jack)),
self.jack.pk, force_str(self.jack)),
'</ul>',
])
},
Expand Down
8 changes: 4 additions & 4 deletions autocomplete_light/tests/test_forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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))
Expand Down
12 changes: 6 additions & 6 deletions autocomplete_light/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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()
Expand Down Expand Up @@ -137,8 +137,8 @@ def __str__(self):
expected = '''
<script type="text/javascript">opener.dismissAddAnotherPopup( window, "5", "abc \\"yoo\\"" );</script>
'''
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):
Expand Down
4 changes: 2 additions & 2 deletions autocomplete_light/views.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -84,7 +84,7 @@ def respond_script(self, obj=None):
html = []
html.append('<script type="text/javascript">')
html.append('opener.dismissAddAnotherPopup( window, "%s", "%s" );' % (
force_text(obj.pk), force_text(obj).replace('"', '\\"')))
force_str(obj.pk), force_str(obj).replace('"', '\\"')))
html.append('</script>')

html = ''.join(html)
Expand Down
2 changes: 1 addition & 1 deletion autocomplete_light/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions docs/source/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test_grappelli/test_grappelli/urls.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
4 changes: 2 additions & 2 deletions test_project/bootstrap_modal/urls.py
Original file line number Diff line number Diff line change
@@ -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"),
])
Loading