Skip to content

Commit

Permalink
django 3.2 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinwahl committed Nov 21, 2023
1 parent 088a255 commit 7ea7a95
Show file tree
Hide file tree
Showing 34 changed files with 45 additions and 58 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ jobs:
fail-fast: false
matrix:
db: [sqlite, postgres, mysql]
python-version: [3.7, 3.8, 3.9]
django-version: [2.2]
python-version: [3.9, 3.10]
django-version: [3.2]
include:
- db: sqlite
db_url: sqlite:///test_db.sqlite3
Expand Down
5 changes: 1 addition & 4 deletions demo/demo_widgets/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import gettext_lazy as _

import widgy
from widgy.models import Content
Expand All @@ -16,7 +15,6 @@ def valid_parent_of(self, cls, obj=None):


@widgy.register
@python_2_unicode_compatible
class Slide(StrDisplayNameMixin, AcceptsSimpleHtmlChildrenMixin, Content):
tagline = models.CharField(_('tagline'), max_length=255)
background_image = ImageField(verbose_name=_('background image'))
Expand All @@ -42,7 +40,6 @@ def valid_parent_of(self, cls, obj=None):


@widgy.register
@python_2_unicode_compatible
class Box(StrDisplayNameMixin, AcceptsSimpleHtmlChildrenMixin, Content):
title = models.CharField(verbose_name=_('title'), max_length=255)

Expand Down
2 changes: 1 addition & 1 deletion demo/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{% load compress %}
{% load pages_tags %}
{% load widgy_tags %}
{% load staticfiles %}
{% load static %}
<html lang="en">
<head>
<meta charset="UTF-8">
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def read(fname):
'django-compressor>=1.3',
'beautifulsoup4',
'django-argonauts>=1.1.4',
'Django~=2.2',
'Django>=3.1,<3.3',
'html5lib',
'bleach',
'bleach-whitelist',
Expand Down
5 changes: 1 addition & 4 deletions tests/core_tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
from __future__ import unicode_literals

from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from widgy.models import Content
from widgy.db.fields import WidgyField, VersionedWidgyField
from widgy import registry
from django.utils.encoding import python_2_unicode_compatible

from widgy.models import links
from widgy.models.mixins import InvisibleMixin
Expand Down Expand Up @@ -42,7 +41,6 @@ class Meta:
verbose_name = _("bucket")


@python_2_unicode_compatible
class RawTextWidget(Content):
text = models.TextField()

Expand Down Expand Up @@ -212,7 +210,6 @@ class ForeignKeyWidget(Content):


@links.register
@python_2_unicode_compatible
class LinkableThing(models.Model):
name = models.CharField(max_length=255, default='')

Expand Down
2 changes: 1 addition & 1 deletion tests/core_tests/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import json
import imp

import mock
from unittest import mock

from django import urls
from django.utils.functional import cached_property
Expand Down
2 changes: 1 addition & 1 deletion tests/core_tests/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pprint import pprint
import datetime
import time
import mock
from unittest import mock
import unittest
import contextlib

Expand Down
2 changes: 1 addition & 1 deletion tests/core_tests/tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.contrib.contenttypes.models import ContentType
from django.template import Context

import mock
from unittest import mock

from widgy.forms import WidgyFormMixin, WidgyFormField
from widgy.models import Node, VersionTracker
Expand Down
2 changes: 1 addition & 1 deletion widgy/contrib/form_builder/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.urls import reverse
from django.http import HttpResponse
from django.shortcuts import render
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.conf.urls import url
from django.template.defaultfilters import slugify
from django.http import Http404
Expand Down
13 changes: 4 additions & 9 deletions widgy/contrib/form_builder/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
from django import forms
from django.core.mail import EmailMultiAlternatives
from django.conf import settings
from django.utils.translation import ugettext_lazy as _, ugettext
from django.utils.translation import gettext_lazy as _, gettext
from django.shortcuts import redirect
from django.dispatch import receiver
from django.template.loader import render_to_string
from django.utils.functional import cached_property
from django.utils.encoding import python_2_unicode_compatible, force_bytes, force_text
from django.utils.encoding import force_bytes, force_text
from django.template.defaultfilters import truncatechars
from django.core.files import File
from django.core.files.storage import default_storage
Expand Down Expand Up @@ -154,7 +154,6 @@ def __init__(self, *args, **kwargs):


@widgy.register
@python_2_unicode_compatible
class FieldMappingValue(StrDisplayNameMixin, MappingValue):
"""
MappingValue that maps a form field to another value.
Expand Down Expand Up @@ -222,7 +221,6 @@ class EmailSuccessHandlerBaseForm(forms.ModelForm):
content = CKEditorField()


@python_2_unicode_compatible
class EmailSuccessHandlerBase(StrDisplayNameMixin, FormSuccessHandler):
subject = models.CharField(max_length=255, verbose_name=_('subject'))
content = models.TextField(blank=True, verbose_name=_('content'))
Expand Down Expand Up @@ -345,7 +343,6 @@ def post_create(self, site):


@widgy.register
@python_2_unicode_compatible
class SubmitButton(StrDisplayNameMixin, FormElement):
text = models.CharField(max_length=255, default=_('submit'), verbose_name=_('text'))

Expand All @@ -364,7 +361,7 @@ def __str__(self):


def untitled_form():
untitled = ugettext('Untitled form')
untitled = gettext('Untitled form')
n = Form.objects.filter(name__startswith=untitled + ' ').exclude(
_nodes__is_frozen=True
).count() + 1
Expand Down Expand Up @@ -457,7 +454,6 @@ def friendly_uuid(uuid):


@widgy.register
@python_2_unicode_compatible
class Form(TabbedContainer, StrDisplayNameMixin, StrictDefaultChildrenMixin, Content):
name = models.CharField(verbose_name=_('Name'),
max_length=255,
Expand Down Expand Up @@ -668,7 +664,6 @@ class FormFieldForm(forms.ModelForm):
help_text = MiniCKEditorField(label=_('help text'), required=False)


@python_2_unicode_compatible
class FormField(StrDisplayNameMixin, BaseFormField):
widget = None

Expand Down Expand Up @@ -978,7 +973,7 @@ def get_formfield_labels(self):
).values('field_ident').distinct().order_by('field_node__path').values_list('field_ident', flat=True)

ret = OrderedDict([
('created_at', ugettext('Created at')),
('created_at', gettext('Created at')),
])
for field_uuid in uuids:
latest_value = FormValue.objects.filter(
Expand Down
2 changes: 1 addition & 1 deletion widgy/contrib/form_builder/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from django.core.files.uploadedfile import TemporaryUploadedFile
from django.conf import settings

import mock
from unittest import mock

from widgy.contrib.form_builder.forms import PhoneNumberField
from widgy.contrib.form_builder.models import (
Expand Down
4 changes: 2 additions & 2 deletions widgy/contrib/page_builder/db/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from django import forms
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from filer.fields.file import FilerFileField
from filer.models.filemodels import File
Expand Down Expand Up @@ -79,7 +79,7 @@ def __init__(self, *args, **kwargs):
super(VideoField, self).__init__(*args, **kwargs)
self.validators.append(validators_video_url)

def from_db_value(self, value, expression, connection, context):
def from_db_value(self, value, expression, connection):
if value is None:
return value
return self.get_url_instance(value)
Expand Down
2 changes: 1 addition & 1 deletion widgy/contrib/page_builder/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django import forms
from django.db import models
from django.conf import settings
from django.utils.translation import ugettext_lazy as _, ugettext
from django.utils.translation import gettext_lazy as _
from django.dispatch import receiver
from django.template.defaultfilters import truncatechars
from django.contrib.sites.models import Site
Expand Down
2 changes: 1 addition & 1 deletion widgy/contrib/review_queue/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.contrib.admin import ModelAdmin
from django.contrib.admin.views.main import ChangeList
from django.contrib import messages
from django.utils.translation import ugettext_lazy as _, ungettext
from django.utils.translation import gettext_lazy as _, ungettext
from django.utils.html import format_html
from django.template.loader import render_to_string
from django.utils.safestring import mark_safe
Expand Down
2 changes: 1 addition & 1 deletion widgy/contrib/review_queue/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.conf import settings

from widgy.utils import QuerySet
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% load compress staticfiles widgy_tags %}
{% load compress static widgy_tags %}
{% for owner in owners %}
{% get_action_links owner node as links %}
{% for link in links %}
Expand Down
2 changes: 1 addition & 1 deletion widgy/contrib/review_queue/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.shortcuts import get_object_or_404, redirect
from django.contrib import messages
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from django.utils.http import is_safe_url
from django.utils.html import format_html
from django.views.generic import RedirectView, FormView
Expand Down
3 changes: 2 additions & 1 deletion widgy/contrib/urlconf_include/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
from django.conf.urls import include, url
from django.conf.urls.i18n import i18n_patterns
from django import urls
from django.utils.deprecation import MiddlewareMixin

from .models import UrlconfIncludePage


class PatchUrlconfMiddleware(object):
class PatchUrlconfMiddleware(MiddlewareMixin):
def process_request(self, request):
root_urlconf = getattr(request, 'urlconf', settings.ROOT_URLCONF)
if isinstance(root_urlconf, six.string_types):
Expand Down
2 changes: 1 addition & 1 deletion widgy/contrib/urlconf_include/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models
from django.core.exceptions import ImproperlyConfigured
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.conf import settings

from mezzanine.pages.models import Page
Expand Down
9 changes: 3 additions & 6 deletions widgy/contrib/urlconf_include/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from django.utils.decorators import decorator_from_middleware
from django.http import HttpResponse, HttpResponseNotFound
from django import urls
from django.urls.resolvers import _get_cached_resolver
from django.contrib.auth.models import AnonymousUser
from django.contrib.auth import get_user_model
from django.conf.urls import include, url
Expand Down Expand Up @@ -57,12 +58,8 @@ class TestMiddleware(TestCase):
def setUp(self):
self.factory = RequestFactory()

if django.VERSION > (1, 7):
def resolver_cache_size(self):
return urls.get_resolver.cache_info().currsize
else:
def resolver_cache_size(self):
return len(urls._resolver_cache)
def resolver_cache_size(self):
return _get_cached_resolver.cache_info().currsize

def get_request(self, path='/'):
r = self.factory.get(path)
Expand Down
4 changes: 2 additions & 2 deletions widgy/contrib/widgy_i18n/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models
from django.utils.translation import (
ugettext_lazy as _, ugettext, get_language, get_language_info
gettext_lazy as _, gettext, get_language, get_language_info
)
from django.conf import settings

Expand All @@ -25,7 +25,7 @@ class Meta:
@property
def language_name(self):
info = get_language_info(self.language_code)
return ugettext(info['name'])
return gettext(info['name'])

@property
def display_name(self):
Expand Down
4 changes: 2 additions & 2 deletions widgy/contrib/widgy_mezzanine/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django import forms
from django.urls import reverse
from django.contrib.admin.utils import quote
from django.utils.translation import ugettext_lazy as _, ugettext, ungettext
from django.utils.translation import gettext_lazy as _, gettext, ungettext
from django.utils.html import format_html
from django.utils import timezone
from django.contrib import messages
Expand Down Expand Up @@ -235,7 +235,7 @@ def get_undelete_queryset(self, layouts):
def label_from_instance(self, obj):
url = reverse('widgy.contrib.widgy_mezzanine.views.preview',
kwargs={'node_pk': obj.working_copy.pk})
return format_html('<a href="{url}">{preview}</a>', url=url, preview=ugettext('preview'))
return format_html('<a href="{url}">{preview}</a>', url=url, preview=gettext('preview'))


class UndeletePageAdminMixin(object):
Expand Down
2 changes: 1 addition & 1 deletion widgy/contrib/widgy_mezzanine/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.utils.encoding import force_text
from django.conf import settings
from django import urls
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{% load widgy_tags %}
{% load pages_tags %}
{% load compress %}
{% load staticfiles %}
{% load static %}

{% block title %}{{ page.meta_title }} {{ block.super }}{% endblock %}
{% block css %}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends "widgy/versioned_widgy_field_base.html" %}
{% load i18n %}
{% load staticfiles %}
{% load static %}

{% block widgy_tools %}
<li><a class="widgy-fancybox commit" href="{{ commit_url }}">{% trans "Schedule changes" %}</a></li>
Expand Down
2 changes: 1 addition & 1 deletion widgy/contrib/widgy_mezzanine/tests/test_core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import absolute_import
import mock
from unittest import mock
import datetime
from contextlib import contextmanager
from unittest import skipUnless
Expand Down
2 changes: 1 addition & 1 deletion widgy/contrib/widgy_mezzanine/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from django.core.exceptions import PermissionDenied
from django import urls
from django import forms
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _

from mezzanine.pages.views import page as page_view
from mezzanine.pages.models import Page
Expand Down
4 changes: 2 additions & 2 deletions widgy/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from django import forms
from django.template.loader import render_to_string
from django.forms import widgets
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from django.utils.html import format_html
from django.urls import reverse
from django.core.exceptions import ObjectDoesNotExist
Expand Down Expand Up @@ -93,7 +93,7 @@ def conform_to_value(self, owner, value):
# remove the empty choice
choices = [c for c in self.choices if c[0]]
if len(choices) == 1:
self._value = choices[0][0]
self._value = choices[0][0].value
self.widget = DisplayWidget(display_name=choices[0][1])
self.help_text = _('You must save before you can edit this.')
else:
Expand Down
Loading

0 comments on commit 7ea7a95

Please sign in to comment.