From 7425e946ef03a8d6e916ce9903b6a8135649e339 Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 16 Sep 2002 05:32:09 +0000 Subject: [PATCH] making it easier to add new actions, and more docco git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1175 57a73879-2fb5-44c3-a270-3262357dd7e2 --- doc/customizing.txt | 21 ++++++++++++++++++++- roundup/cgi/client.py | 33 ++++++++++++++++++--------------- roundup/cgi/templating.py | 2 +- 3 files changed, 39 insertions(+), 17 deletions(-) diff --git a/doc/customizing.txt b/doc/customizing.txt index 05958a8..7e05252 100644 --- a/doc/customizing.txt +++ b/doc/customizing.txt @@ -2,7 +2,7 @@ Customising Roundup =================== -:Version: $Revision: 1.39 $ +:Version: $Revision: 1.40 $ .. This document borrows from the ZopeBook section on ZPT. The original is at: http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx @@ -1872,6 +1872,25 @@ So now, if the edit attempts to set the assignedto to a user that doesn't have the "Fixer" Permission, the error will be raised. +Setting up a "wizard" (or "druid") for controlled adding of issues +------------------------------------------------------------------ + +1. set up the page templates you wish to use for data input +2. determine what actions need to be taken between the pages - these are + usually to validate user choices and determine what page is next +3. encode those actions in methods on the interfaces Client class and insert + hooks to those actions in the "actions" attribute on that class, like so:: + + actions = client.Class.actions + ( + ('page1_submit', page1SubmitAction), + ... + ) + + def page1SubmitAction(self): + # do the page 1 submit stuff, redirecting the user to the appropriate + # next page if necessary + + ------------------- Back to `Table of Contents`_ diff --git a/roundup/cgi/client.py b/roundup/cgi/client.py index 9bb6ab5..8c8313d 100644 --- a/roundup/cgi/client.py +++ b/roundup/cgi/client.py @@ -1,4 +1,4 @@ -# $Id: client.py,v 1.33 2002-09-15 22:41:15 richard Exp $ +# $Id: client.py,v 1.34 2002-09-16 05:32:09 richard Exp $ __doc__ = """ WWW request handler (also used in the stand-alone server). @@ -344,8 +344,8 @@ class Client: # let the template render figure stuff out return pt.render(self, None, None, **kwargs) except PageTemplate.PTRuntimeError, message: - return '%s
    %s
'%(message, - '
  • '.join(pt._v_errors)) + return '%s
    1. %s
    '%(message, + '
  • '.join([cgi.escape(x) for x in pt._v_errors])) except NoTemplate, message: return '%s'%message except: @@ -369,21 +369,21 @@ class Client: return self.renderTemplate(self.classname, self.template) # these are the actions that are available - actions = { - 'edit': 'editItemAction', - 'editCSV': 'editCSVAction', - 'new': 'newItemAction', - 'register': 'registerAction', - 'login': 'loginAction', - 'logout': 'logout_action', - 'search': 'searchAction', - } + actions = ( + ('edit', 'editItemAction'), + ('editCSV', 'editCSVAction'), + ('new', 'newItemAction'), + ('register', 'registerAction'), + ('login', 'loginAction'), + ('logout', 'logout_action'), + ('search', 'searchAction'), + ) def handle_action(self): ''' Determine whether there should be an _action called. The action is defined by the form variable :action which identifies the method on this object to call. The four basic - actions are defined in the "actions" dictionary on this class: + actions are defined in the "actions" sequence on this class: "edit" -> self.editItemAction "new" -> self.newItemAction "register" -> self.registerAction @@ -397,11 +397,14 @@ class Client: try: # get the action, validate it action = self.form[':action'].value - if not self.actions.has_key(action): + for name, method in selc.actions: + if name == action: + break + else: raise ValueError, 'No such action "%s"'%action # call the mapped action - getattr(self, self.actions[action])() + getattr(self, method)() except Redirect: raise except Unauthorised: diff --git a/roundup/cgi/templating.py b/roundup/cgi/templating.py index baa60c3..a42ae90 100644 --- a/roundup/cgi/templating.py +++ b/roundup/cgi/templating.py @@ -173,7 +173,7 @@ class RoundupPageTemplate(PageTemplate.PageTemplate): if self._v_errors: raise PageTemplate.PTRuntimeError, \ - 'Page Template %s has errors.' % self.id + 'Page Template %s has errors.'%self.id # figure the context classname = classname or client.classname -- 2.30.2