From 432e4301e1642de84e7c22e442a33dab45222056 Mon Sep 17 00:00:00 2001 From: Angelo Dini Date: Mon, 17 Dec 2018 10:56:07 +0100 Subject: [PATCH] Make djangocms-transfer publicly available (#4) * added tests, readme and some updates * fix django.core.urlresolvers * fix django CMS 3.6 compatibility --- .coveragerc | 18 +++++++++++ .gitignore | 1 + .travis.yml | 33 +++++++++++++++++++ CHANGELOG.rst | 8 +++++ README.rst | 42 ++++++++++++++++++++++++ djangocms_transfer/cms_plugins.py | 4 +-- djangocms_transfer/cms_toolbars.py | 9 +++++- djangocms_transfer/compat.py | 1 + setup.py | 52 ++++++++++++++++++++---------- tests/__init__.py | 1 + tests/requirements.txt | 4 +++ tests/settings.py | 23 +++++++++++++ tests/test_migrations.py | 31 ++++++++++++++++++ tox.ini | 27 ++++++++++++++++ 14 files changed, 234 insertions(+), 20 deletions(-) create mode 100644 .coveragerc create mode 100644 .travis.yml create mode 100644 CHANGELOG.rst create mode 100644 tests/__init__.py create mode 100644 tests/requirements.txt create mode 100644 tests/settings.py create mode 100644 tests/test_migrations.py create mode 100644 tox.ini diff --git a/.coveragerc b/.coveragerc new file mode 100644 index 0000000..93764d2 --- /dev/null +++ b/.coveragerc @@ -0,0 +1,18 @@ +[run] +branch = True +source = djangocms_transfer +omit = + migrations/* + tests/* + +[report] +exclude_lines = + pragma: no cover + def __repr__ + if self.debug: + if settings.DEBUG + raise AssertionError + raise NotImplementedError + if 0: + if __name__ == .__main__.: +ignore_errors = True diff --git a/.gitignore b/.gitignore index 5dbb8d2..a80e424 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,5 @@ .idea/ .tox/ .eggs/ +dist/ build/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..787070f --- /dev/null +++ b/.travis.yml @@ -0,0 +1,33 @@ +language: python + +sudo: false + +matrix: + include: + - python: 3.5 + env: TOX_ENV='flake8' + # Django 1.11 + - python: 2.7 + env: DJANGO='dj111' CMS='cms34' + - python: 3.5 + env: DJANGO='dj111' CMS='cms35' + - python: 3.5 + env: DJANGO='dj111' CMS='cms36' + # Django 2.0 + - python: 3.5 + env: DJANGO='dj20' CMS='cms36' + # Django 2.1 + - python: 3.5 + env: DJANGO='dj21' CMS='cms36' + +install: + - pip install tox coverage + - "if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then export PY_VER=py27; fi" + - "if [[ $TRAVIS_PYTHON_VERSION == '3.5' ]]; then export PY_VER=py35; fi" + - "if [[ ${DJANGO}z != 'z' ]]; then export TOX_ENV=$PY_VER-$DJANGO-$CMS; fi" + +script: + - tox -e $TOX_ENV + +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/CHANGELOG.rst b/CHANGELOG.rst new file mode 100644 index 0000000..a5e65a7 --- /dev/null +++ b/CHANGELOG.rst @@ -0,0 +1,8 @@ +========= +Changelog +========= + +1.0.0 (unreleased) +================== + +* Public release diff --git a/README.rst b/README.rst index e69de29..9527a45 100644 --- a/README.rst +++ b/README.rst @@ -0,0 +1,42 @@ +=================== +django CMS Transfer +=================== + + +|pypi| |build| |coverage| + +**django CMS Transfer** is an **experimental** package that allows you to export +and import plugin data from a page or a placeholder. It does not support foreign +key relations and won't import/export related data. + +This addon is compatible with `Divio Cloud `_ and is also available on the +`django CMS Marketplace `_ +for easy installation. + + +Contributing +============ + +This is a an open-source project. We'll be delighted to receive your +feedback in the form of issues and pull requests. Before submitting your +pull request, please review our `contribution guidelines +`_. + + +Running Tests +------------- + +You can run tests by executing:: + + virtualenv env + source env/bin/activate + pip install -r tests/requirements.txt + python setup.py test + + +.. |pypi| image:: https://badge.fury.io/py/djangocms-transfer.svg + :target: http://badge.fury.io/py/djangocms-transfer +.. |build| image:: https://travis-ci.org/divio/djangocms-transfer.svg?branch=master + :target: https://travis-ci.org/divio/djangocms-transfer +.. |coverage| image:: https://codecov.io/gh/divio/djangocms-transfer/branch/master/graph/badge.svg + :target: https://codecov.io/gh/divio/djangocms-transfer diff --git a/djangocms_transfer/cms_plugins.py b/djangocms_transfer/cms_plugins.py index 5ef47ec..acc0e46 100644 --- a/djangocms_transfer/cms_plugins.py +++ b/djangocms_transfer/cms_plugins.py @@ -3,7 +3,7 @@ from django.conf.urls import url from django.core.exceptions import PermissionDenied -from django.core.urlresolvers import reverse +from django.urls import reverse from django.http import JsonResponse, HttpResponse, HttpResponseBadRequest from django.shortcuts import render from django.utils.http import urlencode @@ -151,7 +151,7 @@ def import_plugins_view(cls, request): if LTE_CMS_3_4: return HttpResponse('
') - + if plugin: new_plugins = plugin.reload().get_descendants().exclude(pk__in=tree_order) return plugin.get_plugin_class_instance().render_close_frame(request, obj=new_plugins[0]) diff --git a/djangocms_transfer/cms_toolbars.py b/djangocms_transfer/cms_toolbars.py index cccb96b..69b5d21 100644 --- a/djangocms_transfer/cms_toolbars.py +++ b/djangocms_transfer/cms_toolbars.py @@ -10,6 +10,8 @@ from cms.toolbar_pool import toolbar_pool from cms.utils.urlutils import admin_reverse +from .compat import GTE_CMS_3_6 + @toolbar_pool.register class PluginImporter(CMSToolbar): @@ -37,7 +39,12 @@ def populate(self): 'language': self.current_lang, 'cms_page': page.pk, }) - not_edit_mode = not self.toolbar.edit_mode + + if GTE_CMS_3_6: + not_edit_mode = not self.toolbar.toolbar_language + else: + not_edit_mode = not self.toolbar.language + page_menu.add_break('Page menu importer break') page_menu.add_link_item( ugettext('Export'), diff --git a/djangocms_transfer/compat.py b/djangocms_transfer/compat.py index 5e42760..6681de0 100644 --- a/djangocms_transfer/compat.py +++ b/djangocms_transfer/compat.py @@ -6,3 +6,4 @@ LTE_CMS_3_4 = cms_version < LooseVersion('3.5') LTE_CMS_3_5 = cms_version < LooseVersion('3.6') +GTE_CMS_3_6 = cms_version >= LooseVersion('3.6') diff --git a/setup.py b/setup.py index 9d02b57..289fe83 100644 --- a/setup.py +++ b/setup.py @@ -1,31 +1,49 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- from setuptools import find_packages, setup -import djangocms_transfer +from djangocms_transfer import __version__ -INSTALL_REQUIREMENTS = [ - 'Django>=1.8,<2', - 'django-cms>=3.4.2', +REQUIREMENTS = [ + 'django-cms>=3.4.5', +] + + +CLASSIFIERS = [ + 'Development Status :: 5 - Production/Stable', + 'Environment :: Web Environment', + 'Framework :: Django', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: BSD License', + 'Operating System :: OS Independent', + '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', ] setup( name='djangocms-transfer', - packages=find_packages(), - include_package_data=True, - version=djangocms_transfer.__version__, - description=djangocms_transfer.__doc__, - long_description=open('README.rst').read(), - classifiers=[ - 'Framework :: Django', - 'Intended Audience :: Developers', - 'License :: OSI Approved :: BSD License', - 'Operating System :: OS Independent', - 'Topic :: Software Development' - ], - install_requires=INSTALL_REQUIREMENTS, + version=__version__, author='Divio AG', author_email='info@divio.ch', url='http://github.com/divio/djangocms-transfer', license='BSD', + description='Adds import and export of plugin data.', + packages=find_packages(exclude=['tests']), + long_description=open('README.rst').read(), + include_package_data=True, + zip_safe=False, + install_requires=REQUIREMENTS, + classifiers=CLASSIFIERS, + test_suite='tests.settings.run', ) diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..40a96af --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- diff --git a/tests/requirements.txt b/tests/requirements.txt new file mode 100644 index 0000000..4ba6e07 --- /dev/null +++ b/tests/requirements.txt @@ -0,0 +1,4 @@ +# other requirements +djangocms-helper +tox +coverage diff --git a/tests/settings.py b/tests/settings.py new file mode 100644 index 0000000..34fd10e --- /dev/null +++ b/tests/settings.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +HELPER_SETTINGS = { + 'INSTALLED_APPS': [], + 'LANGUAGE_CODE': 'en', + 'CMS_LANGUAGES': { + 1: [{ + 'code': 'en', + 'name': 'English', + }] + }, + 'ALLOWED_HOSTS': ['localhost'], +} + + +def run(): + from djangocms_helper import runner + runner.cms('djangocms_transfer') + + +if __name__ == '__main__': + run() diff --git a/tests/test_migrations.py b/tests/test_migrations.py new file mode 100644 index 0000000..8f52564 --- /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/tox.ini b/tox.ini new file mode 100644 index 0000000..6cbef74 --- /dev/null +++ b/tox.ini @@ -0,0 +1,27 @@ +[tox] +envlist = + flake8 + 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 + +[testenv] +deps = + -r{toxinidir}/tests/requirements.txt + dj111: Django>=1.11,<2.0 + dj20: Django>=2.0,<2.1 + dj21: Django>=2.1,<2.2 + cms34: django-cms>=3.4,<3.5 + 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 + {env:COMMAND:coverage} run setup.py test + {env:COMMAND:coverage} report + +[flake8] +max-line-length = 120 +exclude = */docs/*,*/migrations/*