Skip to content

Commit 3599540

Browse files
author
Richard Jones
committed
making it easier to add new actions, and more docco
1 parent dd3a1bc commit 3599540

File tree

3 files changed

+39
-17
lines changed

3 files changed

+39
-17
lines changed

doc/customizing.txt

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Customising Roundup
33
===================
44

5-
:Version: $Revision: 1.39 $
5+
:Version: $Revision: 1.40 $
66

77
.. This document borrows from the ZopeBook section on ZPT. The original is at:
88
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
18721872
the "Fixer" Permission, the error will be raised.
18731873

18741874

1875+
Setting up a "wizard" (or "druid") for controlled adding of issues
1876+
------------------------------------------------------------------
1877+
1878+
1. set up the page templates you wish to use for data input
1879+
2. determine what actions need to be taken between the pages - these are
1880+
usually to validate user choices and determine what page is next
1881+
3. encode those actions in methods on the interfaces Client class and insert
1882+
hooks to those actions in the "actions" attribute on that class, like so::
1883+
1884+
actions = client.Class.actions + (
1885+
('page1_submit', page1SubmitAction),
1886+
...
1887+
)
1888+
1889+
def page1SubmitAction(self):
1890+
# do the page 1 submit stuff, redirecting the user to the appropriate
1891+
# next page if necessary
1892+
1893+
18751894
-------------------
18761895

18771896
Back to `Table of Contents`_

roundup/cgi/client.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.33 2002-09-15 22:41:15 richard Exp $
1+
# $Id: client.py,v 1.34 2002-09-16 05:32:09 richard Exp $
22

33
__doc__ = """
44
WWW request handler (also used in the stand-alone server).
@@ -344,8 +344,8 @@ def renderTemplate(self, name, extension, **kwargs):
344344
# let the template render figure stuff out
345345
return pt.render(self, None, None, **kwargs)
346346
except PageTemplate.PTRuntimeError, message:
347-
return '<strong>%s</strong><ol>%s</ol>'%(message,
348-
'<li>'.join(pt._v_errors))
347+
return '<strong>%s</strong><ol><li>%s</ol>'%(message,
348+
'<li>'.join([cgi.escape(x) for x in pt._v_errors]))
349349
except NoTemplate, message:
350350
return '<strong>%s</strong>'%message
351351
except:
@@ -369,21 +369,21 @@ def content(self):
369369
return self.renderTemplate(self.classname, self.template)
370370

371371
# these are the actions that are available
372-
actions = {
373-
'edit': 'editItemAction',
374-
'editCSV': 'editCSVAction',
375-
'new': 'newItemAction',
376-
'register': 'registerAction',
377-
'login': 'loginAction',
378-
'logout': 'logout_action',
379-
'search': 'searchAction',
380-
}
372+
actions = (
373+
('edit', 'editItemAction'),
374+
('editCSV', 'editCSVAction'),
375+
('new', 'newItemAction'),
376+
('register', 'registerAction'),
377+
('login', 'loginAction'),
378+
('logout', 'logout_action'),
379+
('search', 'searchAction'),
380+
)
381381
def handle_action(self):
382382
''' Determine whether there should be an _action called.
383383
384384
The action is defined by the form variable :action which
385385
identifies the method on this object to call. The four basic
386-
actions are defined in the "actions" dictionary on this class:
386+
actions are defined in the "actions" sequence on this class:
387387
"edit" -> self.editItemAction
388388
"new" -> self.newItemAction
389389
"register" -> self.registerAction
@@ -397,11 +397,14 @@ def handle_action(self):
397397
try:
398398
# get the action, validate it
399399
action = self.form[':action'].value
400-
if not self.actions.has_key(action):
400+
for name, method in selc.actions:
401+
if name == action:
402+
break
403+
else:
401404
raise ValueError, 'No such action "%s"'%action
402405

403406
# call the mapped action
404-
getattr(self, self.actions[action])()
407+
getattr(self, method)()
405408
except Redirect:
406409
raise
407410
except Unauthorised:

roundup/cgi/templating.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def render(self, client, classname, request, **options):
173173

174174
if self._v_errors:
175175
raise PageTemplate.PTRuntimeError, \
176-
'Page Template %s has errors.' % self.id
176+
'Page Template %s has errors.'%self.id
177177

178178
# figure the context
179179
classname = classname or client.classname

0 commit comments

Comments
 (0)