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

"""Application list rendering.

Routines for formatting lists of applications as HTML tables.  Provides column
definitions for use with :func:`uw.web.html.format.make_table_format`.
"""

from operator import attrgetter

from ll.xist import xsc
from ll.xist.ns import html

from uw.web.html.form import render_checkbox, render_hidden
from uw.web.html.sorttable import make_table_format_sortable, table_column
from uw.web.html.join import html_join



[docs]def attribute_rating_column (unitapp): """Compute the HTML attributes for the rating column. :param unitapp: the candidate application. :return: a dictionary of HTML attribute values. The returned attributes always include the sort value used for ordering when the column header is clicked. Additionally, a style attribute to set the background colour will be provided if the rating has a colour. """ if unitapp.rating: return { "style": "background: #%s" % unitapp.rating.rating_colour, "data-sort-value": "a%02d" % unitapp.rating.rating_sequence, } else: return { "data-sort-value": "a", }
[docs]def format_status_column (unitapp): """Compute the HTML cell contents for the status column. :param unitapp: the candidate application. :return: a fragment of HTML suitable for inclusion in a table cell. Includes the status description, how many faculty have accepted/waitlisted, and the time until/since the current workflow deadline. Actually used only for the status display on the individual application view, since the Status column has been split into two columns. """ deadline = unitapp.format_deadline () if deadline is not None: deadline = ' (%s)' % deadline reasondesc = unitapp.reasondesc app_info = unitapp.app_info warning = None if reasondesc is not None: reasondesc = " (Reason: %s (%s))" % (reasondesc, unitapp.reason_code) # if there is a mismatch between the reason for denial given to us, and the reason in the GSO database, inform the user if app_info and app_info.program_action_code == 'DENY' and app_info.program_reason_code != unitapp.reason_code: warning = html.span(' Warning: Decision reason mismatch GSO (%s) and here (%s)' % (app_info.program_reason_code, unitapp.reason_code), class_="text-danger") return [ unitapp.statusdesc, unitapp.format_accept_counts (), deadline, reasondesc, warning ]
[docs]def attribute_due_column (unitapp): """Compute the basic HTML attributes for the due column. :param unitapp: the candidate application. :return: a dictionary of HTML attribute values. The returned attributes are either a style attribute that sets the background, or none at all. The background colour is set to indicate an imminent or passed workflow deadline. Also used for the status display on the individual application view. """ result = {} diff = unitapp.find_due_days () if diff is None: colour = None elif diff <= 2: colour = 'F88' elif diff <= 5: colour = 'FF8' else: colour = None if colour is not None: result['style'] = "background: #%s" % colour return result
[docs]def attribute_due_column_sort (unitapp): """Compute the complete HTML attributes for the due column. :param unitapp: the candidate application. :return: a dictionary of HTML attribute values. The returned attributes are those provided by attribute_due_column, with an additional attribute providing the sort value used for ordering when the column header is clicked. """ result = attribute_due_column (unitapp) days = unitapp.find_due_days () if days is None: days = 499999 result['data-sort-value'] = "a%06d" % (days + 500000) return result
[docs]def attribute_state_column (unitapp): """Compute the HTML attributes for the state column. :param unitapp: the candidate application. :return: a dictionary of HTML attribute values. The returned attributes are just a data-sort-value providing the sort value used for ordering when the column header is clicked. """ result = {} if unitapp.accept_count: accept_status = 1 elif unitapp.waitlist_count: accept_status = 2 else: accept_status = 3 result['data-sort-value'] = "a%02d%d" % (unitapp.statusseq, accept_status) return result
status_codes = { 'CAN-SP': 'SP', 'PRR': 'PR', }
[docs]def format_citizenship (unitapp): """Compute the HTML cell contents for the citizenship column. :param unitapp: the candidate application. :return: a fragment of HTML suitable for inclusion in a table cell. :rtype: xsc.Frag Includes a short version of the citizenship status as well as the country code (if any). """ c = unitapp.citizenship return xsc.Frag ( html.span ( status_codes.get (c.citizenship_code, c.citizenship_description), title=c.citizenship_description, ), html.span ( ' (', c.format_countries, ')', ) if c.countries else None, )
citizenship_order = { 'CTZ': 'b', 'PRR': 'b', 'CAN-SP': 'c', }
[docs]def attribute_citizenship_column (unitapp): """Compute the HTML attributes for the citizenship column. :param unitapp: the candidate application. :return: a dictionary of HTML attribute values. The only attribute returned is the sort value used for ordering when the column header is clicked. """ c = unitapp.citizenship result = citizenship_order.get (c.citizenship_code, 'a') if result == 'c' and c.countries is not None: result += ''.join (country.country_code for country in c.countries) return {'data-sort-value': result}
# Format (Col, Name, ContentFunc, AttrFunc) application_list_columns = ( (html.col (width='10%'), 'Last Name, First Name (Preferred Name)', attrgetter ('names'), lambda x: {}), (html.col (width='11%'), 'Plan', lambda r: html_join (html.span (r.plan_code, title=r.plan_transcript_description), html.br ()), lambda x: {}), (html.col (width='9%'), 'Citizenship', format_citizenship, attribute_citizenship_column), (html.col (width='4%'), 'Gender', lambda r: r.applicant.gender_code, lambda x: {}), (html.col (width='6%'), 'Rating', lambda r: r.rating.rating_code if r.rating else None, attribute_rating_column), (html.col (width='9%'), 'State', lambda r: [r.statusdesc, r.format_accept_counts ()], attribute_state_column), (html.col (width='8%'), 'Due', lambda r: r.format_deadline (), attribute_due_column_sort), ) application_term_column = (html.col (width='6%'), 'Admit Term', lambda r: r.admit_term.description (), lambda x: {}) application_select_column = (html.col (width='5%'), 'Select', lambda r: render_checkbox ("appl_id", value=r.appl_id, class_="table-checkbox"), lambda r: {'class_': "checkbox"})
[docs]def render_sort_table (table_columns, data, fixed=False): """Render a table so that the columns can be sorted by clicking the header. :param table_columns: column specifications for passing to :func:`uw.web.html.format.make_table_format`. :param data: the data for the rows of the table. :param fixed: whether the table should include fixed col percentages Formats the table using make_table_format and then alters the table to work with the sort table JavaScript module. """ cols = [table_column (col=col if fixed else None, head=head, content=content, attr=attr) for col, head, content, attr in table_columns] table_func = make_table_format_sortable (*cols) table = table_func (data) return table