Skip to content

Commit

Permalink
Add support for Django 1.11/2.0/2.1 and drop for 1.8/1.9/1.10 (django…
Browse files Browse the repository at this point in the history
  • Loading branch information
vthaian authored Nov 16, 2018
1 parent 9528fe5 commit 387e20c
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 40 deletions.
22 changes: 10 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.


Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ Documentation
See ``REQUIREMENTS`` in the `setup.py <https://github.com/divio/djangocms-link/blob/master/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
Expand Down
1 change: 0 additions & 1 deletion djangocms_link/cms_plugins.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
9 changes: 2 additions & 7 deletions djangocms_link/fields.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion djangocms_link/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')),
Expand Down
14 changes: 13 additions & 1 deletion djangocms_link/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@
"""
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
from django.db import models
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
Expand All @@ -31,6 +34,7 @@ def get_templates():
)
return choices


HOSTNAME = getattr(
settings,
'DJANGOCMS_LINK_INTRANET_HOSTNAME_PATTERN',
Expand All @@ -44,6 +48,7 @@ def get_templates():
('_top', _('Delegate to top')),
)


@python_2_unicode_compatible
class AbstractLink(CMSPlugin):
# used by django CMS search
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
]


Expand Down
4 changes: 2 additions & 2 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -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
5 changes: 2 additions & 3 deletions tests/tests_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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'),
Expand Down
16 changes: 8 additions & 8 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
[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


[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
Expand Down

0 comments on commit 387e20c

Please sign in to comment.