Repository navigation
Expand file tree
/
Copy pathmodels.py
More file actions
120 lines (98 loc) · 3.69 KB
/
Copy pathmodels.py
File metadata and controls
120 lines (98 loc) · 3.69 KB
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
from __future__ import absolute_import, unicode_literals
from django.contrib import admin
from django.core.exceptions import ImproperlyConfigured
from django.db import models
from django.utils.translation import ugettext_lazy as _
from feincms.admin.item_editor import FeinCMSInline
from feincms._internal import ct_render_to_string
try:
from filer.fields.file import FilerFileField
from filer.fields.image import FilerImageField
except ImportError:
__all__ = ()
else:
__all__ = (
'MediaFileContentInline', 'ContentWithFilerFile',
'FilerFileContent', 'FilerImageContent',
)
class MediaFileContentInline(FeinCMSInline):
radio_fields = {'type': admin.VERTICAL}
class ContentWithFilerFile(models.Model):
"""
File content
"""
feincms_item_editor_inline = MediaFileContentInline
class Meta:
abstract = True
def render(self, **kwargs):
return ct_render_to_string(
[
'content/filer/%s_%s.html' % (self.file_type, self.type),
'content/filer/%s.html' % self.type,
'content/filer/%s.html' % self.file_type,
'content/filer/default.html',
],
{'content': self},
request=kwargs.get('request'),
context=kwargs.get('context'),
)
class FilerFileContent(ContentWithFilerFile):
mediafile = FilerFileField(verbose_name=_('file'), related_name='+')
file_type = 'file'
type = 'download'
class Meta:
abstract = True
verbose_name = _('file')
verbose_name_plural = _('files')
class FilerImageContent(ContentWithFilerFile):
"""
Create a media file content as follows::
from feincms.contents import FilerImageContent
Page.create_content_type(FilerImageContent, TYPE_CHOICES=(
('inline', _('Default')),
('lightbox', _('Lightbox')),
('whatever', _('Whatever')),
))
For a media file of type 'image' and type 'lightbox', the following
templates are tried in order:
* content/mediafile/image_lightbox.html
* content/mediafile/lightbox.html
* content/mediafile/image.html
* content/mediafile/default.html
The context contains ``content`` and ``request`` (if available).
The content.mediafile attribute are as follows (selection):
label, description, default_caption, default_alt_text,
author, must_always_publish_author_credit,
must_always_publish_copyright, date_taken, file, id, is_public, url
"""
mediafile = FilerImageField(verbose_name=_('image'), related_name='+')
caption = models.CharField(
_('caption'),
max_length=1000,
blank=True,
)
url = models.CharField(
_('URL'),
max_length=1000,
blank=True,
)
file_type = 'image'
class Meta:
abstract = True
verbose_name = _('image')
verbose_name_plural = _('images')
@classmethod
def initialize_type(cls, TYPE_CHOICES=None):
if TYPE_CHOICES is None:
raise ImproperlyConfigured(
'You have to set TYPE_CHOICES when'
' creating a %s' % cls.__name__)
cls.add_to_class(
'type',
models.CharField(
_('type'),
max_length=20,
choices=TYPE_CHOICES,
default=TYPE_CHOICES[0][0],
),
)