From d333a7a145f99c00cff539706a0be5273c2fbdad Mon Sep 17 00:00:00 2001 From: Angelo Dini Date: Thu, 8 Sep 2016 17:45:59 +0200 Subject: [PATCH] first cleanup --- .coveragerc | 21 +- .editorconfig | 11 ++ .gitignore | 20 +- .travis.yml | 48 ++--- CHANGELOG.rst | 64 +++---- LICENSE.txt | 6 +- MANIFEST.in | 2 +- README.rst | 123 +++++++++--- djangocms_link/cms_plugins.py | 44 +++-- djangocms_link/fields.py | 6 +- djangocms_link/forms.py | 25 +-- .../migrations/0010_adapted_fields.py | 82 ++++++++ djangocms_link/models.py | 181 +++++++++++++----- .../south_migrations/0001_initial.py | 104 ---------- .../0002_auto__add_field_link_phone.py | 94 --------- ...d_link_anchor__chg_field_link_page_link.py | 101 ---------- .../0004_auto__chg_field_link_url.py | 91 --------- .../0005_auto__chg_field_link_mailto.py | 93 --------- djangocms_link/south_migrations/__init__.py | 0 .../templates/cms/plugins/link.html | 1 - .../djangocms_link/default/link.html | 13 ++ setup.cfg | 20 -- setup.py | 41 ++-- {djangocms_link/tests => tests}/__init__.py | 0 .../requirements-tests.txt | 0 requirements.txt => tests/requirements.txt | 0 test_settings.py => tests/test_settings.py | 0 .../tests => tests}/tests_model.py | 6 +- tox.ini | 49 ++--- updatetranslations.sh | 6 - 30 files changed, 475 insertions(+), 777 deletions(-) create mode 100644 djangocms_link/migrations/0010_adapted_fields.py delete mode 100644 djangocms_link/south_migrations/0001_initial.py delete mode 100644 djangocms_link/south_migrations/0002_auto__add_field_link_phone.py delete mode 100644 djangocms_link/south_migrations/0003_auto__add_field_link_anchor__chg_field_link_page_link.py delete mode 100644 djangocms_link/south_migrations/0004_auto__chg_field_link_url.py delete mode 100644 djangocms_link/south_migrations/0005_auto__chg_field_link_mailto.py delete mode 100644 djangocms_link/south_migrations/__init__.py delete mode 100644 djangocms_link/templates/cms/plugins/link.html create mode 100644 djangocms_link/templates/djangocms_link/default/link.html delete mode 100644 setup.cfg rename {djangocms_link/tests => tests}/__init__.py (100%) rename requirements-tests.txt => tests/requirements-tests.txt (100%) rename requirements.txt => tests/requirements.txt (100%) rename test_settings.py => tests/test_settings.py (100%) rename {djangocms_link/tests => tests}/tests_model.py (95%) delete mode 100755 updatetranslations.sh diff --git a/.coveragerc b/.coveragerc index cb1f059e..76332969 100644 --- a/.coveragerc +++ b/.coveragerc @@ -1,27 +1,18 @@ [run] branch = True -source = djangocms_link +source = djangocms_picture +omit = + migrations/* + tests/* [report] -omit = ../*migrations*,../*tests*,../*south_migrations* -# Regexes for lines to exclude from consideration exclude_lines = - # Have to re-enable the standard pragma pragma: no cover - - # Don't complain about missing debug-only code: def __repr__ - if self\.debug - - # Don't complain if tests don't hit defensive assertion code: + if self.debug: + if settings.DEBUG raise AssertionError raise NotImplementedError - - # Don't complain if non-runnable code isn't run: if 0: if __name__ == .__main__.: - ignore_errors = True - -[html] -directory = coverage_html diff --git a/.editorconfig b/.editorconfig index c221e013..adafbd5e 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,12 +9,23 @@ end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true +max_line_length = 80 + +[*.py] +max_line_length = 120 +quote_type = single [*.{scss,js,html}] +max_line_length = 120 indent_style = space +quote_type = double [*.js] max_line_length = 120 +quote_type = single [*.rst] max_line_length = 80 + +[*.yml] +indent_size = 2 diff --git a/.gitignore b/.gitignore index fe88b0a0..a80e4246 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,8 @@ -*.log -*.pot *.pyc -.project -.pydevproject -.settings -djangocms_link.egg-info -dist -build -env* -.tox -.coverage -.eggs -.idea +*.egg-info +.DS_Store +.idea/ +.tox/ +.eggs/ +dist/ +build/ diff --git a/.travis.yml b/.travis.yml index ce22c3d8..4ca66529 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,39 +1,27 @@ -# Config file for automatic testing at travis-ci.org - language: python -python: 3.5 - sudo: false env: - matrix: - - TOXENV=flake8 - - TOXENV=isort - - TOXENV=py35-dj19-cms33 - - TOXENV=py35-dj19-cms32 - - TOXENV=py34-dj19-cms33 - - TOXENV=py34-dj19-cms32 - - TOXENV=py27-dj19-cms33 - - TOXENV=py27-dj19-cms32 - - TOXENV=py35-dj18-cms33 - - TOXENV=py35-dj18-cms32 - - TOXENV=py35-dj18-cms31 - - TOXENV=py34-dj18-cms33 - - TOXENV=py34-dj18-cms32 - - TOXENV=py34-dj18-cms31 - - TOXENV=py33-dj18-cms33 - - TOXENV=py33-dj18-cms32 - - TOXENV=py33-dj18-cms31 - - TOXENV=py27-dj18-cms33 - - TOXENV=py27-dj18-cms32 - - TOXENV=py27-dj18-cms31 + - TOX_ENV=flake8 + - TOX_ENV=py27-latest + - TOX_ENV=py34-latest + # Django 1.8 + - TOX_ENV=py34-dj18-cms33 + - TOX_ENV=py34-dj18-cms32 + - TOX_ENV=py27-dj18-cms33 + - TOX_ENV=py27-dj18-cms32 + # Django 1.9 + - TOX_ENV=py34-dj19-cms33 + - TOX_ENV=py34-dj19-cms32 + - TOX_ENV=py27-dj19-cms33 + - TOX_ENV=py27-dj19-cms32 -# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors install: - - pip install -U tox>=1.8 coveralls + - pip install tox coverage -# command to run tests, e.g. python setup.py test -script: COMMAND='coverage run' tox -e$TOXENV +script: + - tox -e $TOX_ENV -after_success: coveralls +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 8bc19ccb..a18e6c4a 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -1,64 +1,49 @@ ----------- -unreleased ----------- +========= +Changelog +========= -Version 1.8.3 -* Added native Aldryn support +1.8.3 (unreleased) +================== +* Added native Aldryn support ----------- -2016-07-18 ----------- -Version 1.8.2 +1.8.2 (2016-07-18) +================== * Fixed styling issues with attributes field * Pinned djangocms_attributes_field to v0.1.1+ * Fixed a regression where unnecessary whitespace was added to rendered html ----------- -2016-07-05 ----------- - -Version 1.8.1 +1.8.1 (2016-07-05) +================== * Pinned to djangocms-attributes-field v0.1.0 * Let attributes field be optional ----------- -2016-06-20 ----------- - -Version 1.8.0 +1.8.0 (2016-06-20) +================== * Adds support for arbitrary HTML attributes on link tag ----------- -2015-03-04 ----------- - -Version 1.7.2 +1.7.2 (2015-03-04) +================== * fix field name clashes with in Django 1.9 ----------- -2015-10-14 ----------- - -Version 1.7.1 +1.7.1 (2015-10-14) +================== * Pin Django Select2 to >=4.3,<5.0 to preserve Django 1.6 compatibility ----------- -2015-10-12 ----------- -Version 1.7 +1.7.0 (2015-10-12) +================== * Move migrations to standard location * Move to djangocms-helper for tests @@ -66,12 +51,9 @@ Version 1.7 * Fix tel field * Change mailto field length ----------- -2015-06-09 ----------- -Version 1.6.2 -Changes since 1.6.1 +1.6.2 (2015-06-09) +================== * Use RST for Readme * Add repo badges for Travis, PyPI, etc. @@ -79,8 +61,8 @@ Changes since 1.6.1 * Allow anchor-only links * Added clarity to the helptext for the anchor field ----------- -2014-05-07 ----------- + +1.6.1 (2014-05-07) +================== * Fix a bug in forms Fix a we refer field.widget.queryset instead field.queryset. diff --git a/LICENSE.txt b/LICENSE.txt index 1d72bfb2..29267a58 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -8,17 +8,17 @@ modification, are permitted provided that the following conditions are met: * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - * Neither the name of Djeese Factory GmbH nor the + * Neither the name of Divio AG nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL DJEESE FACTORY GMBH BE LIABLE FOR ANY +DISCLAIMED. IN NO EVENT SHALL DIVIO AG BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/MANIFEST.in b/MANIFEST.in index 3544ea3d..9dc46ee4 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,5 +1,5 @@ include LICENSE.txt -include README.md +include README.rst recursive-include djangocms_link/locale * recursive-include djangocms_link/templates * recursive-exclude * *.py[co] diff --git a/README.rst b/README.rst index 871b942b..7d60eeb1 100644 --- a/README.rst +++ b/README.rst @@ -1,38 +1,76 @@ -############## -djangocms-link -############## +=============== +django CMS Link +=============== -.. image:: https://img.shields.io/pypi/v/djangocms-link.svg - :target: https://pypi.python.org/pypi/djangocms-link/ -.. image:: https://img.shields.io/pypi/dm/djangocms-link.svg - :target: https://pypi.python.org/pypi/djangocms-link/ -.. image:: https://img.shields.io/badge/wheel-yes-green.svg - :target: https://pypi.python.org/pypi/djangocms-link/ -.. image:: https://img.shields.io/pypi/l/djangocms-link.svg - :target: https://pypi.python.org/pypi/djangocms-link/ +|pypi| |build| |coverage| -A Link plugin for django CMS. +**django CMS Link** is a plugin for `django CMS `_ that +allows you to add links on your site. + +This addon is compatible with `Aldryn `_ and is also available on the +`django CMS Marketplace `_ +for easy installation. + +.. image:: preview.gif + + +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 +`_. + +One of the easiest contributions you can make is helping to translate this addon on +`Transifex `_. + + +Documentation +============= + +See ``REQUIREMENTS`` in the `setup.py `_ +file for additional dependencies: + +* Python 2.7, 3.3 or higher +* Django 1.8 or higher Installation -~~~~~~~~~~~~ +------------ +For a manual install: -This plugin requires :code:`django CMS` 3.0 or higher to be properly installed and -configured. If you have many pages it supports ajax loading for selecting a page. -To enable this install Django-Select2 3.4 or above. +* run ``pip install djangocms-link`` +* add ``djangocms_link`` to your ``INSTALLED_APPS`` +* run ``python manage.py migrate djangocms_link`` -* In your projects :code:`virtualenv`, run :code:`pip install djangocms-link`. -* Add :code:`'djangocms_link'` to your :code:`INSTALLED_APPS` setting. -* Run ``manage.py migrate djangocms_link``. -.. warning:: If upgrading for versions prior to 1.7, remove `djangocms_link` from - ``MIGRATION_MODULES`` setting. +Configuration +------------- + +Note that the provided templates are very minimal by design. You are encouraged +to adapt and override them to your project's requirements. + +This addon provides a ``default`` template for all instances. You can provide +additional template choices by adding a ``DJANGOCMS_LINK_TEMPLATES`` +setting:: + + DJANGOCMS_LINK_TEMPLATES = [ + ('feature', _('Featured Version')), + ] + +You'll need to create the `feature` folder inside ``templates/djangocms_link/`` +otherwise you will get a *template does not exist* error. You can do this by +copying the ``default`` folder inside that directory and renaming it to +``feature``. + + + + +To get ``django-select2`` support https://github.com/applegrew/django-select2#installation -.. warning:: If using Django 1.6, you may need to eventually add - :code:`'djangocms_link': 'djangocms_link.south_migrations',` to - :code:`SOUTH_MIGRATION_MODULES` If you want to enable the ajax loading: @@ -41,6 +79,42 @@ If you want to enable the ajax loading: * Add :code:`url(r'^select2/', include('django_select2.urls')),` to your main ``urls.py``. + + + + + + + + + + + + +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-link.svg + :target: http://badge.fury.io/py/djangocms-link +.. |build| image:: https://travis-ci.org/divio/djangocms-link.svg?branch=master + :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 + + + + + + + Settings ~~~~~~~~ @@ -75,4 +149,3 @@ Translations If you want to help translate the plugin please do it on transifex: https://www.transifex.com/projects/p/djangocms-link/resource/djangocms-link/ - diff --git a/djangocms_link/cms_plugins.py b/djangocms_link/cms_plugins.py index d642a8e5..7b93305b 100644 --- a/djangocms_link/cms_plugins.py +++ b/djangocms_link/cms_plugins.py @@ -7,40 +7,44 @@ from django.contrib.sites.models import Site from django.utils.translation import ugettext_lazy as _ -from djangocms_link.forms import LinkForm -from djangocms_link.models import Link +from .forms import LinkForm +from .models import Link class LinkPlugin(CMSPluginBase): - model = Link form = LinkForm name = _('Link') render_template = 'cms/plugins/link.html' text_enabled = True allow_children = True - fieldsets = ( + + fieldsets = [ (None, { 'fields': ( - 'name', 'url', 'page_link', 'anchor', 'mailto', 'phone', 'target', - ), + 'name', + ('external_link', 'internal_link'), + ) }), - ('Advanced', { - 'classes': ('collapse', ), - 'fields': ('attributes', ), + (_('Advanced settings'), { + 'classes': ('collapse',), + 'fields': ( + 'template', + ('target', 'link_type'), + ('anchor', 'styles'), + ('mailto', 'phone'), + 'attributes', + ) }), - ) + ] + + + def get_render_template(self, context, instance, placeholder): + return 'djangocms_link/{}/link.html'.format(instance.template) def render(self, context, instance, placeholder): - link = instance.link() - context.update({ - 'name': instance.name, - 'link': link, - 'target': instance.target, - 'placeholder': placeholder, - 'object': instance - }) - return context + context['link'] = instance.link() + return super(LinkPlugin, self).render(context, instance, placeholder) def get_form(self, request, obj=None, **kwargs): form_class = super(LinkPlugin, self).get_form(request, obj, **kwargs) @@ -60,7 +64,5 @@ def __init__(self, *args, **kwargs): return Form - def icon_src(self, instance): - return '{0}cms/img/icons/plugins/link.png'.format(settings.STATIC_URL) plugin_pool.register_plugin(LinkPlugin) diff --git a/djangocms_link/fields.py b/djangocms_link/fields.py index 18405c16..0bad4802 100644 --- a/djangocms_link/fields.py +++ b/djangocms_link/fields.py @@ -28,7 +28,11 @@ def security_check(self, request, *args, **kwargs): return False class UserSearchField(AutoModelSelect2Field): - search_fields = ['username__icontains', 'firstname__icontains', 'lastname__icontains'] + search_fields = [ + 'username__icontains', + 'firstname__icontains', + 'lastname__icontains' + ] def security_check(self, request, *args, **kwargs): user = request.user diff --git a/djangocms_link/forms.py b/djangocms_link/forms.py index e7b84dad..8e9644cc 100644 --- a/djangocms_link/forms.py +++ b/djangocms_link/forms.py @@ -8,27 +8,27 @@ from djangocms_attributes_field.widgets import AttributesWidget -from djangocms_link.models import Link +from .models import Link class LinkForm(ModelForm): try: from djangocms_link.fields import PageSearchField - page_link = PageSearchField(label=_('Page'), required=False) + internal_link = PageSearchField(label=_('Page'), required=False) except ImportError: from cms.forms.fields import PageSelectFormField - page_link = PageSelectFormField(label=_('Page'), required=False) + internal_link = PageSelectFormField(label=_('Page'), required=False) def for_site(self, site): - # override the page_link fields queryset to contains just pages for + # override the internal_link fields queryset to contains just pages for # current site # this will work for PageSelectFormField from cms.models import Page - self.fields['page_link'].queryset = Page.objects.drafts().on_site(site) - # set the current site as a page_link field instance attribute + self.fields['internal_link'].queryset = Page.objects.drafts().on_site(site) + # set the current site as a internal_link field instance attribute # this will be used by the field later to properly set up the queryset # this will work for PageSearchField - self.fields['page_link'].site = site + self.fields['internal_link'].site = site class Meta: model = Link @@ -48,14 +48,3 @@ def _get_media(self): media._js = ['cms/js/libs/jquery.min.js'] + media._js return media media = property(_get_media) - - def clean(self): - cleaned_data = super(LinkForm, self).clean() - url = cleaned_data.get('url') - page_link = cleaned_data.get('page_link') - mailto = cleaned_data.get('mailto') - phone = cleaned_data.get('phone') - anchor = cleaned_data.get('anchor') - if not any([url, page_link, mailto, phone, anchor]): - raise ValidationError(_('At least one link is required.')) - return cleaned_data diff --git a/djangocms_link/migrations/0010_adapted_fields.py b/djangocms_link/migrations/0010_adapted_fields.py new file mode 100644 index 00000000..218591f2 --- /dev/null +++ b/djangocms_link/migrations/0010_adapted_fields.py @@ -0,0 +1,82 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion +import djangocms_attributes_field.fields +import djangocms_link.validators + + +class Migration(migrations.Migration): + + dependencies = [ + ('djangocms_link', '0009_auto_20160705_1344'), + ] + + operations = [ + migrations.AddField( + model_name='link', + name='link_type', + field=models.CharField(blank=True, max_length=255, verbose_name='Link type', choices=[('anchor', ''), ('button', '