Source code for uw.local.teaching.webui.ta.ui

"""UI-related utility routines for TA management.

These are functions to generate fragments of HTML that are useful throughout
the TA management portion of the application.
"""

from ll.xist.ns import html

[docs]def format_units (units, label=False): """Format a number of TA units. :param units: the number of TA units, or None. :param bool label: whether or not to label the number as being units. An input of None results in returning None. Otherwise, the number is formatted; if label is True, then "unit" or "units" as appropriate is appended. """ if units is None: return None else: result = '%.2f' % units if label: result += ' unit' if units != 1: result += 's' return result
[docs]def format_actual (actual, planned, label=False): """Format an actual number of units, noting differences from plan. :param actual: the actual number of TA units currently assigned. :param planned: the planned number of TA units to assign, or None. :param bool label: whether or not to label the number as being units. Note that the actual number of units cannot be None. If the actual and planned units are the same, simply format the actual units using format_units. Otherwise, append a span indicating if the plan is missing (None), or if the actual units are over or under the planned units. """ if actual == planned: return format_units (actual, label) else: if planned is None: dif = None dir = 'no plan' else: dif = format_units (abs (actual - planned)) dir = ' over' if actual > planned else ' under' return [ format_units (actual, label), ' ', html.span (dif, dir, style="color: red;") ]
[docs]def format_entitlement (units, label=False): """Format a number of TA units which is an entitlement. :param units: the number of TA units, or None. :param bool label: whether or not to label the number as being units. If the number of units is negative, highlight it in red. Otherwise, this is no different from format_units. """ result = format_units (units, label) if units < 0: result = html.span (result, style="color: red;") return result