changeset 623:088282ae5cf3

move twikidraw saving stuff from request to AttachFile, ok for CGI, needs tests for Twisted and WSGI
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 07 May 2006 18:04:51 +0200
parents 8fba6d15a2f5
children dcb874ba84ba
files MoinMoin/action/AttachFile.py MoinMoin/request.py
diffstat 2 files changed, 27 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/AttachFile.py	Sat May 06 00:09:06 2006 +0200
+++ b/MoinMoin/action/AttachFile.py	Sun May 07 18:04:51 2006 +0200
@@ -348,7 +348,10 @@
     querystr = wikiutil.escape(wikiutil.makeQueryString(querystr))
     pagelink = '%s/%s?%s' % (request.getScriptname(), wikiutil.quoteWikinameURL(pagename), querystr)
     helplink = Page(request, "HelpOnActions/AttachFile").url(request)
-    savelink = Page(request, pagename).url(request) # XXX include target filename param here for twisted
+    querystr = {'action': 'AttachFile', 'do': 'savedrawing'}
+    querystr = wikiutil.escape(wikiutil.makeQueryString(querystr))
+    savelink = '%s/%s?%s' % (request.getScriptname(), wikiutil.quoteWikinameURL(pagename), querystr)
+    #savelink = Page(request, pagename).url(request) # XXX include target filename param here for twisted
                                            # request, {'savename': request.form['drawing'][0]+'.draw'}
     #savelink = '/cgi-bin/dumpform.bat'
 
@@ -445,15 +448,15 @@
     msg = None
     if action_name in request.cfg.actions_excluded:
         msg = _('File attachments are not allowed in this wiki!')
-    elif request.form.has_key('filepath'):
+    elif not request.form.has_key('do'):
+        upload_form(pagename, request)
+    elif request.form['do'][0] == 'savedrawing':
         if request.user.may.write(pagename):
             save_drawing(pagename, request)
             request.http_headers()
             request.write("OK")
         else:
             msg = _('You are not allowed to save a drawing on this page.')
-    elif not request.form.has_key('do'):
-        upload_form(pagename, request)
     elif request.form['do'][0] == 'upload':
         if request.user.may.write(pagename):
             if request.form.has_key('file'):
@@ -495,7 +498,6 @@
     if msg:
         error_msg(pagename, request, msg)
 
-
 def upload_form(pagename, request, msg=''):
     _ = request.getText
 
--- a/MoinMoin/request.py	Sat May 06 00:09:06 2006 +0200
+++ b/MoinMoin/request.py	Sun May 07 18:04:51 2006 +0200
@@ -892,19 +892,24 @@
 
     def setup_args(self, form=None):
         """ Return args dict 
-        
-        In POST request, invoke _setup_args_from_cgi_form to handle possible
-        file uploads. For other request simply parse the query string.
+        First, we parse the query string (usually this is used in GET methods,
+        but TwikiDraw uses ?action=AttachFile&do=savedrawing plus posted stuff).
+        Second, we update what we got in first step by the stuff we get from
+        the form (or by a POST). We invoke _setup_args_from_cgi_form to handle
+        possible file uploads.
         
         Warning: calling with a form might fail, depending on the type of the
-        request! Only the request know which kind of form it can handle.
+        request! Only the request knows which kind of form it can handle.
         
         TODO: The form argument should be removed in 1.5.
         """
+        args = cgi.parse_qs(self.query_string, keep_blank_values=1)
+        args = self.decodeArgs(args)
+        # if we have form data (e.g. in a POST), those override the stuff we already have:
         if form is not None or self.request_method == 'POST':
-            return self._setup_args_from_cgi_form(form)
-        args = cgi.parse_qs(self.query_string, keep_blank_values=1)
-        return self.decodeArgs(args)
+            postargs = self._setup_args_from_cgi_form(form)
+            args.update(postargs)
+        return args
 
     def _setup_args_from_cgi_form(self, form=None):
         """ Return args dict from a FieldStorage
@@ -1076,14 +1081,7 @@
                 self.http_redirect(url)
                 return self.finish()
             
-            # 3. Or save drawing
-            elif self.form.has_key('filepath') and self.form.has_key('noredirect'):
-                # looks like user wants to save a drawing
-                from MoinMoin.action.AttachFile import execute
-                # TODO: what if pagename is None?
-                execute(pagename, self)
-
-            # 4. Or handle action
+            # 3. Or handle action
             else:
                 if action is None:
                     action = 'show'
@@ -1438,8 +1436,10 @@
         """ Return args dict 
         
         Twisted already parsed args, including __filename__ hacking,
-        but did not decoded the values.
+        but did not decode the values.
         """
+        # TODO: check if for a POST this included query_string args (needed for
+        # TwikiDraw's action=AttachFile&do=savedrawing)
         return self.decodeArgs(self.twistd.args)
         
     def read(self, n=None):
@@ -1643,7 +1643,7 @@
             self.fail(err)
 
     def _setup_args_from_cgi_form(self, form=None):
-        """ Override to create standlone form """
+        """ Override to create standalone form """
         form = cgi.FieldStorage(self.rfile, headers=self.headers, environ={'REQUEST_METHOD': 'POST'})
         return RequestBase._setup_args_from_cgi_form(self, form)
         
@@ -1988,11 +1988,13 @@
             
             self._setup_vars_from_std_env(env)
             RequestBase.__init__(self, {})
-        
+
         except Exception, err:
             self.fail(err)
     
     def setup_args(self, form=None):
+        # TODO: does this include query_string args for POST requests?
+        # see also how CGI works now
         if form is None:
             form = cgi.FieldStorage(fp=self.stdin, environ=self.env, keep_blank_values=1)
         return self._setup_args_from_cgi_form(form)