This repository has been archived by the owner on Jan 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
models.py
133 lines (108 loc) · 3.94 KB
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# -*- coding: utf-8 -*-
from functools import partial
from django.db import models
from django.utils.html import strip_tags
from django.utils.translation import ugettext_lazy as _
from cms.models.pluginmodel import CMSPlugin
from cms.models.fields import PageField
from djangocms_text_ckeditor.fields import HTMLField
from filer.fields.folder import FilerFolderField
from filer.fields.image import FilerImageField
from .utils import get_additional_styles
CMSPluginField = partial(
models.OneToOneField,
to=CMSPlugin,
related_name='+',
parent_link=True,
)
class GalleryPlugin(CMSPlugin):
STANDARD = 'standard'
STYLE_CHOICES = [
(STANDARD, _('Standard')),
]
ENGINE_CHOICES = (
('fade', _('Fade')),
('slide', _('Slide'))
)
cmsplugin_ptr = CMSPluginField()
style = models.CharField(
_('Style'), choices=STYLE_CHOICES + get_additional_styles(), default=STANDARD, max_length=50)
extra_styles = models.CharField(
_('Extra styles'), max_length=50, blank=True,
help_text=_('An arbitrary string of CSS classes to add'))
engine = models.CharField(_('Engine'), choices=ENGINE_CHOICES, default=ENGINE_CHOICES[0][0], max_length=50)
timeout = models.IntegerField(_('Timeout'), default=5000, help_text=_("Set to 0 to disable autoplay"))
duration = models.IntegerField(_('Duration'), default=300)
shuffle = models.BooleanField(_('Shuffle slides'), default=False)
def __unicode__(self):
style = _('Style')
engine = _('Engine')
timeout = _('Timeout')
duration = _('Duration')
shuffle = _('Shuffle Slides')
return u'%s: %s, %s: %s, %s: %i, %s: %i, %s: %s' % (
style, self.style.title(), engine, self.engine.title(),
timeout, self.timeout, duration, self.duration, shuffle, self.shuffle
)
class SlidePlugin(CMSPlugin):
LINK_TARGETS = (
('', _('same window')),
('_blank', _('new window')),
('_parent', _('parent window')),
('_top', _('topmost frame')),
)
cmsplugin_ptr = CMSPluginField()
image = FilerImageField(verbose_name=_('image'), blank=True, null=True)
content = HTMLField("Content", blank=True, null=True)
url = models.URLField(_("Link"), blank=True, null=True)
page_link = PageField(
verbose_name=_('Page'),
blank=True,
null=True,
help_text=_("A link to a page has priority over a text link.")
)
target = models.CharField(
verbose_name=_("target"),
max_length=100,
blank=True,
choices=LINK_TARGETS,
)
link_anchor = models.CharField(
verbose_name=_("link anchor"),
max_length=128,
blank=True,
)
link_text = models.CharField(
verbose_name=_('link text'),
max_length=200,
blank=True
)
def __unicode__(self):
image_text = content_text = ''
if self.image_id:
image_text = u'%s' % (self.image.name or self.image.original_filename)
if self.content:
text = strip_tags(self.content).strip()
if len(text) > 100:
content_text = u'%s...' % text[:100]
else:
content_text = u'%s' % text
if image_text and content_text:
return u'%s (%s)' % (image_text, content_text)
else:
return image_text or content_text
def copy_relations(self, oldinstance):
self.image_id = oldinstance.image_id
self.page_link_id = oldinstance.page_link_id
def get_link(self):
link = self.url or u''
if self.page_link_id:
link = self.page_link.get_absolute_url()
if self.link_anchor:
link += u'#' + self.link_anchor
return link
class SlideFolderPlugin(CMSPlugin):
cmsplugin_ptr = CMSPluginField()
folder = FilerFolderField(verbose_name=_('folder'))
def copy_relations(self, oldinstance):
self.folder_id = oldinstance.folder_id