tehfink avatar tehfink committed 4940ca6

new features: define templates per plugin, and sample size for gallery plugin

Comments (0)

Files changed (2)

cmsplugin_photologue/cms_plugins.py

 from cms.plugin_base import CMSPluginBase
 from cms.plugin_pool import plugin_pool
-from models import *
+from cmsplugin_photologue.models import PhotologueGalleryPlugin, PhotologuePhotoPlugin
 from django.utils.translation import ugettext as _
-from photologue.models import *
+from photologue.models import Gallery, Photo
 from django.conf import settings
 
-#overrides photologue.urls.SAMPLE_SIZE : 'Number of random images from the gallery to display.'
-SAMPLE_SIZE = ":%s" % getattr(settings, 'CMSPLUGIN_PHOTOLOGUE_SAMPLE_SIZE', 3)
 
 class CMSPhotologueGalleryPlugin(CMSPluginBase):
     model = PhotologueGalleryPlugin
     name = _("Photologue Gallery")
     text_enabled = True
-    render_template = "plugins/cmsplugin_photologue/photologue_gallery.html"
 
     def render(self, context, instance, placeholder):
-        context.update({'gallery':instance.gallery, 'placeholder':placeholder})
-        context.update({'queryset': Gallery.objects.filter(is_public=True), 'allow_empty': True, 'paginate_by': 5, 'sample_size':SAMPLE_SIZE, 'css' : instance.get_css_display()})
+
+        #set plugin template from plugin model
+        self.render_template = "plugins/cmsplugin_photologue/%s" % instance.get_template_display()
+
+        context.update({
+            'gallery':      instance.gallery,
+            'placeholder':  placeholder,
+            'queryset':     Gallery.objects.filter(is_public=True),
+            'allow_empty':  True,
+            'paginate_by':  5,
+            'sample_size':  ":%s" % instance.sample_size,
+            'css':          instance.get_css_display(),
+        })
         return context
 
 plugin_pool.register_plugin(CMSPhotologueGalleryPlugin)
     model = PhotologuePhotoPlugin
     name = _("Photologue Photo")
     text_enabled = True
-    render_template = "plugins/cmsplugin_photologue/photologue_photo.html"
 
     def render(self, context, instance, placeholder):
-        context.update({'photo':instance.photo, 'placeholder':placeholder})
-        context.update({'slug_field': 'title_slug', 'queryset': Photo.objects.filter(is_public=True), 'is_thumb' : instance.is_thumb, 'css' : instance.get_css_display()})
+
+        #set plugin template from plugin model
+        self.render_template = "plugins/cmsplugin_photologue/%s" % instance.get_template_display()
+
+        context.update({
+            'photo':        instance.photo,
+            'placeholder':  placeholder,
+            'slug_field':   'title_slug',
+            'queryset':     Photo.objects.filter(is_public=True),
+            'is_thumb':     instance.is_thumb,
+            'css':          instance.get_css_display(),
+        })
         return context
 
 plugin_pool.register_plugin(CMSPhotologuePhotoPlugin)

cmsplugin_photologue/models.py

 from django.db import models
 from cms.models import CMSPlugin
-from photologue.models import *
+from photologue.models import Gallery, Photo
 from django.utils.translation import ugettext_lazy as _
 from django.conf import settings
 
+
 #get custom css from settings or use default
 CMSPLUGIN_PHOTOLOGUE_CSS_CHOICES = getattr(settings,"CMSPLUGIN_PHOTOLOGUE_CSS", (('0', ''),('1', 'left'),('2', 'right'),('3', 'center'),) )
 
+#get custom templates from settings or use default
+CMSPLUGIN_PHOTOLOGUE_GALLERY_TEMPLATES_CHOICES = getattr(settings,"CMSPLUGIN_PHOTOLOGUE_GALLERY_TEMPLATES", (('default', 'photologue_gallery.html'),) )
+CMSPLUGIN_PHOTOLOGUE_PHOTO_TEMPLATES_CHOICES = getattr(settings,"CMSPLUGIN_PHOTOLOGUE_PHOTO_TEMPLATES", (('default', 'photologue_photo.html'),) )
+
+#get custom gallery sample size from settings or use default (overrides photologue.urls.SAMPLE_SIZE)
+SAMPLE_SIZE = getattr(settings, 'CMSPLUGIN_PHOTOLOGUE_SAMPLE_SIZE', 3)
+
 
 class PhotologueGalleryPlugin(CMSPlugin):
     gallery = models.ForeignKey(Gallery)
+    sample_size = models.PositiveSmallIntegerField(_('Sample size'), default=SAMPLE_SIZE, help_text=_('Number of random images to display from the gallery'))
     css = models.CharField(_('CSS class'), max_length=1, choices=CMSPLUGIN_PHOTOLOGUE_CSS_CHOICES, default='0', help_text=_('Additional CSS class to apply'))
+    template = models.CharField(_('Plugin template'), max_length=255, choices=CMSPLUGIN_PHOTOLOGUE_GALLERY_TEMPLATES_CHOICES, default='photologue_gallery.html', help_text=_('Template used to render plugin'))
+
 
 class PhotologuePhotoPlugin(CMSPlugin):
     IS_THUMB_CHOICES = (
     photo = models.ForeignKey(Photo)
     is_thumb = models.CharField(_('is thumbnail'), max_length=1, choices=IS_THUMB_CHOICES, default='0', help_text=_('Show thumbnail or full size image'))
     css = models.CharField(_('CSS class'), max_length=1, choices=CMSPLUGIN_PHOTOLOGUE_CSS_CHOICES, default='0', help_text=_('Additional CSS class to apply'))
+    template = models.CharField(_('Plugin template'), max_length=255, choices=CMSPLUGIN_PHOTOLOGUE_PHOTO_TEMPLATES_CHOICES, default='photologue_photo.html', help_text=_('Template used to render plugin'))
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 ProjectModifiedEvent.java.
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.