|
2 | 2 | Customising Roundup |
3 | 3 | =================== |
4 | 4 |
|
5 | | -:Version: $Revision: 1.40 $ |
| 5 | +:Version: $Revision: 1.41 $ |
6 | 6 |
|
7 | 7 | .. This document borrows from the ZopeBook section on ZPT. The original is at: |
8 | 8 | http://www.zope.org/Documentation/Books/ZopeBook/current/ZPT.stx |
@@ -1875,21 +1875,78 @@ the "Fixer" Permission, the error will be raised. |
1875 | 1875 | Setting up a "wizard" (or "druid") for controlled adding of issues |
1876 | 1876 | ------------------------------------------------------------------ |
1877 | 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 |
| 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 |
1882 | 1931 | hooks to those actions in the "actions" attribute on that class, like so:: |
1883 | 1932 |
|
1884 | 1933 | actions = client.Class.actions + ( |
1885 | 1934 | ('page1_submit', page1SubmitAction), |
1886 | | - ... |
1887 | 1935 | ) |
1888 | 1936 |
|
1889 | 1937 | 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). |
1893 | 1950 |
|
1894 | 1951 | ------------------- |
1895 | 1952 |
|
|
0 commit comments