Skip to content

Commit

Permalink
Implements attributes field (django-cms#241)
Browse files Browse the repository at this point in the history
* Drop support for old Pythons, Djangos and CMSes

* Delete South migrations
* Update readme for new support matrix
* Update setup.py for new support matrix
* Drop test requirements for Django 1.7 and lower
* Add test requirements for Django 1.9
* Update test matrix in tox and travis conf.
* Fix flake issue in AUTHORS

* Implemented attributes-field for File, Image and Link plugins

For each plugin:
* Added attributes-field and `attributes_str` method to models
* Added migration
* Added form for presenting fields nicely
* Added fieldsets to plugins
* Updated templates to support attributes
* Updated translation strings

* Address review comments

* Removed explicit property
  • Loading branch information
mkoistinen authored Jun 21, 2016
1 parent c22ffa4 commit 206e76e
Show file tree
Hide file tree
Showing 80 changed files with 388 additions and 7,883 deletions.
23 changes: 19 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@ language: python

sudo: false

python: 3.5

env:
- TOXENV=flake8
- 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
- TOXENV=py27-dj17-cms31
- TOXENV=py27-dj17-cms30
- TOXENV=py27-dj16-cms31
- TOXENV=py27-dj16-cms30

cache:
directories:
Expand Down
2 changes: 1 addition & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

* Divio GmbH (divio.ch)
* Stefan Foulis <stefan.foulis@gmail.com>
* Yann Malet <yann.malet@gmail.com>
* Yann Malet <yann.malet@gmail.com>
46 changes: 32 additions & 14 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,28 @@ cmsplugin-filer
A set of cms plugins that replace the plugins shipped with django-cms with
versions that use file fields from django-filer.

Warning: starting with version 0.10 support for django-cms 2.x was dropped (table renaming magic removal).
Pin your dependencies to ``cmsplugin-filer<0.10`` for django-cms 2.x projects.
Warning: ::

NOTICE TO DJANGO 1.7 USERS:
Starting with version 1.1.0, support for Python 2.6, Django 1.7 or lower
and django CMS 3.0.x and lower was dropped. Please pin your dependencies
to ``cmsplugin-filer<1.1.0`` for older projects.

To use cmsplugin-filer, you **must** use the latest 3.0.x or any 3.1/3.2 version of django CMS.
Starting with version 0.10 support for django CMS 2.x was dropped
(table renaming magic removal). Pin your dependencies to
``cmsplugin-filer<0.10`` for django-cms 2.x projects.


Dependencies
============

* django-filer >= 1.2
* Django >= 1.4
* django-cms >= 3.0
* Django >= 1.8
* django-cms >= 3.1
* django-sekizai >= 0.4.2
* easy_thumbnails >= 1.0
* django-appconf
* djangocms-attributes-field


Installation
============
Expand All @@ -47,9 +52,12 @@ To get started using ``cmsplugin-filer``:
...
)


- run ``migrate``.

You can also set ``FILER_IMAGE_USE_ICON`` in your ``settings.py`` to configure ``cmsplugin_filer_image`` plugin to use 32x32 icons for representing plugin instances.
You can also set ``FILER_IMAGE_USE_ICON`` in your ``settings.py`` to configure
``cmsplugin_filer_image`` plugin to use 32x32 icons for representing
plugin instances.

The default template in ``cmsplugin_filer_image`` expects the subject location functionality to be enabled.
Follow: http://django-filer.readthedocs.org/en/latest/installation.html#subject-location-aware-cropping
Expand Down Expand Up @@ -108,7 +116,14 @@ and change all ``'cmsplugin_filer_image.ThumbnailOption'`` to ``thumbnail_model`
``u"orm['cmsplugin_filer_image.ThumbnailOption']"`` to ``u"orm['%s']" % thumbnail_model``.


The default template in ``cmsplugin_filer_image`` expects the subject location
functionality to be enabled.
Follow: http://django-filer.readthedocs.org/en/0.9.2/installation.html#subject-location-aware-cropping

Please note that current develop version moved plugin packages from `src`
directory to project root. This may break your installation if upgrading.
Uninstall any previous `cmsplugin_filer` installation (either from PyPI or
from github repository) and reinstall it.


Integrations
Expand All @@ -122,15 +137,17 @@ Integrations
`djangocms-text-ckeditor <http://pypi.python.org/pypi/djangocms-text-ckeditor/>`__.
Add this setting to enable it::

TEXT_SAVE_IMAGE_FUNCTION='cmsplugin_filer_image.integrations.ckeditor.create_image_plugin'
TEXT_SAVE_IMAGE_FUNCTION='cmsplugin_filer_image.integrations.ckeditor.create_image_plugin'

This allows dragging images into the text editor in Firefox and newer versions of IE.
This allows dragging images into the text editor in Firefox and newer versions
of IE.


Customisation
-------------

Most plugins (file, folder, image and teaser) support configuring custom "styles" (templates).
Most plugins (file, folder, image and teaser) support configuring custom
"styles" (templates).

e.g add the following settings for the image plugin::

Expand All @@ -140,9 +157,10 @@ e.g add the following settings for the image plugin::
)
CMSPLUGIN_FILER_IMAGE_DEFAULT_STYLE = 'boxed'

Now, if a template exists at ``cmsplugin_filer_image/plugins/image/boxed.html`` it will be used. If not, it will fall
back to ``cmsplugin_filer_image/plugins/image/default.html``. If a css class in the default template is enough, it can
be used in the template as ``{{ instance.style }}``.
Now, if a template exists at ``cmsplugin_filer_image/plugins/image/boxed.html``
it will be used. If not, it will fall back to ``cmsplugin_filer_image/plugins/image/default.html``.
If a css class in the default template is enough, it can be used in the
template as ``{{ instance.style }}``.

For backwards compatibility the plugin will always use ``cmsplugin_filer_image/image.html`` if it exists. Remove that
template after migrating to the new structure.
Expand All @@ -151,4 +169,4 @@ template after migrating to the new structure.
Classes
-------

Classes like ``left``, ``center``, ``right`` and ``img-responsive`` are given by the plugin to use in your own projects.
Classes like ``left``, ``center``, ``right`` and ``img-responsive`` are given by the plugin to use in your own projects.
2 changes: 1 addition & 1 deletion cmsplugin_filer_file/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.0.1.dev1"
__version__ = "1.1.0"
30 changes: 21 additions & 9 deletions cmsplugin_filer_file/cms_plugins.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,41 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from cms.plugin_pool import plugin_pool
from cms.plugin_base import CMSPluginBase
from django.template.loader import select_template
from django.templatetags.static import static
from django.utils.translation import ugettext_lazy as _
from . import models

from cms.plugin_pool import plugin_pool
from cms.plugin_base import CMSPluginBase

from .conf import settings
from .forms import FilerFileForm
from .models import FilerFile


class FilerFilePlugin(CMSPluginBase):
form = FilerFileForm
module = 'Filer'
model = models.FilerFile
model = FilerFile
name = _("File")
TEMPLATE_NAME = 'cmsplugin_filer_file/plugins/file/%s.html'
render_template = TEMPLATE_NAME % 'default'
text_enabled = True

fieldsets = (
(None, {'fields': [
'title',
'file',
'target_blank'
]}),
(None, {
'fields': [
'title', 'file', 'target_blank'
]
}),
(_('Advanced'), {
'classes': ['collapse', ],
'fields': [
'link_attributes',
]
})
)

if settings.CMSPLUGIN_FILER_FILE_STYLE_CHOICES:
fieldsets[0][1]['fields'].append('style')

Expand Down
20 changes: 20 additions & 0 deletions cmsplugin_filer_file/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-

from __future__ import unicode_literals

from django import forms

from djangocms_attributes_field.widgets import AttributesWidget

from .models import FilerFile


class FilerFileForm(forms.ModelForm):

class Meta:
model = FilerFile
exclude = []

def __init__(self, *args, **kwargs):
super(FilerFileForm, self).__init__(*args, **kwargs)
self.fields['link_attributes'].widget = AttributesWidget(val_attrs={'style': 'width: 500px!important'})
22 changes: 17 additions & 5 deletions cmsplugin_filer_file/locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2013-01-09 18:33+0100\n"
"POT-Creation-Date: 2016-06-17 17:12-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -17,18 +17,30 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: cms_plugins.py:10
#: cms_plugins.py:20
msgid "File"
msgstr ""

#: models.py:22
#: cms_plugins.py:31
msgid "Advanced"
msgstr ""

#: models.py:34
msgid "title"
msgstr ""

#: models.py:23
#: models.py:36
msgid "file"
msgstr ""

#: models.py:24
#: models.py:40
msgid "Open link in new window"
msgstr ""

#: models.py:42
msgid "Style"
msgstr ""

#: models.py:44
msgid "Optional. Adds HTML attributes to the rendered link."
msgstr ""
21 changes: 21 additions & 0 deletions cmsplugin_filer_file/migrations/0003_filerfile_link_attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.6 on 2016-06-16 21:56
from __future__ import unicode_literals

from django.db import migrations
import djangocms_attributes_field.fields


class Migration(migrations.Migration):

dependencies = [
('cmsplugin_filer_file', '0002_auto_20160112_1617'),
]

operations = [
migrations.AddField(
model_name='filerfile',
name='link_attributes',
field=djangocms_attributes_field.fields.AttributesField(default=dict, help_text='Optional. Adds HTML attributes to the rendered link.'),
),
]
11 changes: 10 additions & 1 deletion cmsplugin_filer_file/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from cms.models import CMSPlugin
from django.db import models
from django.utils.translation import ugettext_lazy as _

from cms.models import CMSPlugin

from filer.fields.file import FilerFileField
from filer.utils.compatibility import python_2_unicode_compatible

from cmsplugin_filer_utils import FilerPluginManager
from djangocms_attributes_field.fields import AttributesField

from .conf import settings


Expand All @@ -24,6 +29,8 @@ class FilerFile(CMSPlugin):
"""
STYLE_CHOICES = settings.CMSPLUGIN_FILER_FILE_STYLE_CHOICES
DEFAULT_STYLE = settings.CMSPLUGIN_FILER_FILE_DEFAULT_STYLE
EXCLUDED_KEYS = ['href', 'target', ]

title = models.CharField(_("title"), max_length=255, null=True, blank=True)
file = FilerFileField(
verbose_name=_('file'),
Expand All @@ -33,6 +40,8 @@ class FilerFile(CMSPlugin):
target_blank = models.BooleanField(_('Open link in new window'), default=False)
style = models.CharField(
_('Style'), choices=STYLE_CHOICES, default=DEFAULT_STYLE, max_length=255, blank=True)
link_attributes = AttributesField(excluded_keys=EXCLUDED_KEYS,
help_text=_('Optional. Adds HTML attributes to the rendered link.'))

objects = FilerPluginManager(select_related=('file',))

Expand Down
Loading

0 comments on commit 206e76e

Please sign in to comment.