1 """
   2     MoinMoin - FrontController Macro
   3 
   4     Copyright (c) 2003 by gian paolo ciceri <gp.ciceri@acm.org>
   5     All rights reserved, see COPYING for details.
   6 
   7     This macro try to implement a FrontController Presentation Pattern
   8     (see Fowler, PEEA, pag. 344)
   9 
  10 """
  11 
  12 # Imports
  13 
  14 from MoinMoin import config, wikiutil
  15 from MoinMoin.util import pysupport
  16 import sys, re, cStringIO
  17 
  18 
  19 def execute(macro, *args, **kw):
  20     _ = macro.request.getText
  21 
  22     # command mapping dict (HTML FORM name -> inner command name)
  23     commands = {}
  24     commands['Upload'] = 'Test'
  25 
  26     # return immediately if getting links for the current page
  27     if macro.request.mode_getpagelinks:
  28         return ''
  29 
  30     # Let's the dance begin:
  31     #
  32     #
  33     # now try to get 'submit' value to know the command to be executed:
  34     # TODO: let the admin choose the 'submit' trigger value via config option
  35     #
  36     # a dummy 'submit' value means that you're at the entry point, where you've to draw
  37     # an (empty, but you can add, somewhere in the future, arguments to the macro call) form.
  38     #
  39     #
  40 
  41     # be sure we're handling with some command name
  42     try:
  43         cmdName = commands[macro.request.form['submit'].value]
  44     except:
  45         cmdName = None
  46 
  47     #now try to find the command implementation class (in MoinMoin macro, for plugins there's bug pending
  48 
  49     if cmdName is not None:
  50 
  51         cmdClass = pysupport.importName('MoinMoin.macro.command.Command' + cmdName, cmdName)
  52         if cmdClass is None:
  53             cmdClass = pysupport.importName('MoinMoin.macro.command.UnknownCommand', 'Unknown')
  54 
  55         # then create a cmd object and process it, passing forward the macro object
  56         cmdObj = cmdClass()
  57         return macro.formatter.rawHTML(cmdObj.dbc__process(macro, *args, **kw))
  58 
  59     else:
  60         # catch-all
  61         return catchAll(macro, *args, **kw)
  62 
  63 
  64 def catchAll(macro, *args, **kw):
  65     pagename = macro.formatter.page.page_name
  66     theForm = '''
  67 <form action="%s" method="POST">
  68 <table>
  69 <tr>
  70 <td>name</td>
  71 <td><input type="text" name="name" size="10" maxlength="10" value="%s" /></td>
  72 </tr>
  73 <tr>
  74 <td>email</td>
  75 <td><input type="text" name="email" size="20" maxlength="20" value="%s" /></td>
  76 </tr>
  77 <tr>
  78 <td colspan="2"><input name="submit" value="%s" type="submit" /></td>
  79 </tr>
  80 <tr>
  81 <td colspan="2"><input name="submit" value="runit" type="submit" /></td>
  82 </tr>
  83 </table>
  84 </form>
  85 '''
  86     buf = cStringIO.StringIO()
  87     buf.write(theForm % (wikiutil.quoteWikiname(pagename), 'testName', 'testMail', 'Upload'))
  88     return macro.formatter.rawHTML(buf.getvalue())

MoinMoin: macro/CommandMacro.py (last edited 2007-10-29 19:21:00 by localhost)