"""Application dispay edit page implementation.
WSGI handler and routines for formatting the edit page.
"""
from itertools import takewhile
from ll.xist.ns import html
from uw.web.html.form import render_select, parse_date_2, render_form_value_hidden, render_hidden
from uw.web.html.bootstrapform import render_bootstrap_submit, parse_bootstrap_date
from uw.web.wsgi import status
from uw.web.wsgi.form import use_form_param
from uw.web.wsgi.function import return_html
from uw.local import termtools
from uw.local.util.format import format_person
from ...util.identity import use_remote_identity
from ..db.status import render_state_change_override_form, change_state, reason_gso_mapping
from .view_render import render_page
[docs]def render_edit (unitapp, remote_identity, roles):
"""Render application editing form 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`.
"""
is_director = 'DIR' in roles
result = []
faculty_info = unitapp.get_faculty_information (remote_identity.person_id)
result.append (html.h2 ('Rating'))
if unitapp.rating is None:
rating = None
else:
rating = unitapp.rating.rating_code
result.append (html.form (
'Rate application as: ',
render_select ("!rating", unitapp.cursor.execute_tuples ("select rating_code, rating_code as rating_code_display from work_application_rating_code where active order by rating_sequence"), rating, blank=True, class_="form-control input-inline vertical-align"),
' ',
render_bootstrap_submit ("Rate!"),
action="", method="post"
))
result.append (html.h2 ('Requested Supervisor'))
result.append (html.table (
html.tr (
html.th ('Requested Supervisor by Applicant:'),
html.td (", ".join (unitapp.requested_supervisor)
)
)))
request_table = []
for supervisor in faculty_info['requested_supervisor']:
request_table.append (html.tr (html.td(format_person (unitapp.cursor, supervisor.person_id)), html.form (html.td(render_hidden (value=supervisor.person_id, name="!remove_request"), html.input (type="submit", value="Remove!")), action="", method="post")))
result.append (html.p ('Currently Requesting:'))
result.append (html.table (request_table))
result.append (
html.form (html.p (
'This application requested supervisor: ',
render_select ('!request', faculty_info['faculty_members'], class_="form-control input-inline vertical-align"),
' ', render_bootstrap_submit ("Request!")
), action="", method="post")
)
result.append (html.h2 ('Override State Change'))
result.append (render_state_change_override_form (unitapp.cursor, form_class="override", select_class="form-control input-inline vertical-align"))
if is_director or 'IQC' in roles:
result.append (html.h2 ('Research Interest Areas'))
result.append (
html.form (
html.p (
[
html.label (
html.input (type="checkbox", name=area.faculty_interest_area, checked=area.checked),
' ',
area.faculty_interest_description
),
html.br ()
] for area in unitapp.research_areas
),
html.p (render_bootstrap_submit ("Update!", name="!areas") ),
action="", method="post"
)
)
return 'edit', result
@return_html
def view_edit_get_handler (cursor, unitapp, remote_identity, roles):
"""Application editing form GET URL handler.
"""
return render_page (unitapp, roles, render_edit, remote_identity=remote_identity)
@use_remote_identity
@use_form_param
@return_html
def view_edit_post_handler (cursor, unitapp, remote_identity, form, roles):
"""Application editing form POST URL handler.
This implements the following actions:
- defer the application to a different term
- adjust the research interest areas associated with the application
- update the status of the application
- attach a rating to the application
- upload a compilation document PDF
"""
if not roles & set (['ADC', 'DIR']):
raise status.HTTPForbidden ()
if '!areas' in form:
vars = unitapp.vars
vars['group_code'] = unitapp.group_code
vars['unit_code'] = unitapp.unit_code
for area in unitapp.research_areas:
old = area.checked is not None
new = area.faculty_interest_area in form
vars['area'] = area.faculty_interest_area
if old and not new:
# Remove interest area
cursor.execute_none ("delete from work_application_interest where (uw_id, appl_id, group_code, unit_code, faculty_interest_area) = (%(uw_id)s, %(appl_id)s, %(group_code)s, %(unit_code)s, %(area)s)", **vars)
elif not old and new:
# Add interest area
cursor.execute_none ("insert into work_application_interest values (%(uw_id)s, %(appl_id)s, %(group_code)s, %(unit_code)s, %(area)s)", **vars)
elif '!status' in form:
# Update application status
is_override = "override" in form
new_state_code = form.required_field_value ("!status")
new_state_info = cursor.execute_optional_tuple ("select * from work_application_status_code where status_code = %(code)s", code=new_state_code)
if new_state_info is None:
return ('Invalid State', html.p ('There is no state “%s”. Please go back and try again.' % new_state_code))
if new_state_info.status_default_deadline is None:
deadline = None
else:
if new_state_info.fixed_deadline and not is_override:
deadline = cursor.execute_required_value("select new_deadline from work_application_status_change WHERE (uw_id, appl_id, new_status_code) = (%(uw_id)s, %(appl_id)s, %(code)s)", code=new_state_code, **unitapp.vars)
else:
deadline = parse_bootstrap_date (form, "date")
reason_code = form.optional_field_value ("reason")
reason_info = cursor.execute_optional_tuple ("select program_reason_code, program_reason_description from uw_program_reason where (program_action_code, program_reason_code) = (%(action_code)s, %(reason_code)s)", action_code=reason_gso_mapping.get (new_state_code), reason_code=reason_code)
has_date = "date" in form
if "confirmed" in form:
change_state (unitapp, remote_identity, new_state_code, deadline, override=is_override, reason_code=reason_code)
else:
return ('Confirm Status Change',
html.form (
render_form_value_hidden (form, "override") if is_override else None,
render_form_value_hidden (form, "reason") if reason_code else None,
render_form_value_hidden (form, "!status"),
render_form_value_hidden (form, "statusdesc"),
render_form_value_hidden (form, "date") if has_date else None,
html.p (),
html.table (
html.tr (
html.td ('Applicant Name:'),
html.td (unitapp.applicant.first_name,
' ', unitapp.applicant.last_name)
),
html.tr (
html.td ('Applicant UW ID:'),
html.td (unitapp.uw_id)
),
html.tr (
html.td ('Current State:'),
html.td (unitapp.statusdesc)
),
html.tr (
html.td ('New State:'),
html.td (html.b (new_state_info.status_description))
),
html.tr (
html.td ('Deadline:'),
html.td (html.b (deadline.isoformat ()))
) if deadline else None,
html.tr (
html.td ('Reason:'),
html.td ('%(program_reason_description)s (%(program_reason_code)s)' % reason_info._asdict ())
) if reason_info else None,
),
html.p ('Please check that the above details are correct before proceeding. The appropriate notifications to faculty members and/or other interested parties will be sent immediately upon the state being changed. If the above is not correct please use the “Back” button to return to the previous screen.'),
html.p (
html.input (type="hidden", name="confirmed", value=""),
render_bootstrap_submit ("Change Status!")
),
action="", method="post"
)
)
elif '!rating' in form:
rating = form.required_field_value ("!rating")
if len (rating) == 0: # empty string / blank option
rating = None
# TODO: note current user in work_application_rating record
cursor.execute_none ("insert into work_application_rating (uw_id, appl_id, rater_person_id, rating_code) values (%(uw_id)s, %(appl_id)s, %(person_id)s, %(rating_code)s)", rating_code=rating, person_id=remote_identity.person_id, **unitapp.vars)
elif '!request' in form:
requested_person_id = form.required_field_value ("!request")
cursor.execute_none ("insert into work_application_request (uw_id, appl_id, requested_person_id) values (%(uw_id)s, %(appl_id)s, %(requested_person_id)s)", requested_person_id=requested_person_id, **unitapp.vars)
elif '!remove_request' in form:
requested_person_id = form.required_field_value ("!remove_request")
cursor.execute_none ("delete from work_application_request where (uw_id, appl_id, requested_person_id) = (%(uw_id)s, %(appl_id)s, %(requested_person_id)s)", requested_person_id=requested_person_id, **unitapp.vars)
elif '!compilation' in form:
pdf = form.required_field_value ("compilation")
cursor.callproc_none ("work_application_update_compilation", unitapp.uw_id, unitapp.appl_id, pdf, remote_identity.person_id)
elif 'remove_compilation' in form:
if "confirm_removal" in form:
cursor.execute_none ("delete from work_application_compilation_document where (uw_id, appl_id)=(%(uw_id)s, %(appl_id)s)", uw_id=unitapp.uw_id, appl_id=unitapp.appl_id)
else:
return (unitapp.title,
html.form (
render_hidden ("remove_compilation", ""),
render_hidden ("confirm_removal", ""),
html.p ('This action will delete the current compilation document. Are you sure you would like to continue?'),
html.p (
render_bootstrap_submit ("Yes")
),
method="post", action=""
)
)
raise status.HTTPFound (".")