Skip to content

Commit

Permalink
feat: Added Django 3.2 and Python 3.8 and 3.9 support (#196)
Browse files Browse the repository at this point in the history
* remove python_2_unicode_compatible

* remove file # -*- coding: utf-8 -*- declarations

* remove python2 __future__ imports and six primitive types

* replaced lru cache imports to: from functools import lru_cache

* remapped import for ACTION_CHECKBOX_NAME

* replaced ugettext with gettext, ugettext_lazy with gettext_lazy, and ungettext with ngettext

* test assertEquals replaced with assertEqual

* replaced force_text() with force_str(), https://docs.djangoproject.com/en/3.2/ref/utils/#django.utils.encoding.force_text

* moved from django.conf.urls.url() to django.urls.re_path()
  • Loading branch information
Aiky30 authored Jan 14, 2022
1 parent ce89c1b commit 325f355
Show file tree
Hide file tree
Showing 51 changed files with 112 additions and 202 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9
- name: Install flake8
run: pip install --upgrade flake8
- name: Run flake8
Expand All @@ -29,7 +29,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9
- run: python -m pip install isort
- name: isort
uses: liskin/gh-problem-matcher-wrap@v1
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.6, 3.7, 3.8, ] # latest release minus two
python-version: [ 3.7, 3.8, 3.9 ] # latest release minus two
requirements-file: [
dj11_cms40.txt,
dj22_cms40.txt,
dj32_cms40.txt,
]
os: [
ubuntu-20.04,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ venv
node_modules/
yarn.lock
docs/_build/
venv*
5 changes: 4 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ Changelog

Unreleased
==========

* Python 3.8, 3.9 support added
* Django 3.0, 3.1 and 3.2 support added
* Python 3.5 and 3.6 support removed
* Django 1.11 support removed

1.0.28 (2021-10-18)
===================
Expand Down
45 changes: 21 additions & 24 deletions djangocms_moderation/admin.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from __future__ import unicode_literals

from django import forms
from django.apps import apps
from django.conf.urls import url
from django.contrib import admin, messages
from django.contrib.auth import get_user_model
from django.contrib.contenttypes.models import ContentType
Expand All @@ -11,9 +8,9 @@
from django.http import Http404, HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.template.loader import render_to_string
from django.urls import reverse
from django.urls import re_path, reverse
from django.utils.html import format_html, format_html_join
from django.utils.translation import ugettext, ugettext_lazy as _, ungettext
from django.utils.translation import gettext, gettext_lazy as _, ngettext

from cms.admin.placeholderadmin import PlaceholderAdminMixin
from cms.toolbar.utils import get_object_preview_url
Expand Down Expand Up @@ -78,7 +75,7 @@ def has_delete_permission(self, request, obj=None):

def show_user(self, obj):
_name = obj.get_by_user_name()
return ugettext("By {user}").format(user=_name)
return gettext("By {user}").format(user=_name)

show_user.short_description = _("Status")

Expand Down Expand Up @@ -152,7 +149,7 @@ def get_urls(self):
info = self.model._meta.app_label, self.model._meta.model_name

return [
url(
re_path(
r'^delete_selected/',
self.admin_site.admin_view(self.delete_selected_view),
name='{}_{}_delete'.format(*info),
Expand Down Expand Up @@ -270,13 +267,13 @@ def get_status(self, obj):

if last_action:
if obj.moderation_request.version_can_be_published():
status = ugettext('Ready for publishing')
status = gettext('Ready for publishing')
elif obj.moderation_request.is_rejected():
status = ugettext('Pending author rework')
status = gettext('Pending author rework')
elif obj.moderation_request.is_active and obj.moderation_request.has_pending_step():
next_step = obj.moderation_request.get_next_required()
role = next_step.role.name
status = ugettext('Pending %(role)s approval') % {'role': role}
status = gettext('Pending %(role)s approval') % {'role': role}
elif not obj.moderation_request.version.can_be_published():
status = obj.moderation_request.version.get_state_display()
else:
Expand All @@ -285,9 +282,9 @@ def get_status(self, obj):
'action': last_action.get_action_display(),
'name': user_name,
}
status = ugettext('%(action)s by %(name)s') % message_data
status = gettext('%(action)s by %(name)s') % message_data
else:
status = ugettext('Ready for submission')
status = gettext('Ready for submission')
return status

def get_comments_link(self, obj):
Expand Down Expand Up @@ -450,7 +447,7 @@ def _traverse_moderation_nodes(node_item):
queryset.delete()
messages.success(
request,
ungettext(
ngettext(
'%(count)d request successfully deleted',
'%(count)d requests successfully deleted',
num_deleted_requests
Expand Down Expand Up @@ -504,22 +501,22 @@ def get_urls(self):
info = self.model._meta.app_label, self.model._meta.model_name

return [
url(
re_path(
r"^approve/",
self.admin_site.admin_view(self.approved_view),
name="{}_{}_approve".format(*info),
),
url(
re_path(
r"^rework/",
self.admin_site.admin_view(self.rework_view),
name="{}_{}_rework".format(*info),
),
url(
re_path(
r"^publish/",
self.admin_site.admin_view(self.published_view),
name="{}_{}_publish".format(*info),
),
url(
re_path(
r"^resubmit/",
self.admin_site.admin_view(self.resubmit_view),
name="{}_{}_resubmit".format(*info),
Expand Down Expand Up @@ -592,7 +589,7 @@ def resubmit_view(self, request):

messages.success(
request,
ungettext(
ngettext(
"%(count)d request successfully resubmitted for review",
"%(count)d requests successfully resubmitted for review",
len(resubmitted_requests),
Expand Down Expand Up @@ -639,7 +636,7 @@ def published_view(self, request):

messages.success(
request,
ungettext(
ngettext(
"%(count)d request successfully published",
"%(count)d requests successfully published",
len(published_moderation_requests),
Expand Down Expand Up @@ -698,7 +695,7 @@ def rework_view(self, request):

messages.success(
request,
ungettext(
ngettext(
"%(count)d request successfully submitted for rework",
"%(count)d requests successfully submitted for rework",
len(rejected_requests),
Expand Down Expand Up @@ -790,7 +787,7 @@ def approved_view(self, request):

messages.success(
request,
ungettext(
ngettext(
"%(count)d request successfully approved",
"%(count)d requests successfully approved",
len(approved_requests),
Expand Down Expand Up @@ -1088,7 +1085,7 @@ def get_comments_link(self, obj):

def get_urls(self):
def _url(regex, fn, name, **kwargs):
return url(regex, self.admin_site.admin_view(fn), kwargs=kwargs, name=name)
return re_path(regex, self.admin_site.admin_view(fn), kwargs=kwargs, name=name)

url_patterns = [
_url(
Expand Down Expand Up @@ -1138,7 +1135,7 @@ class ConfirmationPageAdmin(PlaceholderAdminMixin, admin.ModelAdmin):

def get_urls(self):
def _url(regex, fn, name, **kwargs):
return url(regex, self.admin_site.admin_view(fn), kwargs=kwargs, name=name)
return re_path(regex, self.admin_site.admin_view(fn), kwargs=kwargs, name=name)

url_patterns = [
_url(
Expand Down Expand Up @@ -1191,7 +1188,7 @@ def form_data(self, obj):
"",
"<p>{}: <b>{}</b><br />{}: <b>{}</b></p>",
(
(ugettext("Question"), d["label"], ugettext("Answer"), d["value"])
(gettext("Question"), d["label"], gettext("Answer"), d["value"])
for d in data
),
)
Expand Down
14 changes: 7 additions & 7 deletions djangocms_moderation/admin_actions.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from collections import defaultdict
from functools import partial

from django.contrib import admin
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import PermissionDenied
from django.db.models import Q
from django.http import HttpResponseRedirect
from django.shortcuts import reverse
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from cms.utils.urlutils import add_url_parameters

Expand All @@ -24,7 +24,7 @@ def resubmit_selected(modeladmin, request, queryset):
Validate and re-submit all the selected moderation requests for
moderation and notify reviewers via email.
"""
selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
selected = request.POST.getlist(ACTION_CHECKBOX_NAME)
url = "{}?ids={}&collection_id={}".format(
reverse("admin:djangocms_moderation_moderationrequest_resubmit"),
",".join(selected),
Expand All @@ -41,7 +41,7 @@ def reject_selected(modeladmin, request, queryset):
Validate and reject all the selected moderation requests and notify
the author about these requests
"""
selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
selected = request.POST.getlist(ACTION_CHECKBOX_NAME)
url = "{}?ids={}&collection_id={}".format(
reverse("admin:djangocms_moderation_moderationrequest_rework"),
",".join(selected),
Expand All @@ -54,7 +54,7 @@ def reject_selected(modeladmin, request, queryset):


def approve_selected(modeladmin, request, queryset):
selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
selected = request.POST.getlist(ACTION_CHECKBOX_NAME)
url = "{}?ids={}&collection_id={}".format(
reverse("admin:djangocms_moderation_moderationrequest_approve"),
",".join(selected),
Expand All @@ -70,7 +70,7 @@ def delete_selected(modeladmin, request, queryset):
if not modeladmin.has_delete_permission(request):
raise PermissionDenied

selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
selected = request.POST.getlist(ACTION_CHECKBOX_NAME)
url = "{}?ids={}&collection_id={}".format(
reverse('admin:djangocms_moderation_moderationrequesttreenode_delete'),
",".join(selected),
Expand All @@ -87,7 +87,7 @@ def publish_selected(modeladmin, request, queryset):
if request.user != request._collection.author:
raise PermissionDenied

selected = request.POST.getlist(admin.ACTION_CHECKBOX_NAME)
selected = request.POST.getlist(ACTION_CHECKBOX_NAME)
url = "{}?ids={}&collection_id={}".format(
reverse("admin:djangocms_moderation_moderationrequest_publish"),
",".join(selected),
Expand Down
4 changes: 1 addition & 3 deletions djangocms_moderation/apps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
from __future__ import unicode_literals

from django.apps import AppConfig
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


class ModerationConfig(AppConfig):
Expand Down
3 changes: 1 addition & 2 deletions djangocms_moderation/cms_toolbars.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from django.contrib.auth import get_permission_codename
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from cms.cms_toolbars import ADMIN_MENU_IDENTIFIER
from cms.utils.urlutils import add_url_parameters
Expand Down
2 changes: 1 addition & 1 deletion djangocms_moderation/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _


UUID_BACKEND = "djangocms_moderation.backends.uuid4_backend"
Expand Down
4 changes: 1 addition & 3 deletions djangocms_moderation/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from __future__ import unicode_literals

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


# NOTE: those are not just numbers!! we will do binary AND on them,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from cms.plugin_pool import plugin_pool

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.12 on 2018-05-03 09:15
from __future__ import unicode_literals

from django.db import migrations


Expand Down
2 changes: 1 addition & 1 deletion djangocms_moderation/contrib/moderation_forms/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from aldryn_forms.models import FormPlugin

Expand Down
8 changes: 3 additions & 5 deletions djangocms_moderation/emails.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from __future__ import unicode_literals

from django.conf import settings
from django.core.mail import EmailMessage
from django.template.loader import render_to_string
from django.urls import reverse
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 .conf import EMAIL_NOTIFICATIONS_FAIL_SILENTLY
from .utils import get_absolute_url
Expand Down Expand Up @@ -40,7 +38,7 @@ def _send_email(
template = "djangocms_moderation/emails/moderation-request/{}".format(template)

# TODO What language should the email be sent in? e.g. `with force_language(lang):`
subject = force_text(subject)
subject = force_str(subject)
content = render_to_string(template, context)

message = EmailMessage(
Expand Down
10 changes: 5 additions & 5 deletions djangocms_moderation/filters.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from django.contrib import admin
from django.contrib.auth import get_user_model
from django.db.models import Q
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 . import constants, helpers

Expand All @@ -22,7 +22,7 @@ def lookups(self, request, model_admin):
options = []
for user in helpers.get_all_moderators():
options.append(
(force_text(user.pk), user.get_full_name() or user.get_username())
(force_str(user.pk), user.get_full_name() or user.get_username())
)
return options

Expand All @@ -44,7 +44,7 @@ def lookups(self, request, model_admin):
# collect all unique users from the three queries
for user in helpers.get_all_reviewers():
options.append(
(force_text(user.pk), user.get_full_name() or user.get_username())
(force_str(user.pk), user.get_full_name() or user.get_username())
)
return options

Expand Down Expand Up @@ -78,7 +78,7 @@ def choices(self, changelist):
}
for lookup, title in self.lookup_choices:
yield {
"selected": self.value() == force_text(lookup),
"selected": self.value() == force_str(lookup),
"query_string": changelist.get_query_string(
{self.parameter_name: lookup}, []
),
Expand Down
Loading

0 comments on commit 325f355

Please sign in to comment.