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

add support for django 4.2 and python 3.10, drop support for django 2… #86

Closed
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
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.10'
- 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.10'
- run: python -m pip install isort
- name: isort
uses: liskin/gh-problem-matcher-wrap@v1
Expand Down
8 changes: 4 additions & 4 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.7, 3.8, 3.9, ] # latest release minus two
python-version: [ 3.8, 3.9, '3.10'] # latest release minus two
requirements-file: [
dj22_cms40.txt,
dj32_cms40.txt,
dj42_cms40.txt,
]
os: [
ubuntu-20.04,
Expand Down Expand Up @@ -43,10 +43,10 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ 3.7, 3.8, 3.9, ] # latest release minus two
python-version: [ 3.8, 3.9, '3.10'] # latest release minus two
requirements-file: [
dj22_cms40.txt,
dj32_cms40.txt,
dj42_cms40.txt,
]

steps:
Expand Down
5 changes: 3 additions & 2 deletions djangocms_url_manager/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class UrlAdmin(*url_admin_classes):
def get_urls(self):
return urlpatterns + super().get_urls()

@admin.display(
description="URL"
)
def get_model_url(self, obj):
return obj.get_url(obj.site)

Expand All @@ -62,8 +65,6 @@ def get_search_results(self, request, queryset, search_term):

return queryset, use_distinct

get_model_url.short_description = "URL"

def change_view(self, request, object_id, form_url='', extra_context=None):
extra_context = extra_context or {}
# Provide additional context to the changeform
Expand Down
11 changes: 0 additions & 11 deletions djangocms_url_manager/apps.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,8 @@
from django.apps import AppConfig
from django.conf import settings
from django.utils.translation import gettext_lazy as _


class UrlManagerConfig(AppConfig):
name = "djangocms_url_manager"
verbose_name = _("django CMS URL Manager")
url_manager_supported_models = {}

def ready(self):
from .compat import CMS_36

if CMS_36:
from .utils import parse_settings

self.url_manager_supported_models = parse_settings(
settings, "URL_MANAGER_SUPPORTED_MODELS"
)
8 changes: 3 additions & 5 deletions djangocms_url_manager/compat.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from distutils.version import LooseVersion
import django

import cms
from packaging.version import Version


CMS_VERSION = cms.__version__

CMS_36 = LooseVersion(CMS_VERSION) < LooseVersion("3.7")
DJANGO_4_2 = Version(django.get_version()) >= Version('4.2') and Version(django.get_version()) < Version('4.3')


def get_page_placeholders(page, language=None):
Expand Down
10 changes: 5 additions & 5 deletions djangocms_url_manager/urls.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
from django.urls import re_path
from django.urls import path

from . import constants, views


urlpatterns = [
re_path(
r"^select2/$",
path(
"select2/",
views.ContentTypeObjectSelect2View.as_view(),
name=constants.SELECT2_CONTENT_TYPE_OBJECT_URL_NAME,
),
re_path(
r"^select2/urls/$", views.UrlSelect2View.as_view(), name=constants.SELECT2_URLS
path(
"select2/urls/", views.UrlSelect2View.as_view(), name=constants.SELECT2_URLS
),
]
7 changes: 3 additions & 4 deletions djangocms_url_manager/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import functools
from collections import Iterable, OrderedDict
from collections import OrderedDict
from collections.abc import Iterable
from functools import lru_cache

from django.apps import apps
Expand All @@ -9,15 +10,13 @@

from cms.models import PageContent

from djangocms_url_manager.compat import CMS_36


def parse_settings(config, attr_name):
url_manager_supported_models = OrderedDict()
if not hasattr(config, attr_name):
raise ImproperlyConfigured(
"{} must be defined in your {}".format(
attr_name, "settings" if CMS_36 else "cms_config"
attr_name, "cms_config"
)
)
models = getattr(config, attr_name)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


INSTALL_REQUIREMENTS = [
"Django>=2.2,<4.0",
"Django>=3.2,<5.0",
"django-cms",
"djangocms-attributes-field",
]
Expand Down
7 changes: 7 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from djangocms_url_manager.compat import DJANGO_4_2


if not DJANGO_4_2: # TODO: remove when dropping support for Django < 4.2
from django.test.testcases import TransactionTestCase

TransactionTestCase.assertQuerySetEqual = TransactionTestCase.assertQuerysetEqual
5 changes: 1 addition & 4 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from cms.utils.urlutils import admin_reverse

from djangocms_url_manager.admin import UrlAdmin
from djangocms_url_manager.compat import CMS_36, get_page_placeholders
from djangocms_url_manager.compat import get_page_placeholders
from djangocms_url_manager.constants import (
SELECT2_CONTENT_TYPE_OBJECT_URL_NAME,
SELECT2_URLS,
Expand Down Expand Up @@ -148,9 +148,6 @@ def _create_page(self, title, language=None, site=None, published=True, **kwargs
if self.is_versioning_enabled() and not kwargs.get("created_by"):
kwargs["created_by"] = self.superuser

if CMS_36 and published:
kwargs["published"] = True

page = create_page(
title=title,
language=language,
Expand Down
3 changes: 0 additions & 3 deletions tests/requirements/dj22_cms40.txt

This file was deleted.

5 changes: 5 additions & 0 deletions tests/requirements/dj32_cms40.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
-r requirements_base.txt

Django>=3.2,<4.0

# Unreleased django-cms 4.0 compatible packages
https://github.com/django-cms/django-cms/tarball/release/4.0.1.x#egg=django-cms
https://github.com/django-cms/djangocms-versioning/tarball/1.2.2#egg=djangocms-versioning
https://github.com/django-cms/djangocms-moderation/tarball/2.1.5#egg=djangocms-moderation
8 changes: 8 additions & 0 deletions tests/requirements/dj42_cms40.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-r requirements_base.txt

Django>=4.2,<5.0

# Unreleased django 4.2 compatible packages
https://github.com/django-cms/django-cms/tarball/release/4.0.1.x#egg=django-cms
https://github.com/joshyu/djangocms-versioning/tarball/feat/django-42-compatible#egg=djangocms-versioning
https://github.com/FidelityInternational/djangocms-moderation/tarball/feature/django-42-compat#egg=djangocms-moderation
9 changes: 2 additions & 7 deletions tests/requirements/requirements_base.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
coverage
django-app-helper
django-classy-tags
django-formtools==2.2
django-formtools>=2.4.1
django-sekizai
django-treebeard
djangocms-admin-style
djangocms-attributes-field
factory-boy
flake8
isort
pyflakes>=2.1.1

# Unreleased django-cms 4.0 compatible packages
https://github.com/django-cms/django-cms/tarball/develop-4#egg=django-cms
https://github.com/django-cms/djangocms-versioning/tarball/master#egg=djangocms-versioning
https://github.com/django-cms/djangocms-moderation/tarball/master#egg=djangocms-moderation
pyflakes
4 changes: 0 additions & 4 deletions tests/test_cms_config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from importlib import reload
from unittest import skipIf
from unittest.mock import Mock

from django.conf import settings
Expand All @@ -9,7 +8,6 @@
from cms.models import Page
from cms.test_utils.testcases import CMSTestCase

from djangocms_url_manager.compat import CMS_36
from djangocms_url_manager.test_utils.polls.models import Poll, PollContent
from djangocms_url_manager.test_utils.polls.utils import (
get_all_poll_content_objects,
Expand All @@ -22,7 +20,6 @@
)


@skipIf(CMS_36, "Test relevant only for CMS>=4.0")
class UrlManagerCMSExtensionTestCase(CMSTestCase):
def test_missing_cms_config_url_manager_supported_models_attribute(self):
"""Tests, if the url_manager_supported_models attribute has not been specified,
Expand Down Expand Up @@ -145,7 +142,6 @@ def test_url_manager_search_helpers(self):
)


@skipIf(CMS_36, "Test relevant only for CMS>=4.0")
class NavigationSettingTestCase(TestCase):

def tearDownClass():
Expand Down
5 changes: 2 additions & 3 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from unittest import skipUnless
from unittest import skip

from django.apps import apps
from django.conf import settings
Expand All @@ -7,13 +7,12 @@

from cms.test_utils.testcases import CMSTestCase

from djangocms_url_manager.compat import CMS_36
from djangocms_url_manager.test_utils.polls.models import PollContent
from djangocms_url_manager.test_utils.polls.utils import get_all_poll_content_objects
from djangocms_url_manager.utils import supported_models


@skipUnless(CMS_36, "Test relevant only for CMS<4.0")
@skip("Skip test, as dropped support for python < 3.7.")
class CMSSettingsUnitTestCase(CMSTestCase):
def tearDown(self):
supported_models.cache_clear()
Expand Down
36 changes: 1 addition & 35 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,19 @@
from unittest import skipIf, skipUnless

from django.apps import apps
from django.test import override_settings

from cms.models import Page, Placeholder

from djangocms_url_manager.compat import CMS_36
from djangocms_url_manager.test_utils.polls.models import PollContent
from djangocms_url_manager.test_utils.polls.utils import (
get_all_poll_content_objects,
get_published_pages_objects,
)
from djangocms_url_manager.test_utils.polls.utils import get_all_poll_content_objects
from djangocms_url_manager.utils import is_model_supported, supported_models

from .base import BaseUrlTestCase


class UtilsTestCase(BaseUrlTestCase):
@skipUnless(CMS_36, "Test relevant only for CMS<4.0")
def test_supported_models_for_cms36(self):
apps.get_app_config("djangocms_url_manager").ready()
self.assertDictEqual(
supported_models(),
{
Page: get_published_pages_objects,
PollContent: get_all_poll_content_objects,
},
)

@skipIf(CMS_36, "Test relevant only for CMS>=4.0")
def test_supported_models_for_cms40(self):
self.assertDictEqual(
supported_models(), {Page: None, PollContent: get_all_poll_content_objects}
)

@skipUnless(CMS_36, "Test relevant only for CMS<4.0")
@override_settings(
URL_MANAGER_SUPPORTED_MODELS=[
("cms.Page", get_published_pages_objects),
("polls.PollContent", get_all_poll_content_objects),
]
)
def test_is_model_available_method_for_cms36(self):
apps.get_app_config("djangocms_url_manager").ready()
self.assertTrue(is_model_supported(PollContent))
self.assertTrue(is_model_supported(Page))
self.assertFalse(is_model_supported(Placeholder))

@skipIf(CMS_36, "Test relevant only for CMS>=4.0")
def test_is_model_available_method_for_cms40(self):
self.assertTrue(is_model_supported(PollContent))
self.assertTrue(is_model_supported(Page))
Expand Down
Loading
Loading