Mercurial > p > roundup > code
diff roundup/cgi/templating.py @ 8262:2a7c3eeaf167
feat: add templating utils method dynamically; method to set http code
Added new utils.set_http_response(integer) to set the HTML response
code from a template. Useful for error handling inside template.
Also noted that a real TemplatingUtils (like set_http_response) method
gets the TemplatingUtils object instance, but there is no way to do
this with registerUtil() from an extension file.
Added new instance.registerUtilMethod() method to register a function
in an extension as a method passing the client instance in as the first
parameter (aka self).
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Tue, 07 Jan 2025 20:22:33 -0500 |
| parents | f7bd22bdef9d |
| children | 669dfccca898 |
line wrap: on
line diff
--- a/roundup/cgi/templating.py Sun Jan 05 00:59:12 2025 -0500 +++ b/roundup/cgi/templating.py Tue Jan 07 20:22:33 2025 -0500 @@ -3799,6 +3799,18 @@ {'fullpath': fullpath, 'issue': e.args[0]}) return "" + def set_http_response(self, code): + '''Set the HTTP response code to the integer `code`. + Example:: + + <tal:x + tal:replace="python:utils.set_response(404);" + /> + + + will make the template return code 404 (not found). + ''' + self.client.response_code = code class MissingValue(object): def __init__(self, description, **kwargs):
