Mercurial > p > roundup > code
diff roundup/cgi/client.py @ 5185:349bef975367
Make @template support two alternate templates for error and ok cases.
Setting @template=oktmpl|errortmpl in a form will display the next
page using the oktmpl if the change did not cause an error. If
submitting the form caused an error (raised by an auditor or something
else), the user is displayed a page using the errortmpl. Docs in
customizing.tmpl. Look for modal edit.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Fri, 17 Feb 2017 19:44:15 -0500 |
| parents | 232c74973a56 |
| children | 8768a95c9a4f |
line wrap: on
line diff
--- a/roundup/cgi/client.py Fri Feb 17 19:33:01 2017 -0500 +++ b/roundup/cgi/client.py Fri Feb 17 19:44:15 2017 -0500 @@ -1163,6 +1163,13 @@ classname (name parameter) and template request variable (view parameter) and return its name. + View can be a single template or two templates separated + by a vbar '|' character. If the Client object has a + non-empty _error_message attribute, the right hand + template (error template) will be used. If the + _error_message is empty, the left hand template (ok + template) will be used. + In most cases the name will be "classname.view", but if "view" is None, then template name "classname" will be returned. @@ -1172,6 +1179,20 @@ [ ] cover with tests """ + + # determine if view is oktmpl|errortmpl. If so assign the + # right one to the view parameter. If we don't have alternate + # templates, just leave view alone. + if (view.find('|') != -1 ): + # we have alternate templates, parse them apart. + (oktmpl, errortmpl) = view.split("|", 2) + if self._error_message: + # we have an error, use errortmpl + view = errortmpl + else: + # no error message recorded, use oktmpl + view = oktmpl + loader = self.instance.templates # if classname is not set, use "home" template
