From 8e2cd531b8e77454adf86f20def330264564bed4 Mon Sep 17 00:00:00 2001 From: Angelo Dini Date: Fri, 9 Sep 2016 13:34:14 +0200 Subject: [PATCH] final cleanup --- README.rst | 77 ++++++------------- djangocms_link/cms_plugins.py | 2 - djangocms_link/fields.py | 9 ++- djangocms_link/forms.py | 15 +--- .../migrations/0010_adapted_fields.py | 10 --- djangocms_link/models.py | 26 ------- .../djangocms_link/default/link.html | 13 ++++ setup.py | 1 - 8 files changed, 46 insertions(+), 107 deletions(-) diff --git a/README.rst b/README.rst index 7d60eeb1..b0b62588 100644 --- a/README.rst +++ b/README.rst @@ -8,6 +8,9 @@ django CMS Link **django CMS Link** is a plugin for `django CMS `_ that allows you to add links on your site. +This plugin supports child plugins. If you add an other plugin as a +child it will take this content instead of the link name as the content of the link. + This addon is compatible with `Aldryn `_ and is also available on the `django CMS Marketplace `_ for easy installation. @@ -66,29 +69,36 @@ 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 support environments where non-standard URLs would otherwise work, this +project supports the defining of an additional RegEx pattern for validating the +host-portion of the URL. +For example: :: + # RFC1123 Pattern: + DJANGOCMS_LINK_INTRANET_HOSTNAME_PATTERN = r'[a-z,0-9,-]{1,15}' -To get ``django-select2`` support https://github.com/applegrew/django-select2#installation - - -If you want to enable the ajax loading: - -* In your projects :code:`virtualenv`, run :code:`pip install Django-Select2`. -* Add :code:`'django_select2'` to your :code:`INSTALLED_APPS` settings. -* Add :code:`url(r'^select2/', include('django_select2.urls')),` to your main ``urls.py``. - - - - - + # NetBios Pattern: + DJANGOCMS_LINK_INTRANET_HOSTNAME_PATTERN = r'[a-z,0-9,!@#$%^()\\-\'{}.~]{1,15}' +Either of these might accept a URL such as: :: + http://SEARCHHOST/?q=some+search+string +If left undefined, the normal Django URLValidator will be used. +Django Select2 +~~~~~~~~~~~~~~ +This plugin supports `django-select2 `_ +for simpler use of internal links. We **do not support 5.x**, this is why you +need to manually configure this feature: +* run ``pip install django-select2>=4.3,<5.0`` +* add ``django_select2`` to your ``INSTALLED_APPS`` +* add ``url(r'^select2/', include('django_select2.urls')),`` to your ``urls.py`` +* set ``DJANGOCMS_ENABLE_SELECT2 = True`` in your ``settings.py`` Running Tests @@ -108,44 +118,3 @@ 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 - - - - - - - -Settings -~~~~~~~~ - -To support environments where non-standard URLs would otherwise work, this -project supports the defining of an additional RegEx pattern for validating the -host-portion of the URL. - -For example: :: - - # RFC1123 Pattern: - DJANGOCMS_LINK_INTRANET_HOSTNAME_PATTERN = r'[a-z,0-9,-]{1,15}' - - # NetBios Pattern: - DJANGOCMS_LINK_INTRANET_HOSTNAME_PATTERN = r'[a-z,0-9,!@#$%^()\\-\'{}.~]{1,15}' - -Either of these might accept a URL such as: :: - - http://SEARCHHOST/?q=some+search+string - -If left undefined, the normal Django URLValidator will be used. - - -Children -~~~~~~~~ - -This plugin supports child plugins. If you add an other plugin as a child it will take this content -instead of the link name as the content of the link. - -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 9809fcc3..aa0bb90c 100644 --- a/djangocms_link/cms_plugins.py +++ b/djangocms_link/cms_plugins.py @@ -35,13 +35,11 @@ class LinkPlugin(CMSPluginBase): 'classes': ('collapse',), 'fields': ( 'template', - ('styles', 'link_type'), 'attributes', ) }), ] - def get_render_template(self, context, instance, placeholder): return 'djangocms_link/{}/link.html'.format(instance.template) diff --git a/djangocms_link/fields.py b/djangocms_link/fields.py index 9dc42a6a..8c468da1 100644 --- a/djangocms_link/fields.py +++ b/djangocms_link/fields.py @@ -2,7 +2,14 @@ from django.conf import settings -if 'django_select2' in settings.INSTALLED_APPS: +ENABLE_SELECT2 = getattr( + settings, + 'DJANGOCMS_ENABLE_SELECT2', + True +) + + +if 'django_select2' in settings.INSTALLED_APPS and ENABLE_SELECT2: from django_select2.fields import AutoModelSelect2Field class PageSearchField(AutoModelSelect2Field): diff --git a/djangocms_link/forms.py b/djangocms_link/forms.py index 8ed120b6..11131720 100644 --- a/djangocms_link/forms.py +++ b/djangocms_link/forms.py @@ -13,13 +13,13 @@ class LinkForm(ModelForm): try: from djangocms_link.fields import PageSearchField internal_link = PageSearchField( - label=_('Page'), + label=_('Internal link'), required=False, ) except ImportError: from cms.forms.fields import PageSelectFormField internal_link = PageSelectFormField( - label=_('Page'), + label=_('Internal link'), required=False, ) @@ -52,14 +52,3 @@ def clean(self): if not any([external_link, internal_link, mailto, phone, anchor]): raise ValidationError(_('At least one link is required.')) return cleaned_data - - # def _get_media(self): - # """ - # Provide a description of all media required to render the widgets on this form - # """ - # media = Media() - # for field in self.fields.values(): - # media = media + field.widget.media - # media._js = ['cms/js/libs/jquery.min.js'] + media._js - # return media - # media = property(_get_media) diff --git a/djangocms_link/migrations/0010_adapted_fields.py b/djangocms_link/migrations/0010_adapted_fields.py index 218591f2..502707d4 100644 --- a/djangocms_link/migrations/0010_adapted_fields.py +++ b/djangocms_link/migrations/0010_adapted_fields.py @@ -14,21 +14,11 @@ class Migration(migrations.Migration): ] operations = [ - migrations.AddField( - model_name='link', - name='link_type', - field=models.CharField(blank=True, max_length=255, verbose_name='Link type', choices=[('anchor', ''), ('button', '