From 387e20cfbed4aca55e7da3aea04b06a6cda98cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20P=C5=82=C3=B3ciennik?= Date: Fri, 16 Nov 2018 12:43:56 +0100 Subject: [PATCH] Add support for Django 1.11/2.0/2.1 and drop for 1.8/1.9/1.10 (#149) --- .travis.yml | 22 ++++++++++------------ CHANGELOG.rst | 6 +++++- README.rst | 4 ++-- djangocms_link/cms_plugins.py | 1 - djangocms_link/fields.py | 9 ++------- djangocms_link/migrations/0001_initial.py | 2 +- djangocms_link/models.py | 14 +++++++++++++- setup.py | 4 ++-- tests/requirements.txt | 4 ++-- tests/tests_model.py | 5 ++--- tox.ini | 16 ++++++++-------- 11 files changed, 47 insertions(+), 40 deletions(-) diff --git a/.travis.yml b/.travis.yml index f7d97f32..6571719b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,18 +4,16 @@ sudo: false env: - TOX_ENV=flake8 - - TOX_ENV=py27-latest - - TOX_ENV=py34-latest - # Django 1.8 - - TOX_ENV=py27-dj18-cms34 - - TOX_ENV=py27-dj18-cms33 - - TOX_ENV=py34-dj18-cms34 - - TOX_ENV=py34-dj18-cms33 - # Django 1.9 - - TOX_ENV=py27-dj19-cms34 - - TOX_ENV=py27-dj19-cms33 - - TOX_ENV=py34-dj19-cms34 - - TOX_ENV=py34-dj19-cms33 + # Django 1.11 + - TOX_ENV=py27-dj111-cms35 + - TOX_ENV=py35-dj111-cms35 + - TOX_ENV=py35-dj111-cms36 + # Django 2.0 + - TOX_ENV=py35-dj20-cms35 + - TOX_ENV=py35-dj20-cms36 + # Django 2.1 + - TOX_ENV=py35-dj21-cms35 + - TOX_ENV=py35-dj21-cms36 install: - pip install tox coverage diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 4d488fc6..89bd0bb5 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,9 +3,13 @@ Changelog ========= -2.1.3 (unreleased) +2.2.0 (unreleased) ================== +* Added support for Django 1.11, 2.0 and 2.1 +* Removed support for Django 1.8, 1.9, 1.10 +* Adapted testing infrastructure (tox/travis) to incorporate + django CMS 3.5 and 4.0 * Fixed a bug where overriding ``Site.__str__`` resulted in invalid urls. diff --git a/README.rst b/README.rst index 4657769a..c77550dd 100644 --- a/README.rst +++ b/README.rst @@ -36,8 +36,8 @@ Documentation See ``REQUIREMENTS`` in the `setup.py `_ file for additional dependencies: -* Python 2.7, 3.3 or higher -* Django 1.8 or higher +* Python 2.7, 3.4 or higher +* Django 1.11 or higher Installation diff --git a/djangocms_link/cms_plugins.py b/djangocms_link/cms_plugins.py index 1022ca0e..cebe8517 100644 --- a/djangocms_link/cms_plugins.py +++ b/djangocms_link/cms_plugins.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- -from django.conf import settings from django.utils.translation import ugettext_lazy as _ from django.contrib.sites.models import Site diff --git a/djangocms_link/fields.py b/djangocms_link/fields.py index f13e56b4..569bca5e 100644 --- a/djangocms_link/fields.py +++ b/djangocms_link/fields.py @@ -1,16 +1,11 @@ -from distutils.version import LooseVersion - from django.conf import settings ENABLE_SELECT2 = getattr(settings, 'DJANGOCMS_LINK_USE_SELECT2', False) if ENABLE_SELECT2 and 'django_select2' in settings.INSTALLED_APPS: - import django_select2 - - select2_version = LooseVersion(django_select2.__version__) - if select2_version >= LooseVersion('5'): + try: from djangocms_link.fields_select2 import Select2PageSearchField as PageSearchField - else: + except ImportError: from djangocms_link.fields_select2_legacy import Select2LegacyPageSearchField as PageSearchField else: from cms.forms.fields import PageSelectFormField as PageSearchField diff --git a/djangocms_link/migrations/0001_initial.py b/djangocms_link/migrations/0001_initial.py index c9b4edd9..58413abd 100644 --- a/djangocms_link/migrations/0001_initial.py +++ b/djangocms_link/migrations/0001_initial.py @@ -15,7 +15,7 @@ class Migration(migrations.Migration): migrations.CreateModel( name='Link', fields=[ - ('cmsplugin_ptr', models.OneToOneField(serialize=False, parent_link=True, auto_created=True, to='cms.CMSPlugin', primary_key=True)), + ('cmsplugin_ptr', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, serialize=False, parent_link=True, auto_created=True, to='cms.CMSPlugin', primary_key=True)), ('name', models.CharField(verbose_name='name', max_length=256)), ('url', models.URLField(verbose_name='link', blank=True, null=True)), ('anchor', models.CharField(help_text='This applies only to page and text links.', blank=True, default='', max_length=128, verbose_name='anchor')), diff --git a/djangocms_link/models.py b/djangocms_link/models.py index 212f83bd..beda48bb 100644 --- a/djangocms_link/models.py +++ b/djangocms_link/models.py @@ -5,6 +5,8 @@ """ from __future__ import unicode_literals +from distutils.version import LooseVersion + from django.contrib.sites.models import Site from django.conf import settings from django.core.exceptions import ValidationError @@ -12,6 +14,7 @@ from django.utils.encoding import python_2_unicode_compatible, force_text from django.utils.translation import ugettext, ugettext_lazy as _ +import cms from cms.models import CMSPlugin, Page from djangocms_attributes_field.fields import AttributesField @@ -31,6 +34,7 @@ def get_templates(): ) return choices + HOSTNAME = getattr( settings, 'DJANGOCMS_LINK_INTRANET_HOSTNAME_PATTERN', @@ -44,6 +48,7 @@ def get_templates(): ('_top', _('Delegate to top')), ) + @python_2_unicode_compatible class AbstractLink(CMSPlugin): # used by django CMS search @@ -137,7 +142,14 @@ def get_link(self): # simulate the call to the unauthorized CMSPlugin.page property cms_page = self.placeholder.page if self.placeholder_id else None - if ref_page.site_id != getattr(cms_page, 'site_id', None): + if getattr(cms_page, 'node'): + ref_page_site_id = ref_page.node.site_id + cms_page_site_id = getattr(cms_page.node, 'site_id', None) + else: + ref_page_site_id = ref_page.site_id + cms_page_site_id = getattr(cms_page, 'site_id', None) + + if ref_page_site_id != cms_page_site_id: ref_site = Site.objects._get_site_by_id(ref_page.site_id).domain link = '//{}{}'.format(ref_site, link) elif self.external_link: diff --git a/setup.py b/setup.py index cf44f332..bb8b42b2 100644 --- a/setup.py +++ b/setup.py @@ -6,8 +6,8 @@ REQUIREMENTS = [ - 'django-cms>=3.2.0', - 'djangocms-attributes-field>=0.1.1', + 'django-cms>=3.4.5', + 'djangocms-attributes-field>=0.4.0', ] diff --git a/tests/requirements.txt b/tests/requirements.txt index 221c8a54..ae6f727a 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,8 +1,8 @@ # requirements from setup.py -django-select2>=5.0 +django-select2>=5.11 # other requirements djangocms-text-ckeditor html5lib<0.99999999 -djangocms-helper>=0.9.2,<0.10 +djangocms-helper>=1.1.0,<1.2.0 tox coverage diff --git a/tests/tests_model.py b/tests/tests_model.py index 24ebc315..22dd83fa 100644 --- a/tests/tests_model.py +++ b/tests/tests_model.py @@ -61,14 +61,13 @@ def test_link(self): external_link='http://example.com', ) self.assertEqual(plugin.get_link(), 'http://example.com') - plugin = add_plugin( page.placeholders.get(slot='content'), 'LinkPlugin', 'en', internal_link=page, ) - self.assertEqual(plugin.get_link(), '/en/') + self.assertEqual(plugin.get_link(), '/en/help/') plugin = add_plugin( page.placeholders.get(slot='content'), @@ -77,7 +76,7 @@ def test_link(self): internal_link=page, anchor='some-h1', ) - self.assertEqual(plugin.get_link(), '/en/#some-h1') + self.assertEqual(plugin.get_link(), '/en/help/#some-h1') plugin = add_plugin( page.placeholders.get(slot='content'), diff --git a/tox.ini b/tox.ini index 13357f33..ea570ec2 100644 --- a/tox.ini +++ b/tox.ini @@ -1,9 +1,9 @@ [tox] envlist = flake8 - py{34,27}-latest - py{34,27}-dj18-cms{34,33} - py{34,27}-dj19-cms{34,33} + py{27,34,35,36}-dj111-cms{34,35} + py{34,35,36}-dj20-cms{35,36} + py{35,36}-dj21-cms{35,36} skip_missing_interpreters=True @@ -11,11 +11,11 @@ skip_missing_interpreters=True [testenv] deps = -r{toxinidir}/tests/requirements.txt - dj18: Django>=1.8,<1.9 - dj19: Django>=1.9,<1.10 - latest: django-cms - cms33: django-cms>=3.3,<3.4 - cms34: django-cms>=3.4,<3.5 + dj111: Django>=1.11,<2.0 + dj20: Django>=2.0,<2.1 + dj21: Django>=2.1,<2.2 + cms35: django-cms>=3.5,<3.6 + cms36: https://github.com/divio/django-cms/archive/release/3.6.x.zip commands = {envpython} --version {env:COMMAND:coverage} erase