"""Overall application display rendering.
Routines for formatting an application display. The overall page, including
the application header, is formatting by functions in this module. The
portions of the display which differ from page to page are handled by other
view_* modules, as are the actual WSGI handlers for the various pages of an
application.
"""
from datetime import datetime, date, timedelta
from ll.xist.ns import html
from uw.web.html.form import render_hidden
from uw.web.html.bootstrapform import render_bootstrap_upload_submit, render_copy_button, render_bootstrap_submit
from uw.web.html.format import format_date, format_datetime, make_table_format
from uw.local import termtools
from ...util.format import format_person
from ..db.status import render_state_change_usual_form
from ..db.unitapp import UnitApplication, attendance, levels
from .list_render import format_status_column, attribute_due_column
unit_roles = set (['ADC', 'DIR', 'FAC'])
grad_roles = set (['ADC', 'DIR'])
subpages = (
(('main', "Main"), unit_roles),
(('contact', "Contact"), unit_roles),
(('offer', "Offers"), grad_roles),
(('history', "History"), grad_roles),
(('edit', "Edit"), grad_roles),
)
[docs]def get_active_subpages (subpages, roles):
"""Determine which of the specified subpages are active for the roles.
:param list subpages: the eligible subpages.
:param set roles: the set of active role codes.
:return: the subpages which are visible to the active roles, i.e., those
whose associated roles intersect the active roles.
Each subpage is represented as a tuple of (subpage, roles) where the
subpage describes the subpage and the roles are a set of role codes.
"""
result = []
for subpage, page_roles in subpages:
if page_roles & roles:
result.append (subpage)
return result
[docs]def render_page (unitapp, roles, render_body, remote_identity):
"""Render the entire main part of the HTML page for an application.
:param unitapp: the candidate application.
:param roles: the set of roles possessed by the user.
:param render_body: a function to render the body of the page.
:param remote_identity: the user's remote identity.
:return: the page title and HTML page body.
This routine records that the user has seen the application. If they have
not yet seen it, this changes their opinion from "Unseen" to "Undecided".
The resulting page consists of a header portion rendered directly by this
function and a body below which is rendered by the render_body parameter.
"""
# Ensure that user is recorded as having seen this application
unitapp.get_faculty_information (remote_identity.person_id)
# Render the page-specific portion of the application
subpage, subpage_body = render_body (unitapp, remote_identity, roles)
# Remainder of this method renders the overall page
main_url = "" if subpage == 'main' else "../"
is_admin = roles & grad_roles
cursor = unitapp.cursor
nav_links = [html.a ('Main Menu', href=main_url + "../../")]
if 'FAC' in roles:
term = termtools.fromDate (date.today () + timedelta (days=6*30))
if unitapp.admit_term < term:
term_arc = "term/%s/" % unitapp.admit_term.code ()
else:
term_arc = ""
nav_links.append ('; ')
nav_links.append (html.a ('Your Applications',
href=main_url + "../../faculty/%s" % term_arc))
app_table = html.table (
html.tr (
html.th ('Level'),
html.th ('Plan'),
html.th ('Time'),
html.th ('Decision'),
html.th ('Compilation Document'),
)
)
app_info = unitapp.app_info
app_table.append (
html.tr (
html.td (app_info.appl_academic_level, title=levels[app_info.appl_academic_level]),
html.td (unitapp.plan_code, title=unitapp.plan_transcript_description),
html.td (app_info.approved_load, title=attendance[app_info.approved_load]),
html.td (app_info.program_action_code + '/' + app_info.program_reason_code if app_info.program_reason_code else app_info.program_action_code, title=app_info.program_action_description + '/' + app_info.program_reason_description if app_info.program_reason_description else app_info.program_action_description),
html.td (format_compilation_document (unitapp.cursor, app_info, is_admin, main_url)),
)
)
if unitapp.subplans:
app_table.append (
html.tr (
html.th ('Subplans:', colspan=2),
html.td (", ".join(unitapp.subplans), colspan=4)
)
)
if unitapp.requested_supervisor:
app_table.append (
html.tr (
html.th ('Requested Supervisor:', colspan=2),
html.td (", ".join (unitapp.requested_supervisor), colspan=4)
)
)
if unitapp.exchange_agreement:
app_table.append (
html.tr (
html.th ('Exchange Agreement:', colspan=2),
html.td (", ".join (unitapp.exchange_agreement), colspan=4)
)
)
if app_info.appl_admit_type != 'NEW':
app_table.append (
html.tr (
html.th ('Admit Type:', colspan=2),
html.td (app_info.appl_admit_type, colspan=4)
)
)
if [app_info.group_code, app_info.unit_code] != [unitapp.group_code, unitapp.unit_code]:
app_table.append (
html.tr (
html.th ('Group/Dept:', colspan=2),
html.td (app_info.group_code + '/' + app_info.unit_code, colspan=4)
)
)
if unitapp.other_apps:
other_apps = html.p ('Other Applications:')
for (appl_id, term) in unitapp.other_apps:
app = UnitApplication (cursor, cursor.unitapp_by_id (appl_id=appl_id))
link_text = '{} ({})'.format(app.plan_code, term.description())
other_apps.append (' ')
other_apps.append (html.a (link_text, href=main_url + "../%s/" % appl_id))
else:
other_apps = None
subpage_table = []
for page, label in get_active_subpages (subpages, roles):
label = html.b (label)
if page == subpage:
subpage_table.append (html.span (label))
elif page == 'main':
subpage_table.append (html.a (label, href=main_url))
else:
subpage_table.append (html.a (label, href=main_url + page + "/"))
rating = unitapp.rating
copy_button = render_copy_button("Copy", unitapp.copypaste_summary, class_="CopyButton btn btn-default btn-sm")
return unitapp.title, [
html.p (
copy_button,
' ',
html.span ('Rating: ',
html.span (rating.rating_code, style="font-weight: bold;"),
style="font-size: 150%%; background: #%s; padding: 0.5ex; margin-right: 0.5ex;" % rating.rating_colour)
if rating else None,
nav_links),
app_table,
html.p ('Status: ', html.span (format_status_column (unitapp), **attribute_due_column (unitapp))),
render_state_change_usual_form (unitapp, action_url="%sedit/" % main_url, select_class="form-control input-inline default-font") if is_admin else None,
other_apps,
html.table (
html.tr (
html.td (item) for item in subpage_table
),
class_="viewpage"
),
subpage_body
]