Skip to content

Commit

Permalink
final cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
FinalAngel committed Sep 9, 2016
1 parent 3bed5e0 commit 8e2cd53
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 107 deletions.
77 changes: 23 additions & 54 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ django CMS Link
**django CMS Link** is a plugin for `django CMS <http://django-cms.org>`_ 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 <http://aldryn.com>`_ and is also available on the
`django CMS Marketplace <https://marketplace.django-cms.org/en/addons/browse/djangocms-link/>`_
for easy installation.
Expand Down Expand Up @@ -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 <https://github.com/applegrew/django-select2#installation>`_
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
Expand All @@ -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/
2 changes: 0 additions & 2 deletions djangocms_link/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
9 changes: 8 additions & 1 deletion djangocms_link/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
15 changes: 2 additions & 13 deletions djangocms_link/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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)
10 changes: 0 additions & 10 deletions djangocms_link/migrations/0010_adapted_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', '<a>'), ('button', '<button>')]),
),
migrations.AddField(
model_name='link',
name='template',
field=models.CharField(default='default', max_length=255, verbose_name='Template', choices=[('default', 'Default')]),
),
migrations.AddField(
model_name='link',
name='styles',
field=models.CharField(max_length=255, verbose_name='Styles', blank=True),
),
migrations.RenameField(
model_name='link',
old_name='url',
Expand Down
26 changes: 0 additions & 26 deletions djangocms_link/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,6 @@ def get_templates():
)
return choices

TYPE_CHOICES = getattr(
settings,
'DJANGOCMS_LINK_TYPES',
(('', '---------'),)
)

STYLE_CHOICES = getattr(
settings,
'DJANGOCMS_LINK_STYLES',
(('', '---------'),)
)

HOSTNAME = getattr(
settings,
'DJANGOCMS_LINK_INTRANET_HOSTNAME_PATTERN',
Expand Down Expand Up @@ -115,20 +103,6 @@ class AbstractLink(CMSPlugin):
blank=True,
max_length=255,
)
styles = models.CharField(
verbose_name=_('Styles'),
choices=STYLE_CHOICES,
blank=True,
max_length=255,
help_text=_('Optional style choices to be appended to "class". '
'Use "Attributes" to set addtional classes or styles.'),
)
link_type = models.CharField(
verbose_name=_('Link type'),
choices=TYPE_CHOICES,
blank=True,
max_length=255,
)
attributes = AttributesField(
verbose_name=_('Attributes'),
blank=True,
Expand Down
13 changes: 13 additions & 0 deletions djangocms_link/templates/djangocms_link/default/link.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,16 @@
{{ instance.name }}
{% endfor %}
</a>

{% comment %}
# https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a
{{ instance.name }}
{{ link }} or {{ instance.get_link }} summarizes:
{{ instance.external_link }}
{{ instance.internal_link }}
{{ instance.anchor }}
{{ instance.mailto }}
{{ instance.phone }}
{{ instance.target }}
{{ instance.attributes_str }}
{% endcomment %}
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

REQUIREMENTS = [
'django-cms>=3.2.0',
'django-select2>=4.3,<5.0',
'djangocms-attributes-field>=0.1.1',
]

Expand Down

0 comments on commit 8e2cd53

Please sign in to comment.