changeset 626:f64779d5d500

FormSubmit: simplify code, auto-provide filename
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Mon, 25 Mar 2013 18:29:47 +0100
parents f4e63b74b969
children f683dea1ac1b
files data/plugin/action/submitbase.py data/plugin/action/submitcsv.py data/plugin/action/submitemail.py
diffstat 3 files changed, 7 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/data/plugin/action/submitbase.py	Mon Mar 25 17:47:30 2013 +0100
+++ b/data/plugin/action/submitbase.py	Mon Mar 25 18:29:47 2013 +0100
@@ -219,10 +219,11 @@
         
         if 'labels' in form:
             _labels = form.get('labels').split(";")
-            print _labels
             for label in _labels:
                 label = label.encode('utf-8')
                 labels.append(label)
+                if label == 'Attachment' and label not in fields and self.targetFile:
+                    fields[label] = self.targetFile  # provide filename, if none is given
                 values.append(fields[label])
         else:
             labels = fields.keys()
@@ -237,3 +238,4 @@
 
 class SubmitValidationError(Exception):
     """ Exception raised for errors during validation """
+
--- a/data/plugin/action/submitcsv.py	Mon Mar 25 17:47:30 2013 +0100
+++ b/data/plugin/action/submitcsv.py	Mon Mar 25 18:29:47 2013 +0100
@@ -32,13 +32,8 @@
         SubmitBase.__init__(self, pagename, request)
         
         self.delimiter = ';'
-        self.targetFile = ""
-        
-        if "targetfile" in request.form:
-            self.targetFile = request.form.get("targetfile")
-        else:
-            self.targetFile = u"list.csv"
-        
+        self.targetFile = request.form.get("targetfile", "list.csv")
+
     def sanitize(self):
         SubmitBase.sanitize(self)
         self.targetFile = wikiutil.clean_input(self.targetFile)
--- a/data/plugin/action/submitemail.py	Mon Mar 25 17:47:30 2013 +0100
+++ b/data/plugin/action/submitemail.py	Mon Mar 25 18:29:47 2013 +0100
@@ -1,5 +1,4 @@
 # -*- coding: iso-8859-1 -*-
-
 """
     MoinMoin - submitemail Action
     
@@ -26,11 +25,8 @@
     def __init__(self, pagename, request):
         SubmitBase.__init__(self, pagename, request)
         
-        self.targetemail = ""
-        self.subject = "Moinmoin mail"
-        
-        if "targetemail" in request.form:
-            self.targetemail = request.form.get("targetemail")
+        self.subject = "MoinMoin mail"
+        self.targetemail = request.form.get("targetemail", "")
         
     def build_content(self):
         """ Builds simple 'label: value' string """