Source code for uw.local.teaching.webui.term

"""Term-related UI pages.

This includes the overall list of course offerings, as well as the per-term
list of offerings.  These both depend on the logged-in user.
"""

from operator import attrgetter
from itertools import groupby

from ll.xist.ns import html

from uw.web.html.format import format_return
from uw.web.html.join import html_join
from uw.web.wsgi.delegate import *
from uw.web.wsgi.function import return_html

from uw.local import termtools

from ...util.identity import use_remote_identity

[docs]def format_offerings (admin_units, base_url=""): """Format a list of offerings as an HTML <ul> grouped by term. :param admin_units: iterable of offerings to format :param base_url: the base URL for links to the offerings :return: an HTML <ul> with one <li> per term. Each term's list item includes the term description followed by links to the per-offering pages for the provided offerings (parameter admin_units) :rtype: HTML unordered list <ul> **TODO: admin_units should probably be called offerings.** """ result = html.ul () for term, admins in groupby (admin_units, attrgetter ("term_id")): result.append (html.li (termtools.fromCode (term).description (), ': ', format_term_offerings (admins, base_url="%s%s/" % (base_url, term)))) return result
[docs]def format_term_offerings (admin_units, base_url=""): """Format a list of offerings within a term as HTML. :param admin_units: iterable of offerings to format :param base_url: the base URL for links to the offerings :return: HTML <a> links separated by spaces, one for each provided offering :rtype: xsc.frag """ return html_join ((html.a (a.admin_description, href="%s%s/" % (base_url, a.admin_id)) for a in admin_units), sep=' ')
@delegate_get_post @use_remote_identity @return_html def term_index (cursor, remote_identity): """Staff term list URL handler. :param cursor: DB connection cursor :return: tuple of (description, HTML elements for list of terms) :rtype: (str, list) Handles requests for the list of terms. Displays a list of all offerings relevant to the user, grouped by term and linked to the individual offering pages. """ result = [format_return ('Main Menu')] admin_units = cursor.offerings_by_person (person_id=remote_identity.person_id) result.append (format_offerings (admin_units)) return 'My Offerings', result @delegate_get_post @use_remote_identity @return_html def term_handler (cursor, remote_identity, term): """Staff term information URL handler. :param cursor: DB connection cursor :param term: the relevant term :return: tuple of (description, offerings) :rtype: (str, list) Handles requests for the per-term summary page. Displays a list of all offerings in the term relevant to the user, linked to the individual offering pages. """ result = [format_return ('Main Menu', 'My Offerings')] admin_units = cursor.offerings_by_person_term (person_id=remote_identity.person_id, term_id=term.code ()) result.append (html.p (format_term_offerings (admin_units))) return 'Your %s Offerings' % term.description (), result