Source

cmsplugin-nivoslider / cmsplugin_nivoslider / models.py

Full commit
Bertrand Bordage aab3f25 
bcabezas fa80506 
Bertrand Bordage 7de282d 
Bertrand Bordage e5ed930 
bcabezas fa80506 

Bertrand Bordage d09018a 
bcabezas caa02c2 
Marion  Balensi e5cc9f6 
bcabezas caa02c2 
bcabezas fa80506 
Bertrand Bordage 601780a 
bcabezas caa02c2 

















Bertrand Bordage 601780a 

bcabezas caa02c2 






Bertrand Bordage 601780a 

bcabezas caa02c2 

Marion  Balensi e5cc9f6 




















Marion  Balensi 44ed1a5 
bcabezas caa02c2 
bcabezas fa80506 
bcabezas caa02c2 
bcabezas fa80506 
Bertrand Bordage d09018a 
bcabezas fa80506 
Bertrand Bordage d09018a 


Bertrand Bordage e5ed930 
Bertrand Bordage 9c375a5 
Bertrand Bordage d09018a 

Bertrand Bordage 1c76ff4 




Bertrand Bordage d09018a 
# coding: utf-8

from django.db.models import BooleanField, PositiveIntegerField, \
                             CharField

from cms.models import CMSPlugin
from filer.fields.folder import FilerFolderField
from django.contrib.staticfiles.finders import find as staticfiles_find
from django.utils.translation import ugettext, ugettext_lazy as _
import os


EFFECTS = """
    sliceDown
    sliceDownLeft
    sliceUp
    sliceUpLeft
    sliceUpDown
    sliceUpDownLeft
    fold
    fade
    random
    slideInRight
    slideInLeft
    boxRandom
    boxRain
    boxRainReverse
    boxRainGrow
    boxRainGrowReverse
"""
EFFECT_CHOICES = ((e, e) for e in EFFECTS.split())


def find_themes():
    themedirs = staticfiles_find("nivo/themes/", all=True)
    for dir in themedirs:
        for theme in os.listdir(dir):
            yield theme

THEME_CHOICES = ((t, t) for t in set(find_themes()))


class SliderPlugin(CMSPlugin):
    title = CharField(_('title'), max_length=255, null=True, blank=True)
    album = FilerFolderField(verbose_name=_('album'))
    theme = CharField(_('theme'), choices=THEME_CHOICES, max_length=50,
                      default="default")
    effect = CharField(_('effect'), choices=EFFECT_CHOICES, max_length=50,
                       default="random")
    manual_advance = BooleanField(_('manual advance'))
    anim_speed = PositiveIntegerField(_('anim speed'), default=500,
                                      help_text=_("Animation Speed (ms)"))
    pause_time = PositiveIntegerField(_('pause time'), default=3000,
                                      help_text=_("Pause time (ms)"))
    width = PositiveIntegerField(_('width'), null=True, blank=True,
                                 help_text=_("Width of the plugin (px)"))
    height = PositiveIntegerField(_('height'), null=True, blank=True,
                                  help_text=_("Height of the plugin (px)"))
    arrows = BooleanField(_('arrows'), default=True,
                          help_text=_('Arrow buttons for navigation'))
    thumbnails = BooleanField(_('thumbnails'),
                              help_text=_('Thumbnails for navigation [only '
                                          'works with the default theme!]'))
    random_start = BooleanField(_('random start'))
    pause_on_hover = BooleanField(_('pause on mouse hover'), default=True)

    def __unicode__(self):
        if self.title:
            return self.title
        return unicode(self.album)

    @property
    def images(self):
        if not hasattr(self, '__images'):
            files = self.album.files.order_by('name', 'original_filename')
            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',)