Skip to content

Commit

Permalink
Add support for Django 3.1 (django-cms#186)
Browse files Browse the repository at this point in the history
* upgrade to django 3.1

* add missing changelog entries

* remove not supported version

* needs to be py2 compatible for now

* fixes django-cms#179 and django-cms#180

* whatever weirdness that was
  • Loading branch information
FinalAngel authored Sep 2, 2020
1 parent c5f1a4b commit 5728fe4
Show file tree
Hide file tree
Showing 35 changed files with 71 additions and 125 deletions.
31 changes: 14 additions & 17 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,41 +1,38 @@
language: python

dist: xenial
sudo: false

matrix:
include:
- python: 3.5
env: TOX_ENV='flake8'
- python: 3.5
env: TOX_ENV='isort'
# Django 1.11
- python: 2.7
env: DJANGO='dj111' CMS='cms34'
- python: 3.4
env: DJANGO='dj111' CMS='cms35'
- python: 3.5
env: DJANGO='dj111' CMS='cms36'
- python: 3.6
env: DJANGO='dj111' CMS='cms37'
# Django 2.1
- python: 3.6
env: DJANGO='dj21' CMS='cms36'
- python: 3.6
env: DJANGO='dj21' CMS='cms37'
# Django 2.2
- python: 3.5
env: DJANGO='dj22' CMS='cms37'
- python: 3.6
env: DJANGO='dj22' CMS='cms37'
- python: 3.7
env: DJANGO='dj22' CMS='cms37'
- python: 3.8
env: DJANGO='dj22' CMS='cms37'
# Django 3.0, always run the lowest supported version
- python: 3.6
env: DJANGO='dj30' CMS='cms37'
# Django 3.1, always run the lowest supported version
- python: 3.6
env: DJANGO='dj31' CMS='cms38'
allow_failures:
- python: 3.6
env: DJANGO='dj31' CMS='cms38'

install:
- pip install coverage isort tox
- "if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then export PY_VER=py27; fi"
- "if [[ $TRAVIS_PYTHON_VERSION == '3.4' ]]; then export PY_VER=py34; fi"
- "if [[ $TRAVIS_PYTHON_VERSION == '3.5' ]]; then export PY_VER=py35; fi"
- "if [[ $TRAVIS_PYTHON_VERSION == '3.6' ]]; then export PY_VER=py36; fi"
- "if [[ $TRAVIS_PYTHON_VERSION == '3.7' ]]; then export PY_VER=py37; fi"
- "if [[ $TRAVIS_PYTHON_VERSION == '3.8' ]]; then export PY_VER=py37; fi"
- "if [[ ${DJANGO}z != 'z' ]]; then export TOX_ENV=$PY_VER-$DJANGO-$CMS; fi"

script:
Expand Down
10 changes: 10 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@ Changelog
=========


3.0.0 (unreleased)
==================

* Added support for Django 3.1
* Dropped support for Python 2.7 and Python 3.4
* Dropped support for Django < 2.2
* Fixed an issue when using django-select2 where jQuery is missing
* Decreased django-select2's ``data-minimum-input-length`` option to 0


2.6.1 (2020-05-12)
==================

Expand Down
8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ file for additional dependencies:

|python| |django| |djangocms|

* Django Filer 1.5.0 or higher
* Django Filer 1.7 or higher

Make sure `django Filer <http://django-filer.readthedocs.io/en/latest/installation.html>`_
is installed and configured appropriately.
Expand Down Expand Up @@ -128,9 +128,9 @@ You can run tests by executing::
.. |coverage| image:: https://codecov.io/gh/divio/djangocms-link/branch/master/graph/badge.svg
:target: https://codecov.io/gh/divio/djangocms-link

.. |python| image:: https://img.shields.io/badge/python-2.7%20%7C%203.4+-blue.svg
.. |python| image:: https://img.shields.io/badge/python-3.5+-blue.svg
:target: https://pypi.org/project/djangocms-link/
.. |django| image:: https://img.shields.io/badge/django-1.11%20%7C%202.2%20%7C%203.0-blue.svg
.. |django| image:: https://img.shields.io/badge/django-2.2,%203.0,%203.1-blue.svg
:target: https://www.djangoproject.com/
.. |djangocms| image:: https://img.shields.io/badge/django%20CMS-3.4%2B-blue.svg
.. |djangocms| image:: https://img.shields.io/badge/django%20CMS-3.7%2B-blue.svg
:target: https://www.django-cms.org/
1 change: 0 additions & 1 deletion aldryn_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from aldryn_client import forms


Expand Down
1 change: 0 additions & 1 deletion djangocms_link/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# -*- coding: utf-8 -*-
__version__ = '2.6.1'
11 changes: 5 additions & 6 deletions djangocms_link/cms_plugins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# -*- coding: utf-8 -*-
from django.contrib.sites.models import Site
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
Expand Down Expand Up @@ -42,18 +41,18 @@ class LinkPlugin(CMSPluginBase):

@classmethod
def get_render_queryset(cls):
queryset = super(LinkPlugin, cls).get_render_queryset()
queryset = super().get_render_queryset()
return queryset.select_related('internal_link')

def get_render_template(self, context, instance, placeholder):
return 'djangocms_link/{}/link.html'.format(instance.template)

def render(self, context, instance, placeholder):
context['link'] = instance.get_link()
return super(LinkPlugin, self).render(context, instance, placeholder)
return super().render(context, instance, placeholder)

def get_form(self, request, obj=None, **kwargs):
form_class = super(LinkPlugin, self).get_form(request, obj, **kwargs)
form_class = super().get_form(request, obj, **kwargs)

if obj and obj.page and hasattr(obj.page, 'site') and obj.page.site:
site = obj.page.site
Expand All @@ -64,7 +63,7 @@ def get_form(self, request, obj=None, **kwargs):

class Form(form_class):
def __init__(self, *args, **kwargs):
super(Form, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.for_site(site)

return Form
Expand Down
1 change: 0 additions & 1 deletion djangocms_link/fields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from django.conf import settings


Expand Down
18 changes: 15 additions & 3 deletions djangocms_link/fields_select2.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
from django import forms

from cms.models import Page

from django_select2.forms import ModelSelect2Widget


class Select2PageSearchFieldMixin(object):
class Select2PageSearchFieldMixin:
search_fields = [
'title_set__title__icontains',
'title_set__menu_title__icontains',
Expand All @@ -17,15 +16,28 @@ class Select2PageSearchFieldMixin(object):
class Select2PageSelectWidget(Select2PageSearchFieldMixin, ModelSelect2Widget):
site = None

# show entries when clicking on it
def build_attrs(self, base_attrs, extra_attrs=None):
default_attrs = {"data-minimum-input-length": 0}
default_attrs.update(base_attrs)
attrs = super().build_attrs(default_attrs, extra_attrs=extra_attrs)
return attrs

def get_queryset(self):
if self.site:
return Page.objects.drafts().on_site(self.site)
return Page.objects.drafts()

# we need to implement jQuery ourselves, see #180
class Media:
js = (
"https://code.jquery.com/jquery-3.5.1.slim.min.js",
)


class Select2PageSearchField(forms.ModelChoiceField):
widget = Select2PageSelectWidget()

def __init__(self, *args, **kwargs):
kwargs['queryset'] = self.widget.get_queryset()
super(Select2PageSearchField, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
7 changes: 2 additions & 5 deletions djangocms_link/forms.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.forms.models import ModelForm
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from djangocms_attributes_field.widgets import AttributesWidget

Expand Down Expand Up @@ -33,5 +30,5 @@ class Meta:
exclude = ('page', 'position', 'placeholder', 'language', 'plugin_type')

def __init__(self, *args, **kwargs):
super(LinkForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.fields['attributes'].widget = AttributesWidget()
3 changes: 0 additions & 3 deletions djangocms_link/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import django.db.models.deletion
from django.db import migrations, models

Expand Down
3 changes: 0 additions & 3 deletions djangocms_link/migrations/0002_auto_20140929_1705.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


Expand Down
3 changes: 0 additions & 3 deletions djangocms_link/migrations/0003_auto_20150212_1310.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


Expand Down
3 changes: 0 additions & 3 deletions djangocms_link/migrations/0004_auto_20150708_1133.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models

import djangocms_link.validators
Expand Down
3 changes: 0 additions & 3 deletions djangocms_link/migrations/0005_auto_20151003_1710.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-02-26 14:19
from __future__ import unicode_literals

import django.db.models.deletion
from django.db import migrations, models

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.2 on 2016-03-04 04:44
from __future__ import unicode_literals

import django.db.models.deletion
from django.db import migrations, models

Expand Down
3 changes: 0 additions & 3 deletions djangocms_link/migrations/0008_link_attributes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-06-15 20:45
from __future__ import unicode_literals

from django.db import migrations

import djangocms_attributes_field.fields
Expand Down
3 changes: 0 additions & 3 deletions djangocms_link/migrations/0009_auto_20160705_1344.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-07-05 17:44
from __future__ import unicode_literals

from django.db import migrations

import djangocms_attributes_field.fields
Expand Down
3 changes: 0 additions & 3 deletions djangocms_link/migrations/0010_adapted_fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import django.db.models.deletion
from django.db import migrations, models

Expand Down
3 changes: 0 additions & 3 deletions djangocms_link/migrations/0011_fixed_null_values.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models


Expand Down
3 changes: 0 additions & 3 deletions djangocms_link/migrations/0012_removed_null.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models

import djangocms_link.validators
Expand Down
3 changes: 0 additions & 3 deletions djangocms_link/migrations/0013_fix_hostname.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations, models

import djangocms_link.validators
Expand Down
1 change: 0 additions & 1 deletion djangocms_link/migrations/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
# -*- coding: utf-8 -*-
13 changes: 4 additions & 9 deletions djangocms_link/models.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
# -*- coding: utf-8 -*-
"""
Enables the user to add a "Link" plugin that displays a link
using the HTML <a> tag.
"""
from __future__ import unicode_literals

from django.conf import settings
from django.contrib.sites.models import Site
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.encoding import force_text
from django.utils.translation import ugettext
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext
from django.utils.translation import gettext_lazy as _

from cms.models import CMSPlugin, Page

from djangocms_attributes_field.fields import AttributesField
from filer.fields.file import FilerFileField
from six import python_2_unicode_compatible

from .validators import IntranetURLValidator

Expand Down Expand Up @@ -49,7 +45,6 @@ def get_templates():
)


@python_2_unicode_compatible
class AbstractLink(CMSPlugin):
# used by django CMS search
search_fields = ('name', )
Expand Down Expand Up @@ -147,7 +142,7 @@ def __str__(self):
def get_short_description(self):
if self.name and self.get_link():
return '{} ({})'.format(self.name, self.get_link())
return self.name or self.get_link() or ugettext('<link is missing>')
return self.name or self.get_link() or gettext('<link is missing>')

def get_link(self):
if self.internal_link:
Expand Down Expand Up @@ -207,7 +202,7 @@ def get_link(self):
return link

def clean(self):
super(AbstractLink, self).clean()
super().clean()
field_names = (
'external_link',
'internal_link',
Expand Down
3 changes: 1 addition & 2 deletions djangocms_link/validators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import re

from django.core.validators import URLValidator
Expand Down Expand Up @@ -28,7 +27,7 @@ class IntranetURLValidator(URLValidator):
host_re = '(' + hostname_re + domain_re + tld_re + '|localhost)'

def __init__(self, intranet_host_re=None, **kwargs):
super(IntranetURLValidator, self).__init__(**kwargs)
super().__init__(**kwargs)
if intranet_host_re:
self.host_re = (
'(' + self.hostname_re + self.domain_re + self.tld_re +
Expand Down
Loading

0 comments on commit 5728fe4

Please sign in to comment.