Skip to content

Commit

Permalink
feat: backport - django-cms 4.0.x - Django 3.0 support (#7105)
Browse files Browse the repository at this point in the history
Based on changes made in the following PR: 6c92fbe#diff-069df57a3a645590c8bd00dfffb2bd94969c691857a20c7936a5e06fa122a8f3

This is a backport of the original change for django 3.0. This has been done to have a direct comparison to the original change. There will be another PR for django 3.1 and another for 3.2 which is a few PRs combined.
  • Loading branch information
Aiky30 committed Oct 25, 2021
1 parent a35e1dc commit c44b6be
Show file tree
Hide file tree
Showing 69 changed files with 222 additions and 131 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/test.yml
Expand Up @@ -8,9 +8,10 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.6, 3.7] # latest release minus two
python-version: [ 3.6, 3.7, 3.8 ] # latest release minus two
requirements-file: [
django-2.2.txt,
django-3.0.txt,
# django-3.1.txt,
# django-3.2.txt,
]
Expand Down Expand Up @@ -58,9 +59,10 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.6, 3.7] # latest release minus two
python-version: [ 3.6, 3.7, 3.8 ] # latest release minus two
requirements-file: [
django-2.2.txt,
django-3.0.txt,
# django-3.1.txt,
# django-3.2.txt,
]
Expand Down Expand Up @@ -107,9 +109,10 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.6, 3.7] # latest release minus two
python-version: [ 3.6, 3.7, 3.8 ] # latest release minus two
requirements-file: [
django-2.2.txt,
django-3.0.txt,
# django-3.1.txt,
# django-3.2.txt,
]
Expand Down
10 changes: 6 additions & 4 deletions cms/admin/placeholderadmin.py
Expand Up @@ -18,8 +18,6 @@
)
from django.shortcuts import get_list_or_404, get_object_or_404, render
from django.template.response import TemplateResponse
from django.utils import six
from django.utils.six.moves.urllib.parse import parse_qsl, urlparse
from django.utils.decorators import method_decorator
from django.utils.encoding import force_text
from django.utils.html import conditional_escape
Expand Down Expand Up @@ -49,6 +47,10 @@
from cms.utils.urlutils import admin_reverse
from cms.views import render_object_edit, render_object_structure, render_object_preview

from urllib.parse import parse_qsl, urlparse

from six import add_metaclass, get_unbound_function, get_method_function


_no_default = object()

Expand Down Expand Up @@ -76,7 +78,7 @@ def _instance_overrides_method(base, instance, method_name):
"""
bound_method = getattr(instance, method_name)
unbound_method = getattr(base, method_name)
return six.get_unbound_function(unbound_method) != six.get_method_function(bound_method)
return get_unbound_function(unbound_method) != get_method_function(bound_method)


class FrontendEditableAdminMixin(object):
Expand Down Expand Up @@ -175,7 +177,7 @@ def __new__(cls, name, bases, attrs):
return super_new(cls, name, bases, attrs)


@six.add_metaclass(PlaceholderAdminMixinBase)
@add_metaclass(PlaceholderAdminMixinBase)
class PlaceholderAdminMixin(object):
pass

Expand Down
3 changes: 2 additions & 1 deletion cms/admin/settingsadmin.py
Expand Up @@ -12,14 +12,15 @@
from django.http.request import QueryDict
from django.utils.html import conditional_escape
from django.utils.translation import override
from django.utils.six.moves.urllib.parse import urlparse

from cms.admin.forms import RequestToolbarForm
from cms.models import UserSettings
from cms.toolbar.toolbar import CMSToolbar
from cms.utils.page import get_page_from_request
from cms.utils.urlutils import admin_reverse

from six.moves.urllib.parse import urlparse


class SettingsAdmin(ModelAdmin):

Expand Down
7 changes: 4 additions & 3 deletions cms/api.py
Expand Up @@ -15,7 +15,6 @@
from django.db import transaction
from django.template.defaultfilters import slugify
from django.template.loader import get_template
from django.utils import six

from cms import constants
from cms.app_base import CMSApp
Expand All @@ -37,6 +36,8 @@
from cms.utils.plugins import copy_plugins_to_placeholder
from menus.menu_pool import menu_pool

from six import string_types


#===============================================================================
# Helpers/Internals
Expand All @@ -57,7 +58,7 @@ def _verify_apphook(apphook, namespace):
apphook_name = apphook.__class__.__name__
elif hasattr(apphook, '__module__') and issubclass(apphook, CMSApp):
return apphook.__name__
elif isinstance(apphook, six.string_types):
elif isinstance(apphook, string_types):
try:
assert apphook in apphook_pool.apps
except AssertionError:
Expand All @@ -81,7 +82,7 @@ def _verify_plugin_type(plugin_type):
plugin_model = plugin_type.model
assert plugin_type in plugin_pool.plugins.values()
plugin_type = plugin_type.__name__
elif isinstance(plugin_type, six.string_types):
elif isinstance(plugin_type, string_types):
try:
plugin_model = plugin_pool.get_plugin(plugin_type).model
except KeyError:
Expand Down
10 changes: 5 additions & 5 deletions cms/app_base.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from abc import ABCMeta, abstractmethod

from django.utils import six
from six import with_metaclass


class CMSApp(object):
Expand Down Expand Up @@ -40,20 +40,20 @@ def get_configs(self):
"""
Returns all the apphook configuration instances.
"""
raise NotImplemented('Configurable AppHooks must implement this method')
raise NotImplementedError('Configurable AppHooks must implement this method')

def get_config(self, namespace):
"""
Returns the apphook configuration instance linked to the given namespace
"""
raise NotImplemented('Configurable AppHooks must implement this method')
raise NotImplementedError('Configurable AppHooks must implement this method')

def get_config_add_url(self):
"""
Returns the url to add a new apphook configuration instance
(usually the model admin add view)
"""
raise NotImplemented('Configurable AppHooks must implement this method')
raise NotImplementedError('Configurable AppHooks must implement this method')

def get_menus(self, page=None, language=None, **kwargs):
"""
Expand Down Expand Up @@ -105,7 +105,7 @@ def __init__(self, django_app_config):
self.app_config = django_app_config


class CMSAppExtension(six.with_metaclass(ABCMeta)):
class CMSAppExtension(with_metaclass(ABCMeta)):
"""Base class that all cms app extensions should inherit from"""

@abstractmethod
Expand Down
3 changes: 2 additions & 1 deletion cms/app_registration.py
Expand Up @@ -3,13 +3,14 @@
from importlib import import_module

from django.apps import apps
from django.utils.lru_cache import lru_cache
from django.utils.module_loading import module_has_submodule
from django.core.exceptions import ImproperlyConfigured

from cms.app_base import CMSAppConfig, CMSAppExtension
from cms.constants import CMS_CONFIG_NAME

from functools import lru_cache


def _find_subclasses(module, klass):
"""
Expand Down
5 changes: 3 additions & 2 deletions cms/appresolver.py
Expand Up @@ -4,7 +4,6 @@

from django.core.exceptions import ImproperlyConfigured
from django.db import OperationalError, ProgrammingError
from django.utils import six
from django.utils.translation import get_language, override
from django.urls import Resolver404, reverse

Expand All @@ -15,6 +14,8 @@
from cms.utils.compat.dj import RegexPattern, URLPattern, URLResolver
from cms.utils.i18n import get_language_list

from six import string_types


APP_RESOLVERS = []

Expand Down Expand Up @@ -159,7 +160,7 @@ def _set_permissions(patterns, exclude_permissions):

def get_app_urls(urls):
for urlconf in urls:
if isinstance(urlconf, six.string_types):
if isinstance(urlconf, string_types):
mod = import_module(urlconf)
if not hasattr(mod, 'urlpatterns'):
raise ImproperlyConfigured(
Expand Down
5 changes: 3 additions & 2 deletions cms/context_processors.py
@@ -1,18 +1,19 @@
# -*- coding: utf-8 -*-
from django.utils import lru_cache
from django.utils.functional import lazy

from cms.utils.conf import get_cms_setting
from cms.utils.page import get_page_template_from_request

from functools import lru_cache


def cms_settings(request):
"""
Adds cms-related variables to the context.
"""
from menus.menu_pool import MenuRenderer

@lru_cache.lru_cache(maxsize=None)
@lru_cache(maxsize=None)
def _get_menu_renderer():
# We use lru_cache to avoid getting the manager
# every time this function is called.
Expand Down
8 changes: 5 additions & 3 deletions cms/management/commands/subcommands/base.py
Expand Up @@ -7,7 +7,7 @@
from django.core.management.base import BaseCommand, CommandParser
from django.core.management.color import no_style, color_style

from cms.utils.compat import DJANGO_2_0, DJANGO_2_2
from cms.utils.compat import DJANGO_2_0, DJANGO_2_2, DJANGO_3_0


def add_builtin_arguments(parser):
Expand Down Expand Up @@ -37,10 +37,12 @@ def add_builtin_arguments(parser):
help='Raise on CommandError exceptions')
parser.add_argument('--no-color', action='store_true', dest='no_color', default=False,
help="Don't colorize the command output.")
if DJANGO_2_2:
if DJANGO_2_2 or DJANGO_3_0:
parser.add_argument('--force-color', action='store_true', dest='force_color', default=False,
help="Colorize the command output.")

if DJANGO_3_0:
parser.add_argument('--skip-checks', action='store_true', dest='skip_checks', default=False,
help="Skip the checks.")

class SubcommandsCommand(BaseCommand):
subcommands = OrderedDict()
Expand Down
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals

from django.utils.six.moves import input

from cms.management.commands.subcommands.list import plugin_report

from six.moves import input

from .base import SubcommandsCommand


Expand Down
3 changes: 2 additions & 1 deletion cms/management/commands/subcommands/uninstall.py
Expand Up @@ -2,11 +2,12 @@
from __future__ import absolute_import, print_function, unicode_literals

from django.core.management.base import LabelCommand
from django.utils.six.moves import input

from cms.models import Page
from cms.models.pluginmodel import CMSPlugin

from six.moves import input

from .base import SubcommandsCommand


Expand Down
4 changes: 3 additions & 1 deletion cms/models/aliaspluginmodel.py
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
from django.db import models
from django.db.models import Q
from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.encoding import force_text

from cms.models import CMSPlugin, Placeholder

from six import python_2_unicode_compatible


@python_2_unicode_compatible
class AliasPluginModel(CMSPlugin):
Expand Down
4 changes: 3 additions & 1 deletion cms/models/pagemodel.py
Expand Up @@ -8,7 +8,7 @@
from django.db import models
from django.db.models.base import ModelState
from django.db.models.functions import Concat
from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.encoding import force_text
from django.utils.functional import cached_property
from django.utils.timezone import now
from django.utils.translation import (
Expand All @@ -28,6 +28,8 @@

from menus.menu_pool import menu_pool

from six import python_2_unicode_compatible

from treebeard.mp_tree import MP_Node


Expand Down
4 changes: 3 additions & 1 deletion cms/models/permissionmodels.py
Expand Up @@ -5,14 +5,16 @@
from django.contrib.auth.models import Group, UserManager
from django.contrib.sites.models import Site
from django.core.exceptions import ImproperlyConfigured, ValidationError
from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _

from cms.models import Page
from cms.models.managers import (PagePermissionManager,
GlobalPagePermissionManager)
from cms.utils.compat import DJANGO_1_11

from six import python_2_unicode_compatible


# Cannot use contrib.auth.get_user_model() at compile time.
user_app_name, user_model_name = settings.AUTH_USER_MODEL.rsplit('.', 1)
Expand Down
7 changes: 4 additions & 3 deletions cms/models/placeholdermodel.py
Expand Up @@ -8,8 +8,7 @@
from django.contrib.contenttypes.models import ContentType
from django.db import connection, models
from django.template.defaultfilters import title
from django.utils import six
from django.utils.encoding import force_text, python_2_unicode_compatible
from django.utils.encoding import force_text
from django.utils.translation import ugettext_lazy as _

from cms.cache import invalidate_cms_page_cache
Expand All @@ -26,6 +25,8 @@
from cms.utils import permissions
from cms.utils.conf import get_cms_setting

from six import python_2_unicode_compatible, string_types


@python_2_unicode_compatible
class Placeholder(models.Model):
Expand Down Expand Up @@ -460,7 +461,7 @@ def inner_plugin_iterator(lang):
if not vary_on:
# None, or an empty iterable
continue
if isinstance(vary_on, six.string_types):
if isinstance(vary_on, string_types):
if vary_on.lower() not in vary_list:
vary_list.add(vary_on.lower())
else:
Expand Down
3 changes: 2 additions & 1 deletion cms/models/placeholderpluginmodel.py
Expand Up @@ -2,7 +2,8 @@
from cms.models import CMSPlugin
from cms.models.fields import PlaceholderField
from django.db import models
from django.utils.encoding import python_2_unicode_compatible

from six import python_2_unicode_compatible


@python_2_unicode_compatible
Expand Down

0 comments on commit c44b6be

Please sign in to comment.