Source code for uw.local.print_.webui.delegate

"""Convenient URL delegators.

These are used to build up the URL structure of the application by analyzing
an URL path arc as the ID of an orgunit, job, or requisition.
"""

import re

from uw.web.wsgi.delegate import make_int_from_arc, delegate_value, always

[docs]def orgunit_from_arc (arc, cursor, **params): """Interpret a URL path arc as an orgunit. :param arc: the URL path arc. :param cursor: DB connection cursor. :param params: any additional context not needed for this arc parser. Simply checks that the arc is a potentially valid orgunit, i.e., four decimal digits, and returns it unmodified. """ match = re.match ('^([0-9]{4})$', arc) if match is None: return None return match.group (1)
[docs]def orgunit_delegate (dir_handler, arc_handler): """Delegate to URL handler based on orgunit in URL. """ return delegate_value ('orgunit', dir_handler, always (arc_handler), convert_arc=orgunit_from_arc)
[docs]def job_from_arc (arc, cursor, **params): """Interpret a URL path arc as a Job ID. :param arc: the URL path arc. :param cursor: DB connection cursor. :param params: any additional context not needed for this arc parser. Interprets the arc as a numeric Job ID, and obtains the job information. """ arc = make_int_from_arc (5) (arc) if arc is None: return None return cursor.job_by_id (job_id=arc)
[docs]def job_delegate (dir_handler, arc_handler): """Delegate to URL handler based on Job ID in URL. """ return delegate_value ('job', dir_handler, always (arc_handler), convert_arc=job_from_arc)
[docs]def requisition_from_arc (arc, cursor, **params): """Interpret a URL path arc as a Requisition ID. :param arc: the URL path arc. :param cursor: DB connection cursor. :param params: any additional context not needed for this arc parser. Interprets the arc as a Requisition ID, and obtains the requisition information. The ID is at least six decimal digits preceded by an 'R'. """ match = re.match ('^R([0-9]{6,})$', arc) if match is None: return None requisition_num = int (match.group (1)) return cursor.requisition_by_num (requisition_num=requisition_num)
[docs]def requisition_delegate (dir_handler, arc_handler): """Delegate to URL handler based on Requisition ID in URL. """ return delegate_value ('requisition', dir_handler, always (arc_handler), convert_arc=requisition_from_arc)