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

Adding django CMS 3 compatibility #50

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions djangocms_url_manager/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class UrlManagerConfig(AppConfig):
url_manager_supported_models = {}

def ready(self):
from .compat import CMS_36
from .compat import CMS_LT_4

if CMS_36:
if CMS_LT_4:
from .utils import parse_settings

self.url_manager_supported_models = parse_settings(
Expand Down
8 changes: 7 additions & 1 deletion djangocms_url_manager/cms_config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured

from cms.app_base import CMSAppConfig, CMSAppExtension
from cms.models import Page

from djangocms_url_manager.utils import get_page_search_results, parse_settings

from .models import Url

try:
from cms.app_base import CMSAppConfig, CMSAppExtension
# django CMS 3.x does not have a compatible configuration system
except ImportError:
CMSAppConfig = object
CMSAppExtension = object


class UrlCMSAppConfig(CMSAppConfig):
djangocms_url_manager_enabled = True
Expand Down
2 changes: 1 addition & 1 deletion djangocms_url_manager/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

CMS_VERSION = cms.__version__

CMS_36 = LooseVersion(CMS_VERSION) < LooseVersion("3.7")
CMS_LT_4 = LooseVersion(CMS_VERSION) < LooseVersion("4.0")


def get_page_placeholders(page, language=None):
Expand Down
12 changes: 8 additions & 4 deletions djangocms_url_manager/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@
from django.core.exceptions import ImproperlyConfigured
from django.db.models.base import ModelBase

from cms.models import PageContent

from djangocms_url_manager.compat import CMS_36
from djangocms_url_manager.compat import CMS_LT_4
from djangocms_url_manager.models import Url

try:
from cms.models import PageContent
# django CMS 3.x
except ImportError:
from cms.models import Title as PageContent


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, "settings" if CMS_LT_4 else "cms_config"
)
)
models = getattr(config, attr_name)
Expand Down
12 changes: 1 addition & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
INSTALL_REQUIREMENTS = [
"Django>=1.11,<3.0",
"django-cms",
"djangocms-attributes-field>=0.1.1",
]

TEST_REQUIREMENTS = [
"djangocms_helper",
"djangocms-versioning",
"djangocms-attributes-field<2.0.0", # django 1.11 compat
]


Expand All @@ -30,14 +25,9 @@
"Topic :: Software Development",
],
install_requires=INSTALL_REQUIREMENTS,
tests_require=TEST_REQUIREMENTS,
author="Divio AG",
author_email="[email protected]",
url="http://github.com/divio/djangocms-url-manager",
license="BSD",
test_suite="test_settings.run",
dependency_links=[
"http://github.com/divio/django-cms/tarball/release/4.0.x#egg=django-cms-4.0.0",
"http://github.com/divio/djangocms-versioning/tarball/master#egg=djangocms-versioning-0.0.23",
]
)
4 changes: 2 additions & 2 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,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 CMS_LT_4, get_page_placeholders
from djangocms_url_manager.constants import (
SELECT2_CONTENT_TYPE_OBJECT_URL_NAME,
SELECT2_URLS,
Expand Down Expand Up @@ -130,7 +130,7 @@ 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:
if CMS_LT_4 and published:
kwargs["published"] = True

page = create_page(
Expand Down
7 changes: 5 additions & 2 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@ djangocms_helper
pyflakes>=2.1.1
flake8
isort
django-classy-tags<2.0.0
django-sekizai<2.0.0
django-classy-tags<2.0.0 # django 1.11 and 2.1 compat
django-sekizai<2.0.0 # django 1.11 and 2.1 compat
djangocms-admin-style<2.0.0 # django 1.11 and 2.1 compat
django-treebeard<4.4 # django 1.11 and 2.1 compat
http://github.com/divio/djangocms-versioning/tarball/master#egg=djangocms-versioning
6 changes: 3 additions & 3 deletions tests/test_cms_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from cms.models import Page
from cms.test_utils.testcases import CMSTestCase

from djangocms_url_manager.compat import CMS_36
from djangocms_url_manager.compat import CMS_LT_4
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 +22,7 @@
)


@skipIf(CMS_36, "Test relevant only for CMS>=4.0")
@skipIf(CMS_LT_4, "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 +145,7 @@ def test_url_manager_search_helpers(self):
)


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

def tearDownClass():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

from cms.test_utils.testcases import CMSTestCase

from djangocms_url_manager.compat import CMS_36
from djangocms_url_manager.compat import CMS_LT_4
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")
@skipUnless(CMS_LT_4, "Test relevant only for CMS<4.0")
class CMSSettingsUnitTestCase(CMSTestCase):
def tearDown(self):
supported_models.cache_clear()
Expand Down
10 changes: 5 additions & 5 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from cms.models import Page, Placeholder

from djangocms_url_manager.compat import CMS_36
from djangocms_url_manager.compat import CMS_LT_4
from djangocms_url_manager.test_utils.polls.models import PollContent
from djangocms_url_manager.test_utils.polls.utils import (
get_all_poll_content_objects,
Expand All @@ -17,7 +17,7 @@


class UtilsTestCase(BaseUrlTestCase):
@skipUnless(CMS_36, "Test relevant only for CMS<4.0")
@skipUnless(CMS_LT_4, "Test relevant only for CMS<4.0")
def test_supported_models_for_cms36(self):
apps.get_app_config("djangocms_url_manager").ready()
self.assertDictEqual(
Expand All @@ -28,13 +28,13 @@ def test_supported_models_for_cms36(self):
},
)

@skipIf(CMS_36, "Test relevant only for CMS>=4.0")
@skipIf(CMS_LT_4, "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")
@skipUnless(CMS_LT_4, "Test relevant only for CMS<4.0")
@override_settings(
URL_MANAGER_SUPPORTED_MODELS=[
("cms.Page", get_published_pages_objects),
Expand All @@ -47,7 +47,7 @@ def test_is_model_available_method_for_cms36(self):
self.assertTrue(is_model_supported(Page))
self.assertFalse(is_model_supported(Placeholder))

@skipIf(CMS_36, "Test relevant only for CMS>=4.0")
@skipIf(CMS_LT_4, "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
20 changes: 10 additions & 10 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from cms.models import Page, User

from djangocms_url_manager.compat import CMS_36
from djangocms_url_manager.compat import CMS_LT_4

from .base import BaseUrlTestCase

Expand All @@ -22,7 +22,7 @@ def test_select2_view_no_permission(self):
response = self.client.get(self.select2_endpoint)
self.assertEqual(response.status_code, 403)

@skipUnless(CMS_36, "Test relevant only for CMS<4.0")
@skipUnless(CMS_LT_4, "Test relevant only for CMS<4.0")
def test_return_page_in_select2_view_for_cms36(self):
with self.login_user_context(self.superuser):
response = self.client.get(
Expand All @@ -40,7 +40,7 @@ def test_return_page_in_select2_view_for_cms36(self):
],
)

@skipIf(CMS_36, "Test relevant only for CMS>=4.0")
@skipIf(CMS_LT_4, "Test relevant only for CMS>=4.0")
def test_return_page_in_select2_view_for_cms40(self):
with self.login_user_context(self.superuser):
response = self.client.get(
Expand All @@ -51,7 +51,7 @@ def test_return_page_in_select2_view_for_cms40(self):
[p["id"] for p in response.json()["results"]], [self.page.pk, self.page2.pk]
)

@skipIf(CMS_36, "Test relevant only for CMS>=4.0")
@skipIf(CMS_LT_4, "Test relevant only for CMS>=4.0")
@skipUnless(
BaseUrlTestCase.is_versioning_enabled(), "Test only relevant for versioning"
)
Expand Down Expand Up @@ -89,7 +89,7 @@ def test_raise_error_when_return_unregistered_user_model_in_select2_view(self):
data={"content_id": ContentType.objects.get_for_model(User).id},
)

@skipUnless(CMS_36, "Test relevant only for CMS<4.0")
@skipUnless(CMS_LT_4, "Test relevant only for CMS<4.0")
def test_select2_view_set_limit_for_cms36(self):
self._create_page(title="test 3", language=self.language)
with self.login_user_context(self.superuser):
Expand All @@ -103,7 +103,7 @@ def test_select2_view_set_limit_for_cms36(self):
self.assertTrue(content["more"])
self.assertEqual(len(content["results"]), 1)

@skipIf(CMS_36, "Test relevant only for CMS>=4.0")
@skipIf(CMS_LT_4, "Test relevant only for CMS>=4.0")
def test_select2_view_set_limit_for_cms40(self):
self._create_page(title="test 3", language=self.language)
with self.login_user_context(self.superuser):
Expand Down Expand Up @@ -136,7 +136,7 @@ def test_select2_view_text_poll_content_repr(self):
self.assertEqual(response.status_code, 200)
self.assertEqual(response.json()["results"][0]["text"], str(self.poll_content))

@skipUnless(CMS_36, "Test relevant only for CMS<4.0")
@skipUnless(CMS_LT_4, "Test relevant only for CMS<4.0")
def test_select2_view_site_for_cms36(self):
with self.login_user_context(self.superuser):
response = self.client.get(
Expand All @@ -154,7 +154,7 @@ def test_select2_view_site_for_cms36(self):
],
)

@skipIf(CMS_36, "Test relevant only for CMS>=4.0")
@skipIf(CMS_LT_4, "Test relevant only for CMS>=4.0")
def test_select2_view_site_for_cms40(self):
with self.login_user_context(self.superuser):
response = self.client.get(
Expand All @@ -164,7 +164,7 @@ def test_select2_view_site_for_cms40(self):
self.assertEqual(response.status_code, 200)
self.assertEqual([a["id"] for a in response.json()["results"]], [self.page2.pk])

@skipUnless(CMS_36, "Test relevant only for CMS<4.0")
@skipUnless(CMS_LT_4, "Test relevant only for CMS<4.0")
def test_select2_page_view_pk_for_cms36(self):
page = (
Page.objects.published(self.site2.pk)
Expand All @@ -184,7 +184,7 @@ def test_select2_page_view_pk_for_cms36(self):
self.assertEqual(response.status_code, 200)
self.assertEqual([a["id"] for a in response.json()["results"]], [page])

@skipIf(CMS_36, "Test relevant only for CMS>=4.0")
@skipIf(CMS_LT_4, "Test relevant only for CMS>=4.0")
def test_select2_page_view_pk_for_cms40(self):
with self.login_user_context(self.superuser):
response = self.client.get(
Expand Down
9 changes: 5 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
envlist =
flake8
isort
py{35,36,37}-dj{111,20,21,22}-sqlite-cms40-{default,versioning}
py{36,37,38}-dj{111,20,21,22}-sqlite-cms40-{default,versioning}
py{36,37,38}-dj22-sqlite-{cms37,cms38}-default

skip_missing_interpreters=True

Expand All @@ -20,9 +21,9 @@ deps =
cms40: https://github.com/divio/django-cms/archive/release/4.0.x.zip

basepython =
py35: python3.5
py36: python3.6
py37: python3.7
py38: python3.8

commands =
{envpython} --version
Expand All @@ -32,8 +33,8 @@ commands =

[testenv:flake8]
commands = flake8
basepython = python3.5
basepython = python3.6

[testenv:isort]
commands = isort --recursive --check-only --diff {toxinidir}
basepython = python3.5
basepython = python3.6