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

"""Application display main page implementation.

WSGI handler and routines for formatting the main application display.  For
historical reasons some parts of the application display rendering are
imported from .view_comments.
"""

from operator import attrgetter

from ll.xist.ns import html

from uw.web.html.format import make_table_format
from uw.web.html.join import html_join
from uw.web.wsgi.function import return_html
from .util import format_month_date

from .view_render import render_page

from .view_comments import render_opinion, render_comments

information_links = {
    'TOEFL': "http://www.ets.org/toefl/institutions/scores/interpret/",
    'GRE': "http://www.ets.org/gre/institutions/scores/interpret/",
}

[docs]def format_degree (degree): """Format the 'degree (specialization)' in 'Previous Instituions' section so the parentheses are not shown when specialization is not provided :param degree: one of the candidate's degrees :return: a string that shows 'degree (specialization)' if specialization is provided, otherwise shows only the degree """ if degree.degree_specialization is not None: degree_str = degree.degree_full_title + ' (' + degree.degree_specialization + ')' else: degree_str = degree.degree_full_title return degree_str
[docs]def format_test_score(component): """Format the component score in 'Test Scores' section so the parentheses are not shown when percentile is not applicable :param component: the component score associated with a test :return: a string that shows 'score (percentile)' if percentile is applicable, otherwise shows only the component score """ if component.percentile is not None: score_str = "{:.2f} ({:d} percentile)".format(component.test_score, component.percentile) else: score_str = "{:.2f}".format(component.test_score) return score_str
[docs]def render_summary (unitapp): """Render the summary of an application. :param unitapp: the candidate application. This includes conditions, citizenship, financial support, previous institutions, and test scores. """ body = [] if unitapp.adm_conditions: body.append (html.h2 ('Conditions')) body.append (make_table_format ( ('Condition', attrgetter ('condition_description')), ('Status', attrgetter ('condition_status_description')), ) (unitapp.adm_conditions)) body.append (html.h2 ('Citizenship')) table = html.table () for field, label in [ ['citizenship_code', "Status in Canada:"], ['format_countries', "Country of Citizenship:"], ]: field_value = getattr (unitapp.citizenship, field) if field_value: table.append (html.tr (html.td (label), html.td (field_value))) body.append (table) body.append (html.h2 ('Financial Support')) if unitapp.study_agreement: body.append (html.p (html.b ('Study Agreement: '), ", ".join (unitapp.study_agreement))) body.append (make_table_format ( ('Type', attrgetter ('aid_category_description')), ('Status', attrgetter ('aid_status_description')), ('Amount', lambda finance: str (finance.aid_amount) if finance.aid_amount else None) ) (unitapp.adm_finance)) body.append (html.h2 ('Previous Institutions')) table = html.table () for uw_id, res in unitapp.student_education.items (): for ins in res: table.append (html.tr (html.td (html.h3 (ins[0].ext_org_name, ' (', ins[0].country_code, ')'), title=ins[0].country_name, colspan=3))) for att in ins[1]: if att['date'].start_date or att['date'].end_date: table.append ( html.tr (html.th (format_month_date (att['date'].start_date), ' to ', format_month_date (att['date'].end_date), colspan=3)) ) table.append ( html.tr (html.th ('Degree (Specialization)'),html.th ('Degree Date'), html.th ('GPA (Type)')) ) table.append ( html.tr ( html.td (html_join ((format_degree (degree) for degree in att['degree']), html.br ())), html.td (html_join (((format_month_date (degree.degree_date), ' (', degree.degree_status_description, ')') for degree in att['degree']), html.br ())), html.td (html_join ((("{:.1f}".format(gpa.ext_gpa), ' (', gpa.ext_gpa_type_code, ')') for gpa in att['gpa']), html.br ())) ) ) body.append (table) body.append (html.h2 ('Test Scores')) for test, components in unitapp.student_tests: interpretation_link = information_links.get (test[0]) if interpretation_link is not None: interpretation_link = html.tr (html.td (html.a ('Interpretation', target="_blank", href=interpretation_link), colspan=2)) body.append ( html.table ( html.tr (html.td (html.h3 (test[0], ' ', str (test[1])), colspan=2)), [html.tr (html.td (component.test_component_code), html.td (format_test_score(component), class_="pre-display text-center")) for component in components], interpretation_link, class_="ograd-test-scores" ) ) body.append (html.div (style="clear: left")) return body
[docs]def render_main (unitapp, remote_identity, roles): """Render the body of the main application display page. :param unitapp: the candidate application. :param remote_identity: the user's remote identity. :param roles: the roles possessed by the user for this application. The page body includes "opinion"-related information, summary information, and comments. Designed to be used only with :func:`uw.local.grad.webui.view_render.render_page`. """ is_faculty = 'FAC' in roles is_admin = roles & set (('ADC', 'DIR')) return 'main', [ render_opinion (unitapp, remote_identity, is_faculty), render_summary (unitapp), render_comments (unitapp, remote_identity, is_admin), ]
@return_html def view_main_get_handler (cursor, unitapp, remote_identity, roles): """Main application display page URL handler. """ return render_page (unitapp, roles, render_main, remote_identity=remote_identity)