diff --git a/.gitignore b/.gitignore index 55988565..84e31a41 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,26 @@ -*.pyc +*.py[cod] +*$py.class *.egg-info -*.egg/ +*.log +*.pot .DS_Store +.coverage/ +.eggs/ .idea/ +.project/ +.pydevproject/ +.settings/ .tox/ -.eggs/ -dist/ +__pycache__/ build/ +dist/ +env/ + +/~ +/node_modules +.sass-cache +*.css.map +npm-debug.log +package-lock.json + +local.sqlite diff --git a/.travis.yml b/.travis.yml index 787070fc..6f9e5f37 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,10 +6,12 @@ matrix: include: - python: 3.5 env: TOX_ENV='flake8' - # Django 1.11 + - python: 3.5 + env: TOX_ENV='isort' + # Django 1.11 - python: 2.7 env: DJANGO='dj111' CMS='cms34' - - python: 3.5 + - python: 3.4 env: DJANGO='dj111' CMS='cms35' - python: 3.5 env: DJANGO='dj111' CMS='cms36' @@ -17,13 +19,15 @@ matrix: - python: 3.5 env: DJANGO='dj20' CMS='cms36' # Django 2.1 - - python: 3.5 + - python: 3.6 env: DJANGO='dj21' CMS='cms36' install: - - pip install tox coverage + - 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 [[ ${DJANGO}z != 'z' ]]; then export TOX_ENV=$PY_VER-$DJANGO-$CMS; fi" script: diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 3dae13b5..e985a869 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,15 @@ Changelog ========= + +2.3.2 (unreleased) +================== + +* Extended test matrix +* Added isort and adapted imports +* Adapted code base to align with other supported addons + + 2.3.1 (2018-12-20) ================== diff --git a/README.rst b/README.rst index c77550dd..9ee5186f 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,6 @@ django CMS Link =============== - |pypi| |build| |coverage| **django CMS Link** is a plugin for `django CMS `_ that @@ -26,6 +25,10 @@ feedback in the form of issues and pull requests. Before submitting your pull request, please review our `contribution guidelines `_. +We're grateful to all contributors who have helped create and maintain this package. +Contributors are listed at the `contributors `_ +section. + One of the easiest contributions you can make is helping to translate this addon on `Transifex `_. @@ -36,8 +39,7 @@ Documentation See ``REQUIREMENTS`` in the `setup.py `_ file for additional dependencies: -* Python 2.7, 3.4 or higher -* Django 1.11 or higher +|python| |django| |djangocms| Installation @@ -106,9 +108,7 @@ for simpler use of internal links. You need to manually enable it by: Running Tests ------------- -You can run tests by executing: - -.. code-block:: bash +You can run tests by executing:: virtualenv env source env/bin/activate @@ -122,3 +122,10 @@ You can run tests by executing: :target: https://travis-ci.org/divio/djangocms-link .. |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 + :target: https://pypi.org/project/djangocms-link/ +.. |django| image:: https://img.shields.io/badge/django-1.11%20%7C%202.0%20%7C%202.1-blue.svg + :target: https://www.djangoproject.com/ +.. |djangocms| image:: https://img.shields.io/badge/django%20CMS-3.4%2B-blue.svg + :target: https://www.django-cms.org/ diff --git a/djangocms_link/cms_plugins.py b/djangocms_link/cms_plugins.py index 46074d8c..39693f23 100644 --- a/djangocms_link/cms_plugins.py +++ b/djangocms_link/cms_plugins.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from django.utils.translation import ugettext_lazy as _ from django.contrib.sites.models import Site +from django.utils.translation import ugettext_lazy as _ from cms.plugin_base import CMSPluginBase from cms.plugin_pool import plugin_pool @@ -59,7 +59,7 @@ def get_form(self, request, obj=None, **kwargs): site = obj.page.site elif self.page and self.page.site: site = self.page.site - except: + except: # noqa site = Site.objects.get_current() else: site = Site.objects.get_current() diff --git a/djangocms_link/fields.py b/djangocms_link/fields.py index 569bca5e..fec5a4e4 100644 --- a/djangocms_link/fields.py +++ b/djangocms_link/fields.py @@ -1,11 +1,13 @@ +# -*- coding: utf-8 -*- from django.conf import settings + ENABLE_SELECT2 = getattr(settings, 'DJANGOCMS_LINK_USE_SELECT2', False) if ENABLE_SELECT2 and 'django_select2' in settings.INSTALLED_APPS: try: - from djangocms_link.fields_select2 import Select2PageSearchField as PageSearchField + from djangocms_link.fields_select2 import Select2PageSearchField as PageSearchField # noqa except ImportError: - from djangocms_link.fields_select2_legacy import Select2LegacyPageSearchField as PageSearchField + from djangocms_link.fields_select2_legacy import Select2LegacyPageSearchField as PageSearchField # noqa else: - from cms.forms.fields import PageSelectFormField as PageSearchField + from cms.forms.fields import PageSelectFormField as PageSearchField # noqa diff --git a/djangocms_link/fields_select2.py b/djangocms_link/fields_select2.py index 3c5f1eba..db9b7ad4 100644 --- a/djangocms_link/fields_select2.py +++ b/djangocms_link/fields_select2.py @@ -1,6 +1,8 @@ -from cms.models import Page +# -*- coding: utf-8 -*- from django import forms +from cms.models import Page + from django_select2.forms import ModelSelect2Widget diff --git a/djangocms_link/fields_select2_legacy.py b/djangocms_link/fields_select2_legacy.py index 91313176..a2ecb624 100644 --- a/djangocms_link/fields_select2_legacy.py +++ b/djangocms_link/fields_select2_legacy.py @@ -1,4 +1,6 @@ +# -*- coding: utf-8 -*- from cms.models import Page + from django_select2.fields import AutoModelSelect2Field diff --git a/djangocms_link/forms.py b/djangocms_link/forms.py index 2b6b272c..dfbee21a 100644 --- a/djangocms_link/forms.py +++ b/djangocms_link/forms.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals + from django.forms.models import ModelForm from django.utils.translation import ugettext_lazy as _ diff --git a/djangocms_link/migrations/0001_initial.py b/djangocms_link/migrations/0001_initial.py index 58413abd..e7e2c280 100644 --- a/djangocms_link/migrations/0001_initial.py +++ b/djangocms_link/migrations/0001_initial.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/djangocms_link/migrations/0002_auto_20140929_1705.py b/djangocms_link/migrations/0002_auto_20140929_1705.py index 4ebd88df..ad4b7c75 100644 --- a/djangocms_link/migrations/0002_auto_20140929_1705.py +++ b/djangocms_link/migrations/0002_auto_20140929_1705.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/djangocms_link/migrations/0003_auto_20150212_1310.py b/djangocms_link/migrations/0003_auto_20150212_1310.py index 1c4e0c31..2e0033ef 100644 --- a/djangocms_link/migrations/0003_auto_20150212_1310.py +++ b/djangocms_link/migrations/0003_auto_20150212_1310.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/djangocms_link/migrations/0004_auto_20150708_1133.py b/djangocms_link/migrations/0004_auto_20150708_1133.py index 2700568e..7fb12633 100644 --- a/djangocms_link/migrations/0004_auto_20150708_1133.py +++ b/djangocms_link/migrations/0004_auto_20150708_1133.py @@ -1,7 +1,8 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models + import djangocms_link.validators from djangocms_link.models import HOSTNAME diff --git a/djangocms_link/migrations/0005_auto_20151003_1710.py b/djangocms_link/migrations/0005_auto_20151003_1710.py index d36ebd86..089ab39b 100644 --- a/djangocms_link/migrations/0005_auto_20151003_1710.py +++ b/djangocms_link/migrations/0005_auto_20151003_1710.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import models, migrations +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/djangocms_link/migrations/0006_remove_related_name_for_cmsplugin_ptr.py b/djangocms_link/migrations/0006_remove_related_name_for_cmsplugin_ptr.py index 10f0c0dc..c4e7f72c 100644 --- a/djangocms_link/migrations/0006_remove_related_name_for_cmsplugin_ptr.py +++ b/djangocms_link/migrations/0006_remove_related_name_for_cmsplugin_ptr.py @@ -2,8 +2,8 @@ # Generated by Django 1.9.2 on 2016-02-26 14:19 from __future__ import unicode_literals -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/djangocms_link/migrations/0007_set_related_name_for_cmsplugin_ptr.py b/djangocms_link/migrations/0007_set_related_name_for_cmsplugin_ptr.py index 1dcb58fc..3179ee8e 100644 --- a/djangocms_link/migrations/0007_set_related_name_for_cmsplugin_ptr.py +++ b/djangocms_link/migrations/0007_set_related_name_for_cmsplugin_ptr.py @@ -2,8 +2,8 @@ # Generated by Django 1.9.2 on 2016-03-04 04:44 from __future__ import unicode_literals -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models class Migration(migrations.Migration): diff --git a/djangocms_link/migrations/0008_link_attributes.py b/djangocms_link/migrations/0008_link_attributes.py index b0135e7c..0a5928af 100644 --- a/djangocms_link/migrations/0008_link_attributes.py +++ b/djangocms_link/migrations/0008_link_attributes.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals from django.db import migrations + import djangocms_attributes_field.fields diff --git a/djangocms_link/migrations/0009_auto_20160705_1344.py b/djangocms_link/migrations/0009_auto_20160705_1344.py index 08722b96..ce7605fa 100644 --- a/djangocms_link/migrations/0009_auto_20160705_1344.py +++ b/djangocms_link/migrations/0009_auto_20160705_1344.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals from django.db import migrations + import djangocms_attributes_field.fields diff --git a/djangocms_link/migrations/0010_adapted_fields.py b/djangocms_link/migrations/0010_adapted_fields.py index 888cf066..5d7a0b80 100644 --- a/djangocms_link/migrations/0010_adapted_fields.py +++ b/djangocms_link/migrations/0010_adapted_fields.py @@ -1,9 +1,11 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django.db import migrations, models import django.db.models.deletion +from django.db import migrations, models + import djangocms_attributes_field.fields + from djangocms_link.models import get_templates diff --git a/djangocms_link/migrations/0012_removed_null.py b/djangocms_link/migrations/0012_removed_null.py index 30deae01..dd4ef268 100644 --- a/djangocms_link/migrations/0012_removed_null.py +++ b/djangocms_link/migrations/0012_removed_null.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals from django.db import migrations, models + import djangocms_link.validators diff --git a/djangocms_link/migrations/0013_fix_hostname.py b/djangocms_link/migrations/0013_fix_hostname.py index 03e9af1a..555487af 100644 --- a/djangocms_link/migrations/0013_fix_hostname.py +++ b/djangocms_link/migrations/0013_fix_hostname.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals from django.db import migrations, models + import djangocms_link.validators from djangocms_link.models import HOSTNAME diff --git a/djangocms_link/models.py b/djangocms_link/models.py index b4c4f22a..cd0a0d87 100644 --- a/djangocms_link/models.py +++ b/djangocms_link/models.py @@ -5,12 +5,13 @@ """ from __future__ import unicode_literals -from django.contrib.sites.models import Site 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 python_2_unicode_compatible, force_text -from django.utils.translation import ugettext, ugettext_lazy as _ +from django.utils.encoding import force_text, python_2_unicode_compatible +from django.utils.translation import ugettext +from django.utils.translation import ugettext_lazy as _ from cms.models import CMSPlugin, Page @@ -51,7 +52,9 @@ class AbstractLink(CMSPlugin): # used by django CMS search search_fields = ('name', ) - url_validators = [IntranetURLValidator(intranet_host_re=HOSTNAME),] + url_validators = [ + IntranetURLValidator(intranet_host_re=HOSTNAME), + ] template = models.CharField( verbose_name=_('Template'), diff --git a/setup.py b/setup.py index 4e015253..f0a30221 100644 --- a/setup.py +++ b/setup.py @@ -14,31 +14,35 @@ CLASSIFIERS = [ 'Development Status :: 5 - Production/Stable', 'Environment :: Web Environment', - 'Framework :: Django', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', + 'Framework :: Django', + 'Framework :: Django :: 1.11', + 'Framework :: Django :: 2.0', + 'Framework :: Django :: 2.1', 'Programming Language :: Python', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', 'Topic :: Internet :: WWW/HTTP', 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', - 'Topic :: Software Development :: Libraries :: Application Frameworks', - 'Topic :: Software Development :: Libraries :: Python Modules', + 'Topic :: Software Development', + 'Topic :: Software Development :: Libraries', ] setup( name='djangocms-link', version=__version__, - description='Adds a link plugin to django CMS', author='Divio AG', author_email='info@divio.ch', url='https://github.com/divio/djangocms-link', license='BSD', + description='Adds a link plugin to django CMS', long_description=open('README.rst').read(), packages=find_packages(exclude=['tests']), include_package_data=True, diff --git a/tests/requirements.txt b/tests/requirements.txt index ae6f727a..ff8b4007 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -1,8 +1,8 @@ # requirements from setup.py django-select2>=5.11 -# other requirements djangocms-text-ckeditor html5lib<0.99999999 -djangocms-helper>=1.1.0,<1.2.0 +# other requirements +djangocms-helper tox coverage diff --git a/tests/settings.py b/tests/settings.py index 52533646..ab23981f 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- HELPER_SETTINGS = { 'INSTALLED_APPS': [ 'django_select2', diff --git a/tests/tests_field.py b/tests/test_field.py similarity index 92% rename from tests/tests_field.py rename to tests/test_field.py index 00e007aa..d30090cf 100644 --- a/tests/tests_field.py +++ b/tests/test_field.py @@ -1,4 +1,6 @@ +# -*- coding: utf-8 -*- from djangocms_helper.base_test import BaseTestCase + from djangocms_link.fields import PageSearchField from djangocms_link.fields_select2 import Select2PageSearchField diff --git a/tests/test_migrations.py b/tests/test_migrations.py new file mode 100644 index 00000000..8f52564f --- /dev/null +++ b/tests/test_migrations.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# original from +# http://tech.octopus.energy/news/2016/01/21/testing-for-missing-migrations-in-django.html +from django.core.management import call_command +from django.test import TestCase, override_settings +from django.utils.six import text_type +from django.utils.six.moves import StringIO + + +class MigrationTestCase(TestCase): + + @override_settings(MIGRATION_MODULES={}) + def test_for_missing_migrations(self): + output = StringIO() + options = { + 'interactive': False, + 'dry_run': True, + 'stdout': output, + 'check_changes': True, + } + + try: + call_command('makemigrations', **options) + except SystemExit as e: + status_code = text_type(e) + else: + # the "no changes" exit code is 0 + status_code = '0' + + if status_code == '1': + self.fail('There are missing migrations:\n {}'.format(output.getvalue())) diff --git a/tests/tests_model.py b/tests/test_model.py similarity index 86% rename from tests/tests_model.py rename to tests/test_model.py index ce3cb419..2fd4c70e 100644 --- a/tests/tests_model.py +++ b/tests/test_model.py @@ -1,16 +1,15 @@ # -*- coding: utf-8 -*- -from unittest import skipIf, skipUnless from distutils.version import LooseVersion +from unittest import skipIf, skipUnless -from django.core.management import call_command from django.utils.encoding import force_text -from django.utils.six import StringIO import cms from cms.api import add_plugin, create_page from djangocms_helper.base_test import BaseTestCase + CMS_35 = LooseVersion(cms.__version__) >= LooseVersion('3.5') @@ -110,16 +109,3 @@ def test_link_for_cms_34(self): anchor='some-h1', ) self.assertEqual(plugin.get_link(), '/en/#some-h1') - - def test_makemigrations(self): - """ - Fail if there are schema changes with no migrations. - """ - app_name = 'djangocms_link' - out = StringIO() - call_command('makemigrations', dry_run=True, no_input=True, stdout=out) - output = out.getvalue() - self.assertNotIn(app_name, output, ( - '`makemigrations` thinks there are schema changes without' - ' migrations.' - )) diff --git a/tox.ini b/tox.ini index 6cbef747..82468105 100644 --- a/tox.ini +++ b/tox.ini @@ -1,12 +1,42 @@ [tox] envlist = flake8 + isort py{27,34,35,36}-dj111-cms{34,35,36} py{34,35,36}-dj20-cms36 py{35,36}-dj21-cms36 skip_missing_interpreters=True +[flake8] +max-line-length = 119 +exclude = + *.egg-info, + .eggs, + .git, + .settings, + .tox, + build, + data, + dist, + docs, + *migrations*, + requirements, + tmp + +[isort] +line_length = 79 +skip = manage.py, *migrations*, .tox, .eggs, data +include_trailing_comma = true +multi_line_output = 5 +not_skip = __init__.py +lines_after_imports = 2 +default_section = THIRDPARTY +sections = FUTURE, STDLIB, DJANGO, CMS, THIRDPARTY, FIRSTPARTY, LIB, LOCALFOLDER +known_first_party = djangocms_link +known_cms = cms, menus +known_django = django + [testenv] deps = -r{toxinidir}/tests/requirements.txt @@ -22,6 +52,11 @@ commands = {env:COMMAND:coverage} run setup.py test {env:COMMAND:coverage} report -[flake8] -max-line-length = 120 -exclude = */docs/*,*/migrations/* +[testenv:flake8] +deps = flake8 +commands = flake8 + +[testenv:isort] +deps = isort +commands = isort -c -rc -df djangocms_link +skip_install = true