Source code for uw.local.grad.webui.util

"""Miscellaneous utility routines.

These are routines used in various places within Graduate Admissions that are
not general enough to warrant a place in the general library.
"""

from datetime import datetime
import re

from ll.xist.ns import html

from uw.web.html.format import format_return
from uw.web.html.join import html_join

from uw.emailutils import emailaddr
from uw.local import termtools

[docs]def format_month_date (d): """Print a date as a year and month. None and datetime.max are converted into empty strings. Other dates are printed as YYYY-MM. """ if d is None: return "" elif d == datetime.max: return "" else: return d.strftime ("%Y-%m")
address_fields = ('address1', 'address2', 'address3', 'address4', 'city', 'prov', 'postal', 'country', 'phone') address_re = re.compile (r'\(' + ','.join ([r'([^,]*|\"[^"]*\")'] * len (address_fields)) + r'\)')
[docs]def get_email_address (cursor, person_id): """Look up a person's email address, given their Person ID. :param cursor: DB connection cursor. :param person_id: the identity of the person. :return: the email address in the form userid@uwaterloo.ca. """ # TODO: Shouldn't this go to userid@uwaterloo.ca? # But not if no email address is set! result = cursor.execute_optional_tuple ("SELECT * from person_identity_complete where person_id = %(person_id)s", person_id=person_id) if result is None: return None return emailaddr (result.givennames + ' ' + result.surname, result.userid + '@uwaterloo.ca')
[docs]def render_frontpage_header (basis, base_prefix=""): """Render the role front page header information. :param basis: a brief explanation of how applications are selected to be displayed on the front page. :param base_prefix: the relative URL of the role frontpage. """ return [ html.p ( 'Notifications of various events will be sent out by email. You may ', html.a ('edit your notification preferences', href=base_prefix + "../notice"), '.' ), html.p ( 'This page shows applications that may be relevant to you based on ', basis, '. To find a specific application, use the ', html.a ('search page', href=base_prefix + "../view/"), '. To see all the applications for a term, use the ', html.a ('application list', href=base_prefix + "../list/"), ' page.' ), ]