Skip to content

Commit 314e33c

Browse files
committed
Move the MediaFileContent into the medialibrary app
... thereby making it even clearer that it is not the way to go anymore.
1 parent d6fcfe6 commit 314e33c

File tree

5 files changed

+81
-71
lines changed

5 files changed

+81
-71
lines changed

feincms/contents.py

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,6 @@
1010
from feincms import settings
1111
from feincms.admin.item_editor import FeinCMSInline
1212
from feincms.contrib.richtext import RichTextField
13-
from feincms.module.medialibrary.fields import ContentWithMediaFile
14-
15-
16-
class MediaFileContentInline(FeinCMSInline):
17-
raw_id_fields = ('mediafile',)
18-
radio_fields = {'type': admin.VERTICAL}
19-
20-
21-
class MediaFileContent(ContentWithMediaFile):
22-
"""
23-
Rehashed, backwards-incompatible media file content which does not contain
24-
the problems from v1 anymore.
25-
26-
Create a media file content as follows::
27-
28-
from feincms.content.medialibrary.v2 import MediaFileContent
29-
Page.create_content_type(MediaFileContent, TYPE_CHOICES=(
30-
('default', _('Default')),
31-
('lightbox', _('Lightbox')),
32-
('whatever', _('Whatever')),
33-
))
34-
35-
For a media file of type 'image' and type 'lightbox', the following
36-
templates are tried in order:
37-
38-
* content/mediafile/image_lightbox.html
39-
* content/mediafile/image.html
40-
* content/mediafile/lightbox.html
41-
* content/mediafile/default.html
42-
43-
The context contains ``content`` and ``request`` (if available).
44-
"""
45-
46-
feincms_item_editor_inline = MediaFileContentInline
47-
48-
class Meta:
49-
abstract = True
50-
verbose_name = _('media file')
51-
verbose_name_plural = _('media files')
52-
53-
@classmethod
54-
def initialize_type(cls, TYPE_CHOICES=None):
55-
if TYPE_CHOICES is None:
56-
raise ImproperlyConfigured(
57-
'You have to set TYPE_CHOICES when'
58-
' creating a %s' % cls.__name__)
59-
60-
cls.add_to_class(
61-
'type',
62-
models.CharField(
63-
_('type'),
64-
max_length=20,
65-
choices=TYPE_CHOICES,
66-
default=TYPE_CHOICES[0][0],
67-
)
68-
)
69-
70-
def render(self, **kwargs):
71-
ctx = {'content': self}
72-
ctx.update(kwargs)
73-
return render_to_string([
74-
'content/mediafile/%s_%s.html' % (self.mediafile.type, self.type),
75-
'content/mediafile/%s.html' % self.mediafile.type,
76-
'content/mediafile/%s.html' % self.type,
77-
'content/mediafile/default.html',
78-
], ctx, context_instance=kwargs.get('context'))
7913

8014

8115
class RawContent(models.Model):

feincms/management/commands/medialibrary_to_filer.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
from django.core.management.base import NoArgsCommand
55
from django.contrib.auth.models import User
66

7-
from feincms.contents import (
8-
MediaFileContent, FilerFileContent, FilerImageContent,
9-
)
7+
from feincms.contents import FilerFileContent, FilerImageContent
8+
from feincms.module.medialibrary.contents import MediaFileContent
109
from feincms.module.medialibrary.models import MediaFile
1110
from feincms.module.page.models import Page
1211

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
from __future__ 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+
from feincms.module.medialibrary.fields import ContentWithMediaFile
11+
12+
13+
class MediaFileContentInline(FeinCMSInline):
14+
raw_id_fields = ('mediafile',)
15+
radio_fields = {'type': admin.VERTICAL}
16+
17+
18+
class MediaFileContent(ContentWithMediaFile):
19+
"""
20+
Rehashed, backwards-incompatible media file content which does not contain
21+
the problems from v1 anymore.
22+
23+
Create a media file content as follows::
24+
25+
from feincms.content.medialibrary.v2 import MediaFileContent
26+
Page.create_content_type(MediaFileContent, TYPE_CHOICES=(
27+
('default', _('Default')),
28+
('lightbox', _('Lightbox')),
29+
('whatever', _('Whatever')),
30+
))
31+
32+
For a media file of type 'image' and type 'lightbox', the following
33+
templates are tried in order:
34+
35+
* content/mediafile/image_lightbox.html
36+
* content/mediafile/image.html
37+
* content/mediafile/lightbox.html
38+
* content/mediafile/default.html
39+
40+
The context contains ``content`` and ``request`` (if available).
41+
"""
42+
43+
feincms_item_editor_inline = MediaFileContentInline
44+
45+
class Meta:
46+
abstract = True
47+
verbose_name = _('media file')
48+
verbose_name_plural = _('media files')
49+
50+
@classmethod
51+
def initialize_type(cls, TYPE_CHOICES=None):
52+
if TYPE_CHOICES is None:
53+
raise ImproperlyConfigured(
54+
'You have to set TYPE_CHOICES when'
55+
' creating a %s' % cls.__name__)
56+
57+
cls.add_to_class(
58+
'type',
59+
models.CharField(
60+
_('type'),
61+
max_length=20,
62+
choices=TYPE_CHOICES,
63+
default=TYPE_CHOICES[0][0],
64+
)
65+
)
66+
67+
def render(self, **kwargs):
68+
ctx = {'content': self}
69+
ctx.update(kwargs)
70+
return render_to_string([
71+
'content/mediafile/%s_%s.html' % (self.mediafile.type, self.type),
72+
'content/mediafile/%s.html' % self.mediafile.type,
73+
'content/mediafile/%s.html' % self.type,
74+
'content/mediafile/default.html',
75+
], ctx, context_instance=kwargs.get('context'))

tests/testapp/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
from django.utils.translation import ugettext_lazy as _
88

99
from feincms.apps import ApplicationContent
10-
from feincms.contents import RawContent, MediaFileContent, TemplateContent
10+
from feincms.contents import RawContent, TemplateContent
1111
from feincms.models import Base, create_base_model
12+
from feincms.module.medialibrary.contents import MediaFileContent
1213
from feincms.module.page.models import Page
1314
from feincms.module.page import processors
1415

tests/testapp/tests/test_cms.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
from django.db import models
1010
from django.test import TestCase
1111

12-
from feincms.contents import RawContent, RichTextContent, MediaFileContent
12+
from feincms.contents import RawContent, RichTextContent
13+
from feincms.module.medialibrary.contents import MediaFileContent
1314

1415
from testapp.models import ExampleCMSBase, ExampleCMSBase2
1516
from .test_stuff import Empty

0 commit comments

Comments
 (0)