comparison roundup/instance.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 586f76eb33e8
children 370689471a08
comparison
equal deleted inserted replaced
8261:28c5030757d3 8262:2a7c3eeaf167
245 self.cgi_actions[name] = action 245 self.cgi_actions[name] = action
246 else: 246 else:
247 self.cgi_actions[name] = action 247 self.cgi_actions[name] = action
248 248
249 def registerUtil(self, name, function): 249 def registerUtil(self, name, function):
250 """Register a function that can be called using:
251 `utils.<name>(...)`.
252
253 The function is defined as:
254
255 def function(...):
256
257 If you need access to the client, database, form or other
258 item, you have to pass it explicitly::
259
260 utils.name(request.client, ...)
261
262 If you need client access, consider using registerUtilMethod()
263 instead.
264
265 """
250 self.templating_utils[name] = function 266 self.templating_utils[name] = function
251 267
268 def registerUtilMethod(self, name, function):
269 """Register a method that can be called using:
270 `utils.<name>(...)`.
271
272 Unlike registerUtil, the method is defined as:
273
274 def function(self, ...):
275
276 `self` is a TemplatingUtils object. You can use self.client
277 to access the client object for your request.
278 """
279 setattr(self.TemplatingUtils,
280 name,
281 function)
252 282
253 class TrackerError(RoundupException): 283 class TrackerError(RoundupException):
254 pass 284 pass
255 285
256 286

Roundup Issue Tracker: http://roundup-tracker.org/