diff MoinMoin/items/__init__.py @ 244:a11656ba1eab

modify views: use flatland also for the file upload form field
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 29 May 2011 22:53:38 +0200
parents 69c0d9f6981d
children 52ca5dc1ab15
line wrap: on
line diff
--- a/MoinMoin/items/__init__.py	Sun May 29 20:40:03 2011 +0200
+++ b/MoinMoin/items/__init__.py	Sun May 29 22:53:38 2011 +0200
@@ -24,6 +24,7 @@
 
 from flatland import Form, String, Integer, Boolean, Enum
 from flatland.validation import Validator, Present, IsEmail, ValueBetween, URLValidator, Converted
+from MoinMoin.util.forms import FileStorage
 
 from MoinMoin.security.textcha import TextCha, TextChaizedForm, TextChaValid
 from MoinMoin.signalling import item_modified
@@ -688,6 +689,7 @@
         class ModifyForm(CommentForm):
             rev = Integer.using(optional=False)
             meta_text = String.using(optional=False).with_properties(placeholder=L_("MetaData (JSON)"))
+            data_file = FileStorage.using(optional=True, label=L_('Upload file:'))
 
         if request.method == 'GET':
             form = ModifyForm.from_defaults()
@@ -695,7 +697,7 @@
             form['meta_text'] = self.meta_dict_to_text(self.meta)
             form['rev'] = self.rev.revno if self.rev.revno is not None else -1
         elif request.method == 'POST':
-            form = ModifyForm.from_flat(request.form)
+            form = ModifyForm.from_flat(request.form.items() + request.files.items())
             TextCha(form).amend_form()
             valid = form.validate()
             if valid:
@@ -1145,7 +1147,8 @@
         class ModifyForm(CommentForm):
             rev = Integer.using(optional=False)
             meta_text = String.using(optional=False).with_properties(placeholder=L_("MetaData (JSON)"))
-            data_text = String.using(optional=False).with_properties(placeholder=L_("Type your text here"))
+            data_text = String.using(optional=True).with_properties(placeholder=L_("Type your text here"))
+            data_file = FileStorage.using(optional=True, label=L_('Upload file:'))
 
         if request.method == 'GET':
             if template_name is None and isinstance(self.rev, DummyRev):
@@ -1160,7 +1163,7 @@
             form['meta_text'] = self.meta_dict_to_text(self.meta)
             form['rev'] = self.rev.revno if self.rev.revno is not None else -1
         elif request.method == 'POST':
-            form = ModifyForm.from_flat(request.form)
+            form = ModifyForm.from_flat(request.form.items() + request.files.items())
             TextCha(form).amend_form()
             valid = form.validate()
             if valid:
@@ -1343,6 +1346,7 @@
             rev = Integer.using(optional=False)
             # XXX as the "saving" POSTs come from TWikiDraw (not the form), editing meta_text doesn't work
             meta_text = String.using(optional=False).with_properties(placeholder=L_("MetaData (JSON)"))
+            data_file = FileStorage.using(optional=True, label=L_('Upload file:'))
 
         if request.method == 'GET':
             form = ModifyForm.from_defaults()
@@ -1435,6 +1439,7 @@
             rev = Integer.using(optional=False)
             # XXX as the "saving" POSTs come from AnyWikiDraw (not the form), editing meta_text doesn't work
             meta_text = String.using(optional=False).with_properties(placeholder=L_("MetaData (JSON)"))
+            data_file = FileStorage.using(optional=True, label=L_('Upload file:'))
 
         if request.method == 'GET':
             form = ModifyForm.from_defaults()
@@ -1523,6 +1528,7 @@
             rev = Integer.using(optional=False)
             # XXX as the "saving" POSTs come from SvgDraw (not the form), editing meta_text doesn't work
             meta_text = String.using(optional=False).with_properties(placeholder=L_("MetaData (JSON)"))
+            data_file = FileStorage.using(optional=True, label=L_('Upload file:'))
 
         if request.method == 'GET':
             form = ModifyForm.from_defaults()