Commits

Steve Losh committed 1329448

Add file widgets.

Comments (0)

Files changed (3)

         else:
             initial = {}
             for pc in page.pagecontent_set.all():
-                initial['content_' + clean_field_title(pc.title)] = pc.content
+                initial['content_' + clean_field_title(pc.title)] = pc.get_content()
 
             content_form = stoat_forms.get_content_form(page.template, initial=initial)
 
         return FileBrowseFormField(format='Image', label=title, required=required,
                                    widget=FileBrowseWidget(attrs=attrs))
 
+    if typ == 'file':
+        from filebrowser.fields import FileBrowseFormField, FileBrowseWidget
+
+        fmat = options.get('format', 'File')
+        attrs = { 'directory': '', 'extensions': '', 'format': fmat, }
+
+        return FileBrowseFormField(format=fmat, label=title, required=required,
+                                   widget=FileBrowseWidget(attrs=attrs))
+
     if typ == 'fk':
         app_label = options.get('app', 'stoat')
         model_name = options.get('model', 'Page')
     ('text', 'text'),
     ('ckeditor', 'ckeditor'),
     ('img', 'img'),
+    ('file', 'file'),
     ('fk', 'fk'),
     ('int', 'int'),)
 TEMPLATES = [(name, name) for name in settings.STOAT_TEMPLATES.keys()]
                 return model.objects.get(id=self.content)
             except model.DoesNotExist:
                 return None
+        elif self.typ in ['file', 'img']:
+            from filebrowser.base import FileObject
+            from django.conf import settings
+            import os
+            return FileObject(os.path.join(settings.MEDIA_ROOT, self.content))
         else:
             return self.content