Source

cmsplugin-photologue / cmsplugin_photologue / cms_plugins.py

The cms-2.X branch has multiple heads

from cms.plugin_base import CMSPluginBase
from cms.plugin_pool import plugin_pool
from cmsplugin_photologue.models import PhotologueGalleryPlugin, PhotologuePhotoPlugin
from django.utils.translation import ugettext as _
from photologue.models import Gallery, Photo
from django.conf import settings


class CMSPhotologueGalleryPlugin(CMSPluginBase):
    model = PhotologueGalleryPlugin
    name = _("Photologue Gallery")
    text_enabled = True

    def render(self, context, instance, placeholder):

        #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(),
            'text_enabled': self.text_enabled,
        })
        return context

plugin_pool.register_plugin(CMSPhotologueGalleryPlugin)


class CMSPhotologuePhotoPlugin(CMSPluginBase):
    model = PhotologuePhotoPlugin
    name = _("Photologue Photo")
    text_enabled = True

    def render(self, context, instance, placeholder):

        #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(),
            'text_enabled': self.text_enabled,
        })
        return context

plugin_pool.register_plugin(CMSPhotologuePhotoPlugin)