Bertrand Bordage committed 1c76ff4 Draft

Automatically crops and upscales images.

Comments (0)

Files changed (3)


 # coding: utf-8
 from cms.plugin_base import CMSPluginBase
-from cms.plugin_pool import plugin_pool
 from .models import SliderPlugin
 from django.utils.translation import ugettext_lazy as _
+from cms.plugin_pool import plugin_pool
 class CMSSliderPlugin(CMSPluginBase):
     render_template = 'nivo/slider.html'
     text_enabled = False
     admin_preview = False
+    fieldsets = (
+        (None, {
+            'fields': ('title', 'album', ('theme', 'effect',),
+                       ('anim_speed', 'pause_time',), ('width', 'height',),),
+        }),
+        (_('Controls'), {
+            'fields': (('manual_advance', 'pause_on_hover',),
+                       ('arrows', 'thumbnails',), 'random_start',),
+        }),
+    )
     def render(self, context, instance, placeholder):
             'object': instance,
-            'placeholder': placeholder,
             'images': instance.images,
         return context


     def images(self):
         if not hasattr(self, '__images'):
-            files = self.album.files.order_by('name')
+            files = self.album.files
             self.__images = [f for f in files if f.file_type == 'Image']
         return self.__images
+    @property
+    def size(self):
+        if self.width and self.height:
+            return self.width, self.height
     search_fields = ('title', 'album__title',)


 {% load i18n sekizai_tags %}
+{% load thumbnail %}
 {% addtoblock "css" %}
             {% endif %}>
         {% for img in images %}
             <img    id="nivo-slide{{}}-image"
-                    src="{{img.image.url}}"
+                    src="{% if object.size %}{% thumbnail img.image object.size crop upscale %}{% else %}{{ img.image.url }}{% endif %}"
                     data-thumb="{{ img.image.icons.64 }}"
                     alt="{{|default:''}}" />
             {% spaceless %}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.