22Customising Roundup
33===================
44
5- :Version: $Revision: 1.113 $
5+ :Version: $Revision: 1.114 $
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
@@ -2077,54 +2077,54 @@ templating through the "journal" method of the item*::
20772077Defining new web actions
20782078------------------------
20792079
2080- You may define new actions to be triggered by the ``@action`` form
2081- variable. These are added to the tracker ``interfaces.py`` as methods on
2082- the ``Client`` class.
2080+ You may define new actions to be triggered by the ``@action`` form variable.
2081+ These are added to the tracker ``interfaces.py`` as ``Action`` classes that get
2082+ called by the the ``Client`` class.
20832083
2084- Adding action methods takes three steps; first you `define the new
2085- action method `_, then you `register the action method `_ with the cgi
2084+ Adding action classes takes three steps; first you `define the new
2085+ action class `_, then you `register the action class `_ with the cgi
20862086interface so it may be triggered by the ``@action`` form variable.
20872087Finally you `use the new action`_ in your HTML form.
20882088
20892089See "`setting up a "wizard" (or "druid") for controlled adding of
20902090issues`_" for an example.
20912091
20922092
2093- Define the new action method
2093+ Define the new action class
20942094~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20952095
2096- The action methods have the following interface::
2096+ The action classes have the following interface::
20972097
2098- def myActionMethod(self):
2099- ''' Perform some action. No return value is required.
2100- '''
2098+ class MyAction(Action):
2099+ def handle(self):
2100+ ''' Perform some action. No return value is required.
2101+ '''
21012102
2102- The *self* argument is an instance of your tracker ``instance.Client``
2103+ The *self.client* attribute is an instance of your tracker ``instance.Client``
21032104class - thus it's mostly implemented by ``roundup.cgi.Client``. See the
21042105docstring of that class for details of what it can do.
21052106
21062107The method will typically check the ``self.form`` variable's contents.
21072108It may then:
21082109
2109- - add information to ``self.ok_message`` or ``self.error_message``
2110- - change the ``self.template`` variable to alter what the user will see
2110+ - add information to ``self.client. ok_message`` or ``self.client .error_message``
2111+ - change the ``self.client. template`` variable to alter what the user will see
21112112 next
21122113- raise Unauthorised, SendStaticFile, SendFile, NotFound or Redirect
2113- exceptions
2114+ exceptions (import them from roundup.cgi.exceptions)
21142115
21152116
2116- Register the action method
2117+ Register the action class
21172118~~~~~~~~~~~~~~~~~~~~~~~~~~
21182119
2119- The method is now written, but isn't available to the user until you add
2120- it to the `instance.Client`` class ``actions`` variable, like so::
2120+ The class is now written, but isn't available to the user until you add it to
2121+ the ` `instance.Client`` class ``actions`` variable, like so::
21212122
2122- actions = client.Class .actions + (
2123- ('myaction', 'myActionMethod' ),
2123+ actions = client.Client .actions + (
2124+ ('myaction', myActionClass ),
21242125 )
21252126
2126- This maps the action name "myaction" to the action method we defined.
2127-
2127+ This maps the action name "myaction" to the action class we defined.
21282128
21292129Use the new action
21302130~~~~~~~~~~~~~~~~~~
@@ -2748,7 +2748,7 @@ Setting up a "wizard" (or "druid") for controlled adding of issues
27482748 <form method="POST" onSubmit="return submit_once()"
27492749 enctype="multipart/form-data">
27502750 <input type="hidden" name="@template" value="add_page1">
2751- <input type="hidden" name="@action" value="page1submit ">
2751+ <input type="hidden" name="@action" value="page1_submit ">
27522752
27532753 <strong>Category:</strong>
27542754 <tal:block tal:replace="structure context/category/menu" />
@@ -2772,7 +2772,7 @@ Setting up a "wizard" (or "druid") for controlled adding of issues
27722772 </form>
27732773
27742774 Note that later in the form, I test the value of "cat" include form
2775- elements that are appropriate. For example ::
2775+ elements that are appropriate. For exsample ::
27762776
27772777 <tal:block tal:condition="python:cat in '6 10 13 14 15 16 17'.split()">
27782778 <tr>
@@ -2789,26 +2789,27 @@ Setting up a "wizard" (or "druid") for controlled adding of issues
27892789 of 6, 10, 13, 14, 15, 16 or 17.
27902790
279127913. Determine what actions need to be taken between the pages - these are
2792- usually to validate user choices and determine what page is next. Now
2793- encode those actions in methods on the ``interfaces.Client`` class
2794- and insert hooks to those actions in the "actions" attribute on that
2795- class, like so::
2792+ usually to validate user choices and determine what page is next. Now encode
2793+ those actions in a new ``Action`` class and insert hooks to those actions in
2794+ the "actions" attribute on on the ``interfaces.Client`` class, like so (see
2795+ `defining new web actions`_)::
2796+
2797+ class Page1SubmitAction(Action):
2798+ def handle(self):
2799+ ''' Verify that the user has selected a category, and then move
2800+ on to page 2.
2801+ '''
2802+ category = self.form['category'].value
2803+ if category == '-1':
2804+ self.error_message.append('You must select a category of report')
2805+ return
2806+ # everything's ok, move on to the next page
2807+ self.template = 'add_page2'
27962808
27972809 actions = client.Client.actions + (
2798- ('page1_submit', 'page1SubmitAction' ),
2810+ ('page1_submit', Page1SubmitAction ),
27992811 )
28002812
2801- def page1SubmitAction(self):
2802- ''' Verify that the user has selected a category, and then move
2803- on to page 2.
2804- '''
2805- category = self.form['category'].value
2806- if category == '-1':
2807- self.error_message.append('You must select a category of report')
2808- return
2809- # everything's ok, move on to the next page
2810- self.template = 'add_page2'
2811-
281228134. Use the usual "new" action as the ``@action`` on the final page, and
28132814 you're done (the standard context/submit method can do this for you).
28142815
0 commit comments