Source code for uw.local.quest.webui.format

"""Convenient quest formatting routines.
"""

from ll.xist.ns import html

from uw.local import termtools

from uw.web.html.join import html_join


[docs]def format_instructor (instructor, base_url=""): """Format an instructor's identity as HTML. :param instructor: the relevant instructor. :param base_url: the base URL for the link to instructor page. :return: the instructor's name linking to their summary page. """ return html.a (instructor.surname, ', ', instructor.givennames, href="%sinstructor/%s/" % (base_url, instructor.userid))
[docs]def format_instructor_list (instructor_list, base_url=""): """Format the instructor list on /quest/{user_id}/instructor. :param instructor_list: a list of all the instructors. :return: all the instructors names as paragraph elements linked to their summary page. """ return (html.p (format_instructor(inst, base_url)) for inst in instructor_list)
[docs]def format_subject (subject, base_url=""): """Format a subject as HTML. :param subject: the relevant subject. :param base_url: the base URL for the link to subject page. :return: the subject code and subject short description linking to the subject list page. """ return html.p (html.a (subject.subject_code + ' — ' + subject.subject_short_description, href="%ssubject/%s/" % (base_url, subject.subject_code)))
[docs]def format_term (term, base_url=""): """Format a term as HTML. :param term: the relevant term. :param base_url: the base URL for the link to term page. :return: the term description linking to the term list page. """ return html.p (html.a (termtools.fromCode(term).description (), href="%s%s/" % (base_url, term)))
[docs]def format_courses (cursor, courses, subject=None, term=None, base_url=''): """Formats course information to tables :param cursor: DB connection cursor. :param courses: list of relevant courses. :param subject: the relevant subject. :return: a table of the course information details. """ if courses is None: return "No courses are available." result = html.tr ([ html.th ('Course'), html.th ('Units'), html.th ('Title'), html.th ('Description'), html.th ('Requisites') ]) for course in courses: description = html_join (course.course_description.replace (' [', '\n[').split ('\n'), html.br ()) if course.course_description else None requisite = cursor.requisite_by_id (requisite_id=course.requisite_id) result.append (html.tr ( html.td (html.a (course.title, href="%scatalog/%s" % (base_url, course.catalog))), html.td (str (course.course_take_units)), html.td (course.course_title), html.td (description), html.td (requisite), )) return html.table (result)