Skip to content

Commit ab089ae

Browse files
author
Richard Jones
committed
more wizard example
1 parent 01e3f5b commit ab089ae

File tree

1 file changed

+66
-9
lines changed

1 file changed

+66
-9
lines changed

doc/customizing.txt

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Customising Roundup
33
===================
44

5-
:Version: $Revision: 1.40 $
5+
:Version: $Revision: 1.41 $
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
@@ -1875,21 +1875,78 @@ the "Fixer" Permission, the error will be raised.
18751875
Setting up a "wizard" (or "druid") for controlled adding of issues
18761876
------------------------------------------------------------------
18771877

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
1878+
1. Set up the page templates you wish to use for data input. My wizard
1879+
is going to be a two-step process, first figuring out what category of
1880+
issue the user is submitting, and then getting details specific to that
1881+
category. The first page includes a table of help, explaining what the
1882+
category names mean, and then the core of the form::
1883+
1884+
<form method="POST" onSubmit="return submit_once()"
1885+
enctype="multipart/form-data">
1886+
<input type="hidden" name=":template" value="add_page1">
1887+
<input type="hidden" name=":action" value="page1submit">
1888+
1889+
<strong>Category:</strong>
1890+
<span tal:replace="structure context/category/menu" />
1891+
<input type="submit" value="Continue">
1892+
</form>
1893+
1894+
The next page has the usual issue entry information, with the addition of
1895+
the following form fragments::
1896+
1897+
1898+
<form method="POST" onSubmit="return submit_once()"
1899+
enctype="multipart/form-data" tal:condition="context/is_edit_ok"
1900+
tal:define="cat request/form/category/value">
1901+
1902+
<input type="hidden" name=":template" value="add_page2">
1903+
<input type="hidden" name=":required" value="title">
1904+
<input type="hidden" name="category" tal:attributes="value cat">
1905+
1906+
.
1907+
.
1908+
.
1909+
</form>
1910+
1911+
Note that later in the form, I test the value of "cat" include form
1912+
elements that are appropriate. For example::
1913+
1914+
<tal:block tal:condition="python:cat in '6 10 13 14 15 16 17'.split()">
1915+
<tr>
1916+
<th nowrap>Operating System</th>
1917+
<td tal:content="structure context/os/field"></td>
1918+
</tr>
1919+
<tr>
1920+
<th nowrap>Web Browser</th>
1921+
<td tal:content="structure context/browser/field"></td>
1922+
</tr>
1923+
</tal:block>
1924+
1925+
... the above section will only be displayed if the category is one of 6,
1926+
10, 13, 14, 15, 16 or 17.
1927+
1928+
3. Determine what actions need to be taken between the pages - these are
1929+
usually to validate user choices and determine what page is next. Now
1930+
encode those actions in methods on the interfaces Client class and insert
18821931
hooks to those actions in the "actions" attribute on that class, like so::
18831932

18841933
actions = client.Class.actions + (
18851934
('page1_submit', page1SubmitAction),
1886-
...
18871935
)
18881936

18891937
def page1SubmitAction(self):
1890-
# do the page 1 submit stuff, redirecting the user to the appropriate
1891-
# next page if necessary
1892-
1938+
''' Verify that the user has selected a category, and then move on
1939+
to page 2.
1940+
'''
1941+
category = self.form['category'].value
1942+
if category == '-1':
1943+
self.error_message.append('You must select a category of report')
1944+
return
1945+
# everything's ok, move on to the next page
1946+
self.template = 'add_page2'
1947+
1948+
4. Use the usual "edit" action as the :action on the final page, and you're
1949+
done (the standard context/submit method can do this for you).
18931950

18941951
-------------------
18951952

0 commit comments

Comments
 (0)