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

"""Application display offering page implementation.

WSGI handler and routines for formatting the offering page.
"""

import re

from ll.xist.ns import html

from uw.web.html.form import render_checkbox
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.web.html.bootstrapform import render_bootstrap_submit

from ..db.unitapp import levels

from ...util.format import format_person
from .view_render import render_page

[docs]def render_offer (unitapp, remote_identity, roles): """Render offer information for an application 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`. """ faculty_info = unitapp.get_faculty_information () waitlist = faculty_info['waitlist'] acceptances = faculty_info['accepted_by'] if acceptances or waitlist: accept_table = html.table ( html.tr ( html.th ('Faculty Member'), html.th ('Level'), html.th ('Scholarship'), html.th ('Funding Help'), html.th ('Cancel'), ) ) for acceptance in acceptances: accept_table.append ( html.tr ( html.td (format_person (unitapp.cursor, acceptance.person_id)), html.td (acceptance.level_code, title=levels[acceptance.level_code]), html.td (acceptance.exceptional_scholarship), html.td (acceptance.funding_help), html.td (render_checkbox ("cancel_%s" % acceptance.person_id)), ) ) for person_id in waitlist: accept_table.append ( html.tr ( html.td (format_person (unitapp.cursor, person_id)), html.td ('Waitlist', colspan=3), html.td (render_checkbox ("cancel_%s" % person_id)), ) ) accept_table = html.form ( accept_table, html.p (render_bootstrap_submit ("Cancel Selected!")), action="", method="post" ) else: accept_table = html.p ('This application has not been waitlisted or accepted by any faculty member.') return 'offer', accept_table
@return_html def view_offer_get_handler (cursor, unitapp, remote_identity, roles): """Application offer information display GET URL handler. """ return render_page (unitapp, roles, render_offer, remote_identity=remote_identity) cancel_field_pattern = re.compile ("^cancel_(?P<value>[0-9]+)$") @use_form_param @return_html def view_offer_post_handler (cursor, unitapp, remote_identity, form, roles): """Application offer information display POST URL handler. This can cancel an acceptance and return the faculty member's opinion to "Interested". """ for field in form: match = cancel_field_pattern.match (field) if match is None: continue person_id = int (match.group ("value")) cursor.execute_none ("update work_application_faculty_acceptance set acceptance_cancelled = now () where (uw_id, appl_id, faculty_person_id) = (%(uw_id)s, %(appl_id)s, %(faculty_person_id)s) and acceptance_cancelled is null", faculty_person_id=person_id, **unitapp.vars) cursor.execute_none ("update work_application_faculty set view_state = 'INT' where (uw_id, appl_id, faculty_person_id) = (%(uw_id)s, %(appl_id)s, %(faculty_person_id)s)", faculty_person_id=person_id, **unitapp.vars) raise status.HTTPFound (".")