@@ -148,3 +148,95 @@ def func_im(self, *args, **kwargs):
148148
149149 if cleanse :
150150 cls .cleanse = to_instance_method (cleanse )
151+
152+
153+ try :
154+ from filer .fields .file import FilerFileField
155+ from filer .fields .image import FilerImageField
156+ except ImportError :
157+ pass
158+ else :
159+
160+ class MediaFileContentInline (FeinCMSInline ):
161+ radio_fields = {'type' : admin .VERTICAL }
162+
163+ class ContentWithFilerFile (models .Model ):
164+ """
165+ MediaFile Content for use with Django-Filer.
166+ """
167+ feincms_item_editor_inline = MediaFileContentInline
168+
169+ class Meta :
170+ abstract = True
171+
172+ def render (self , ** kwargs ):
173+ ctx = {'content' : self }
174+ ctx .update (kwargs )
175+ return render_to_string ([
176+ 'content/filer/%s_%s.html' % (self .file_type , self .type ),
177+ 'content/filer/%s.html' % self .type ,
178+ 'content/filer/%s.html' % self .file_type ,
179+ 'content/filer/default.html' ,
180+ ], ctx , context_instance = kwargs .get ('context' ))
181+
182+ class FileContent (ContentWithFilerFile ):
183+ mediafile = FilerFileField (verbose_name = _ ('file' ), related_name = '+' )
184+ file_type = 'file'
185+ type = 'download'
186+
187+ class Meta :
188+ abstract = True
189+ verbose_name = _ ('file' )
190+ verbose_name_plural = _ ('files' )
191+
192+ class ImageContent (ContentWithFilerFile ):
193+ """
194+ Create a media file content as follows::
195+
196+ from feincms.content.medialibrary.v2 import MediaFileContent
197+ Page.create_content_type(MediaFileContent, TYPE_CHOICES=(
198+ ('inline', _('Default')),
199+ ('lightbox', _('Lightbox')),
200+ ('whatever', _('Whatever')),
201+ ))
202+
203+ For a media file of type 'image' and type 'lightbox', the following
204+ templates are tried in order:
205+
206+ * content/mediafile/image_lightbox.html
207+ * content/mediafile/lightbox.html
208+ * content/mediafile/image.html
209+ * content/mediafile/default.html
210+
211+ The context contains ``content`` and ``request`` (if available).
212+
213+ The content.mediafile attribute are as follows (selection):
214+ label, description, default_caption, default_alt_text,
215+ author, must_always_publish_author_credit,
216+ must_always_publish_copyright, date_taken, file, id, is_public, url
217+ """
218+
219+ mediafile = FilerImageField (verbose_name = _ ('image' ), related_name = '+' )
220+ file_type = 'image'
221+
222+ class Meta :
223+ abstract = True
224+ verbose_name = _ ('image' )
225+ verbose_name_plural = _ ('images' )
226+
227+ @classmethod
228+ def initialize_type (cls , TYPE_CHOICES = None ):
229+ if TYPE_CHOICES is None :
230+ raise ImproperlyConfigured (
231+ 'You have to set TYPE_CHOICES when'
232+ ' creating a %s' % cls .__name__ )
233+
234+ cls .add_to_class (
235+ 'type' ,
236+ models .CharField (
237+ _ ('type' ),
238+ max_length = 20 ,
239+ choices = TYPE_CHOICES ,
240+ default = TYPE_CHOICES [0 ][0 ],
241+ ),
242+ )
0 commit comments