Source

cmsplugin-photologue / cmsplugin_photologue / models.py

Full commit
from django.db import models
from cms.models import CMSPlugin, Page
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'),) )

# Note that you need to define photos_sized named CMSPLUGIN_PHOTOLOGUE_DISPLAY_MODE_CHOICES and defined them in your settings
CMSPLUGIN_PHOTOLOGUE_DISPLAY_MODE_CHOICES = getattr(settings,"CMSPLUGIN_PHOTOLOGUE_DISPLAY_MODE", (('0', 'big_normal'),('1', 'big_wide'),('2', 'big_square'),('3', 'display_normal'),('4', 'display_wide'),('5', 'display_square'),('6', 'thumbnail'),) )

#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'),) )
CMSPLUGIN_PHOTOLOGUE_TEASER_PHOTO_TEMPLATES_CHOICES = getattr(settings,"CMSPLUGIN_PHOTOLOGUE_TEASER_PHOTO_TEMPLATES", (('default', 'photologue_teaser_photo.html'),) )
CMSPLUGIN_PHOTOLOGUE_POPUP_PHOTO_TEMPLATES_CHOICES = getattr(settings,"CMSPLUGIN_PHOTOLOGUE_POPUP_PHOTO_TEMPLATES", (('default', 'photologue_popup_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'))
    display_mode = models.CharField(_('Display mode'), max_length=1, choices=CMSPLUGIN_PHOTOLOGUE_DISPLAY_MODE_CHOICES, default='3', help_text=_('Apply a specific display mode, normal for 4/3 without cropping, wide for 16/9 with cropping, square for 1/1, or thumbnail'))
    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):
    photo = models.ForeignKey(Photo)
    display_mode = models.CharField(_('Display mode'), max_length=1, choices=CMSPLUGIN_PHOTOLOGUE_DISPLAY_MODE_CHOICES, default='3', help_text=_('Apply a specific display mode, normal for 4/3 without cropping, wide for 16/9 with cropping, square for 1/1, or thumbnail'))
    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'))

class PhotologuePhotoTeaserPlugin(CMSPlugin):
    title = models.CharField(_("title"), max_length=255)
    photo = models.ForeignKey(Photo)
    display_mode = models.CharField(_('Display mode'), max_length=1, choices=CMSPLUGIN_PHOTOLOGUE_DISPLAY_MODE_CHOICES, default='3', help_text=_('Apply a specific display mode, normal for 4/3 without cropping, wide for 16/9 with cropping, square for 1/1, or thumbnail'))
    css = models.CharField(_('CSS class'), max_length=1, choices=CMSPLUGIN_PHOTOLOGUE_CSS_CHOICES, default='0', help_text=_('Additional CSS class to apply'))
    page_link = models.ForeignKey(
        Page, 
        verbose_name=_("page"), 
        help_text=_("If present image will be clickable"), 
        blank=True, 
        null=True, 
        limit_choices_to={'publisher_is_draft': True}
    )
    url = models.CharField(_("link"), max_length=255, blank=True, null=True, help_text=_("If present image will be clickable."))
    description = models.TextField(_("description"), blank=True, null=True)
    template = models.CharField(_('Plugin template'), max_length=255, choices=CMSPLUGIN_PHOTOLOGUE_TEASER_PHOTO_TEMPLATES_CHOICES, default='photologue_teaser_photo.html', help_text=_('Template used to render plugin'))

class PhotologuePhotoPopupPlugin(CMSPlugin):
    title = models.CharField(_("title"), max_length=255)
    photo = models.ForeignKey(Photo)
    display_mode = models.CharField(_('Display mode'), max_length=1, choices=CMSPLUGIN_PHOTOLOGUE_DISPLAY_MODE_CHOICES, default='3', help_text=_('Apply a specific display mode, normal for 4/3 without cropping, wide for 16/9 with cropping, square for 1/1, or thumbnail'))
    css = models.CharField(_('CSS class'), max_length=1, choices=CMSPLUGIN_PHOTOLOGUE_CSS_CHOICES, default='0', help_text=_('Additional CSS class to apply'))
    popup = models.ForeignKey(Photo, related_name='popup')
    popup_display_mode = models.CharField(_('Pop up display mode'), max_length=1, choices=CMSPLUGIN_PHOTOLOGUE_DISPLAY_MODE_CHOICES, default='3', help_text=_('Apply a specific display mode, normal for 4/3 without cropping, wide for 16/9 with cropping, square for 1/1, or thumbnail'))
    template = models.CharField(_('Plugin template'), max_length=255, choices=CMSPLUGIN_PHOTOLOGUE_POPUP_PHOTO_TEMPLATES_CHOICES, default='photologue_popup_photo.html', help_text=_('Template used to render plugin'))