"""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 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)