diff --git a/README.rst b/README.rst index 969da005..f0c7ac90 100644 --- a/README.rst +++ b/README.rst @@ -98,7 +98,7 @@ 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_LINK_SELECT2 = True`` in your ``settings.py`` +* set ``DJANGOCMS_LINK_USE_SELECT2 = True`` in your ``settings.py`` Running Tests diff --git a/aldryn_config.py b/aldryn_config.py index 03c18fbe..25d06939 100644 --- a/aldryn_config.py +++ b/aldryn_config.py @@ -15,7 +15,7 @@ class Form(forms.BaseForm): The following settings need to be configured on your project separately as we don't want to expose them as aldryn configurations yet: DJANGOCMS_LINK_INTRANET_HOSTNAME_PATTERN - DJANGOCMS_LINK_SELECT2 + DJANGOCMS_LINK_USE_SELECT2 """ def clean(self): diff --git a/djangocms_link/cms_plugins.py b/djangocms_link/cms_plugins.py index aa0bb90c..8761a381 100644 --- a/djangocms_link/cms_plugins.py +++ b/djangocms_link/cms_plugins.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import unicode_literals + from django.conf import settings from django.utils.translation import ugettext_lazy as _ from django.contrib.sites.models import Site diff --git a/djangocms_link/fields.py b/djangocms_link/fields.py index 8cdb4d52..d8911be9 100644 --- a/djangocms_link/fields.py +++ b/djangocms_link/fields.py @@ -4,12 +4,12 @@ ENABLE_SELECT2 = getattr( settings, - 'DJANGOCMS_LINK_SELECT2', + 'DJANGOCMS_LINK_USE_SELECT2', False ) -if 'django_select2' in settings.INSTALLED_APPS and ENABLE_SELECT2: +if ENABLE_SELECT2 and 'django_select2' in settings.INSTALLED_APPS: from django_select2.fields import AutoModelSelect2Field class PageSearchField(AutoModelSelect2Field): @@ -50,3 +50,7 @@ def prepare_value(self, value): if not value: return None return super(UserSearchField, self).prepare_value(value) +else: + from cms.forms.fields import PageSelectFormField + + PageSearchField = PageSelectFormField diff --git a/djangocms_link/forms.py b/djangocms_link/forms.py index 11131720..44bdb6ae 100644 --- a/djangocms_link/forms.py +++ b/djangocms_link/forms.py @@ -6,22 +6,15 @@ from djangocms_attributes_field.widgets import AttributesWidget +from .fields import PageSearchField from .models import Link class LinkForm(ModelForm): - try: - from djangocms_link.fields import PageSearchField - internal_link = PageSearchField( - label=_('Internal link'), - required=False, - ) - except ImportError: - from cms.forms.fields import PageSelectFormField - internal_link = PageSelectFormField( - label=_('Internal link'), - required=False, - ) + internal_link = PageSearchField( + label=_('Internal link'), + required=False, + ) def for_site(self, site): # override the internal_link fields queryset to contains just pages for diff --git a/djangocms_link/models.py b/djangocms_link/models.py index e891b967..00813017 100644 --- a/djangocms_link/models.py +++ b/djangocms_link/models.py @@ -3,6 +3,8 @@ Enables the user to add a "Link" plugin that displays a link using the HTML tag. """ +from __future__ import unicode_literals + from django.db import models from django.conf import settings from django.core.exceptions import ValidationError @@ -63,7 +65,6 @@ class AbstractLink(CMSPlugin): external_link = models.URLField( verbose_name=_('External link'), blank=True, - null=True, max_length=2040, validators=url_validators, help_text=_('Provide a valid url to an external website.'), @@ -88,13 +89,11 @@ class AbstractLink(CMSPlugin): mailto = models.EmailField( verbose_name=_('Email address'), blank=True, - null=True, max_length=255, ) phone = models.CharField( verbose_name=_('Phone'), blank=True, - null=True, max_length=255, ) # advanced options @@ -129,7 +128,7 @@ def __str__(self): def get_short_description(self): if self.name: return '{} ({})'.format(self.name, self.get_link()) - return self.get_link() + return self.get_link() or ugettext('') def get_link(self): if self.phone: @@ -142,11 +141,8 @@ def get_link(self): link = self.internal_link.get_absolute_url() else: link = '' - if (self.external_link or self.internal_link_id or not link) and self.anchor: + if (not self.phone and not self.mailto) and self.anchor: link += '#{}'.format(self.anchor) - # link can be empty if a page attached to it has been removed - if link == '': - link = '' return link