Skip to content

Commit 0a52a9f

Browse files
committed
Move contents back to feincms.content to minimize the diff
Splitting up into packages may follow, but that would be something different.
1 parent dd6601a commit 0a52a9f

File tree

6 files changed

+219
-220
lines changed

6 files changed

+219
-220
lines changed

feincms/content/filer/__init__.py

Whitespace-only changes.

feincms/content/filer/models.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
from __future__ import absolute_import, unicode_literals
2+
3+
from django.contrib import admin
4+
from django.core.exceptions import ImproperlyConfigured
5+
from django.db import models
6+
from django.template.loader import render_to_string
7+
from django.utils.translation import ugettext_lazy as _
8+
9+
from feincms.admin.item_editor import FeinCMSInline
10+
11+
try:
12+
from filer.fields.file import FilerFileField
13+
from filer.fields.image import FilerImageField
14+
except ImportError:
15+
__all__ = ()
16+
17+
else:
18+
19+
__all__ = (
20+
'MediaFileContentInline', 'ContentWithFilerFile',
21+
'FilerFileContent', 'FilerImageContent',
22+
)
23+
24+
class MediaFileContentInline(FeinCMSInline):
25+
radio_fields = {'type': admin.VERTICAL}
26+
27+
class ContentWithFilerFile(models.Model):
28+
"""
29+
File content
30+
"""
31+
feincms_item_editor_inline = MediaFileContentInline
32+
33+
class Meta:
34+
abstract = True
35+
36+
def render(self, **kwargs):
37+
ctx = {'content': self}
38+
ctx.update(kwargs)
39+
return render_to_string([
40+
'content/filer/%s_%s.html' % (self.file_type, self.type),
41+
'content/filer/%s.html' % self.type,
42+
'content/filer/%s.html' % self.file_type,
43+
'content/filer/default.html',
44+
], ctx, context_instance=kwargs.get('context'))
45+
46+
class FilerFileContent(ContentWithFilerFile):
47+
mediafile = FilerFileField(verbose_name=_('file'), related_name='+')
48+
file_type = 'file'
49+
type = 'download'
50+
51+
class Meta:
52+
abstract = True
53+
verbose_name = _('file')
54+
verbose_name_plural = _('files')
55+
56+
class FilerImageContent(ContentWithFilerFile):
57+
"""
58+
Create a media file content as follows::
59+
60+
from feincms.contents import FilerImageContent
61+
Page.create_content_type(FilerImageContent, TYPE_CHOICES=(
62+
('inline', _('Default')),
63+
('lightbox', _('Lightbox')),
64+
('whatever', _('Whatever')),
65+
))
66+
67+
For a media file of type 'image' and type 'lightbox', the following
68+
templates are tried in order:
69+
70+
* content/mediafile/image_lightbox.html
71+
* content/mediafile/lightbox.html
72+
* content/mediafile/image.html
73+
* content/mediafile/default.html
74+
75+
The context contains ``content`` and ``request`` (if available).
76+
77+
The content.mediafile attribute are as follows (selection):
78+
label, description, default_caption, default_alt_text,
79+
author, must_always_publish_author_credit,
80+
must_always_publish_copyright, date_taken, file, id, is_public, url
81+
"""
82+
83+
mediafile = FilerImageField(verbose_name=_('image'), related_name='+')
84+
caption = models.CharField(
85+
_('caption'),
86+
max_length=1000,
87+
blank=True,
88+
)
89+
url = models.CharField(
90+
_('URL'),
91+
max_length=1000,
92+
blank=True,
93+
)
94+
95+
file_type = 'image'
96+
97+
class Meta:
98+
abstract = True
99+
verbose_name = _('image')
100+
verbose_name_plural = _('images')
101+
102+
@classmethod
103+
def initialize_type(cls, TYPE_CHOICES=None):
104+
if TYPE_CHOICES is None:
105+
raise ImproperlyConfigured(
106+
'You have to set TYPE_CHOICES when'
107+
' creating a %s' % cls.__name__)
108+
109+
cls.add_to_class(
110+
'type',
111+
models.CharField(
112+
_('type'),
113+
max_length=20,
114+
choices=TYPE_CHOICES,
115+
default=TYPE_CHOICES[0][0],
116+
),
117+
)

feincms/content/raw/models.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,24 @@
1-
# flake8: noqa
21
from __future__ import absolute_import, unicode_literals
32

4-
import warnings
3+
from django.db import models
4+
from django.utils.safestring import mark_safe
5+
from django.utils.translation import ugettext_lazy as _
56

6-
from feincms.contents import RawContent
77

8-
warnings.warn(
9-
'Import RawContent from feincms.contents.',
10-
DeprecationWarning, stacklevel=2)
8+
class RawContent(models.Model):
9+
"""
10+
Content type which can be used to input raw HTML code into the CMS.
11+
12+
The content isn't escaped and can be used to insert CSS or JS
13+
snippets too.
14+
"""
15+
16+
text = models.TextField(_('content'), blank=True)
17+
18+
class Meta:
19+
abstract = True
20+
verbose_name = _('raw content')
21+
verbose_name_plural = _('raw contents')
22+
23+
def render(self, **kwargs):
24+
return mark_safe(self.text)

feincms/content/richtext/models.py

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,47 @@
1-
# flake8: noqa
21
from __future__ import absolute_import, unicode_literals
32

4-
import warnings
3+
from django.db import models
4+
from django.template.loader import render_to_string
5+
from django.utils.translation import ugettext_lazy as _
56

6-
from feincms.contents import RichTextContent
7+
from feincms import settings
8+
from feincms.contrib.richtext import RichTextField
79

8-
warnings.warn(
9-
'Import RichTextContent from feincms.contents.',
10-
DeprecationWarning, stacklevel=2)
10+
11+
class RichTextContent(models.Model):
12+
"""
13+
Rich text content. Uses TinyMCE by default, but can be configured to do
14+
anything you want using ``FEINCMS_RICHTEXT_INIT_CONTEXT`` and
15+
``FEINCMS_RICHTEXT_INIT_TEMPLATE``.
16+
17+
If you are using TinyMCE 4.x then ``FEINCMS_RICHTEXT_INIT_TEMPLATE``
18+
needs to be set to ``admin/content/richtext/init_tinymce4.html``.
19+
20+
Optionally runs the HTML code through HTML cleaners if you specify
21+
``cleanse=True`` when calling ``create_content_type``.
22+
"""
23+
24+
feincms_item_editor_context_processors = (
25+
lambda x: settings.FEINCMS_RICHTEXT_INIT_CONTEXT,
26+
)
27+
feincms_item_editor_includes = {
28+
'head': [settings.FEINCMS_RICHTEXT_INIT_TEMPLATE],
29+
}
30+
31+
class Meta:
32+
abstract = True
33+
verbose_name = _('rich text')
34+
verbose_name_plural = _('rich texts')
35+
36+
def render(self, **kwargs):
37+
return render_to_string(
38+
'content/richtext/default.html',
39+
{'content': self},
40+
context_instance=kwargs.get('context'))
41+
42+
@classmethod
43+
def initialize_type(cls, cleanse=None):
44+
cls.add_to_class(
45+
'text',
46+
RichTextField(_('text'), blank=True, cleanse=cleanse),
47+
)

feincms/content/template/models.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
1-
# flake8: noqa
21
from __future__ import absolute_import, unicode_literals
32

4-
import warnings
3+
from django.db import models
4+
from django.template.loader import render_to_string
5+
from django.utils.translation import ugettext_lazy as _
56

6-
from feincms.contents import TemplateContent
7+
from feincms.content.raw.models import RawContent # noqa
8+
from feincms.content.richtext.models import RichTextContent # noqa
79

8-
warnings.warn(
9-
'Import TemplateContent from feincms.contents.',
10-
DeprecationWarning, stacklevel=2)
10+
11+
class TemplateContent(models.Model):
12+
"""
13+
Pass a list of templates when creating this content type. It uses the
14+
default template system::
15+
16+
Page.create_content_type(TemplateContent, TEMPLATES=[
17+
('content/template/something1.html', 'something'),
18+
('content/template/something2.html', 'something else'),
19+
('base.html', 'makes no sense'),
20+
])
21+
"""
22+
class Meta:
23+
abstract = True
24+
verbose_name = _('template content')
25+
verbose_name_plural = _('template contents')
26+
27+
@classmethod
28+
def initialize_type(cls, TEMPLATES):
29+
cls.add_to_class('template', models.CharField(
30+
_('template'),
31+
max_length=100,
32+
choices=TEMPLATES,
33+
))
34+
35+
def render(self, **kwargs):
36+
return render_to_string(
37+
self.template,
38+
{'content': self},
39+
context_instance=kwargs.get('context'))

0 commit comments

Comments
 (0)