Source code for uw.local.grad.webui.view_contact
"""Application dispay contact page implementation.
WSGI handler and routines for formatting the contact page.
"""
from operator import attrgetter
from ll.xist.ns import html
from uw.web.html.format import format, format_email, make_table_format
from uw.web.html.join import html_join
from uw.web.wsgi import status
from uw.web.wsgi.form import use_form_param
from uw.web.wsgi.function import return_html
from ...util.identity import use_remote_identity
from .util import format_month_date, print_address
from .view_render import render_page
[docs]def render_contact (unitapp, remote_identity, roles):
"""Render application contact information as HTML.
:param unitapp: the candidate application.
:param remote_identity: the user's remote identity.
:param roles: the set of roles possessed by the user.
For use with :func:`uw.local.grad.webui.view_render.render_page`.
"""
result = []
result.append (html.h2 ('Employment History'))
result.append (make_table_format (
('Employer', attrgetter ('employer_name')),
('Start', lambda r: format_month_date (r.start_date)),
('End', lambda r: format_month_date (r.end_date)),
('Country', attrgetter ('country_code'), lambda r: {'title': r.country_name}),
('City', attrgetter ('employer_city')),
('Title', attrgetter ('job_title')),
) (unitapp.student_employment))
result.append (html.h2 ('Referees'))
table = html.table (
html.tr (
html.th ('Name'),
html.th ('Institution'),
html.th ('Title'),
html.th ('Country'),
html.th ('Email'),
html.th ('Phone'),
html.th ('Address'),
)
)
for value in unitapp.referees:
table.append (html.tr (
html.td (value.referee_name),
html.td (value.referee_institution),
html.td (value.referee_title),
html.td (value.referee_country, title=value.country_name),
html.td (format_email (value.referee_email)),
html.td (value.referee_phone),
html.td (html_join ((value.referee_address1, value.referee_address2, value.referee_address3, value.referee_address4), html.br ())),
))
result.append (table)
result.append (html.h2 ('Applicant'))
result.append (html.h3 ('Personal'))
table = html.table ()
for field, label in [['name_title', "Prefix:"], ['preferred_name', "Preferred:"], ['first_name', "First:"], ['middle_name', "Middle:"], ['last_name', "Last:"], ['gender_code', "Gender:"], ['birthdate', "Date of Birth:"]]:
value = getattr (unitapp.applicant, field)
if value:
table.append (html.tr (
html.td (label),
html.td (format (value)),
))
if unitapp.student_languages:
table.append (html.tr (
html.td ('Language:'),
html.td (html_join (((r.language_code, " — ", r.language_name) for r in unitapp.student_languages), ', ')),
))
result.append (table)
result.append (html.h3 ('Email'))
email = unitapp.applicant_email ()
if email:
result.append (html.p (format_email (email.email)))
else:
result.append (html.p ('No email address available.'))
result.append (html.h3 ('Telephone'))
table = html.table ()
for phone in unitapp.phones:
phone_html = [phone.phone_number,
' x%s' % phone.phone_extension if phone.phone_extension else None]
if phone.phone_preferred:
phone_html = html.b (phone_html)
table.append (html.tr (
html.th (phone.phone_type_description, ':'),
html.td (phone_html),
))
result.append (table)
result.append (html.h3 ('Postal'))
for address in unitapp.addresses:
result.append (html.h4 (address.address_type_description))
result.append (html.p (print_address (address)))
return 'contact', result
@return_html
def view_contact_handler (cursor, unitapp, remote_identity, roles):
"""Application contact information display URL handler.
"""
return render_page (unitapp, roles, render_contact, remote_identity=remote_identity)