"""Application display accept page implementation.
WSGI handler and routines for formatting the accept page.
"""
from ll.xist.ns import html
from uw.web.html.form import render_select
from uw.web.html.bootstrapform import render_bootstrap_submit
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 ..db.status import change_state
from ..db.unitapp import levels
from .view_render import render_page
[docs]def make_level_select (cursor, name, level_code=None):
"""Render an HTML form input for choosing a level code.
Return an HTML <select> for choosing a plan level.
"""
return render_select (name, sorted (levels.items ()), level_code)
[docs]def render_accept (unitapp, remote_identity, roles, level_code=None, willfund=False, scholarship=False, fundinghelp=False, **params):
"""Render the acceptance 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.
:param level_code: the prefilled level code to include in the form.
:param willfund: whether the willfund box should be checked on the form.
:param scholarship: whether the scholarship box should be checked on the
form.
:param fundinghelp: whether the fundinghelp box should be checked on the
form.
For use with :func:`uw.local.grad.webui.view_render.render_page`; also
called from the corresponding form POST handler to allow correction of
errors.
"""
if unitapp.group_code == 'ENG':
link_special = html.p (
html.b ('Note:'),
' In addition to filling out this form, you must fill out the ',
html.a ('FOE Accept a Grad Student Form', href="https://uwaterloo.ca/engineering/future-graduate-students/foe-accept-grad-student-form"),
' in order to accept a graduate student. Acceptances cannot be processed until they have been submitted using that form.'
)
else:
link_special = None
if level_code is None:
level_code = unitapp.level_code ()
return 'accept', [
html.h2 ('Accept Applicant for Admission'),
link_special,
html.form (
html.p ('I wish to accept this applicant as a ',
make_level_select (unitapp.cursor, "level", level_code),
' student.'
),
html.p (
html.label (
html.input (type="radio", name="accept", value="af", checked=(willfund and not fundinghelp) or None),
' I am willing to supervise and fund this applicant.'
)
),
html.p (
html.label (
html.input (type="radio", name="accept", value="ah", checked=(willfund and fundinghelp) or None),
' I am willing to supervise this applicant and will need assistance with funding.'
)
),
html.p (
html.label (
html.input (type="checkbox", name="scholarship", checked=scholarship or None),
' This is a truly exceptional applicant who deserves additional scholarship funding beyond RA and TA funds.'
)
),
html.p (
render_bootstrap_submit ("Accept Applicant!", name="!accept")
),
action="", method="post"
)
]
[docs]def render_waitlist (unitapp, remote_identity, roles, waitlist=False):
"""Render the waitlisting 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.
:param bool waitlist: whether the confirmation checkbox should be checked.
For use with :func:`uw.local.grad.webui.view_render.render_page`; also
called from the corresponding form POST handler to allow correction of
errors.
"""
return 'waitlist', [
html.h2 ('Waitlist Applicant for Admission'),
html.form (
html.p (
html.label (
html.input (type="checkbox", name="waitlist", checked=waitlist or None),
'By waitlisting the applicant, I understand that the Associate Director of Graduate Studies will be informed of my interest and will not accept or reject the applicant without consulting me.'
)
),
html.p (
render_bootstrap_submit ("Waitlist Applicant!", name="!waitlist")
),
action=".", method="post"
)
]
@use_form_param
@return_html
def view_accept_get_handler (cursor, unitapp, remote_identity, roles, form):
"""Application waitlist and acceptance GET URL handler.
"""
if "waitlist" in form:
return render_page (unitapp, roles, render_waitlist, remote_identity=remote_identity)
else:
return render_page (unitapp, roles, render_accept, remote_identity=remote_identity)
@use_remote_identity
@use_form_param
@return_html
def view_accept_post_handler (cursor, unitapp, remote_identity, form, roles):
"""Application waitlist and acceptance POST URL handler.
"""
level_code = form.optional_field_value ('level') or None
accept = form.optional_field_value ('accept')
willfund = accept in ['af', 'ah']
exceptional_scholarship = 'scholarship' in form
funding_help = accept in ['ah']
waitlist = 'waitlist' in form
if "!waitlist" in form:
if not unitapp.faculty_can_waitlist:
# Application is not available for waitlisting
return 'Error: Cannot Waitlist Applicant', [
html.p ('This application is not available for waitlisting.')
]
if waitlist:
# Waitlist the applicant
unitapp.set_faculty_opinion (remote_identity.person_id, 'WTL')
raise status.HTTPFound ("../")
else:
# Confirmation not given
subpage, subpage_body = render_waitlist (unitapp, remote_identity, roles, waitlist)
return 'Error: Cannot Waitlist Applicant', [
html.p ('Please tick to confirm that you wish to waitlist this applicant.'),
subpage_body
]
else:
if not unitapp.faculty_can_accept (unitapp.get_faculty_information (remote_identity.person_id)['view_state'].view_state):
# Application is not being circulated
return 'Error: Cannot Accept Applicant', [
html.p ('This application is not currently being circulated.')
]
if not willfund:
error = 'Please tick to indicate your willingness to supervise this applicant.'
elif not level_code:
error = 'Please specify the level at which you would like to accept the applicant.'
else:
error = None
if error is None:
# Accept the applicant
cursor.execute_none ("insert into work_application_faculty_acceptance (uw_id, appl_id, faculty_person_id, level_code, exceptional_scholarship, funding_help) values (%(uw_id)s, %(appl_id)s, %(faculty_person_id)s, %(level_code)s, %(exceptional_scholarship)s, %(funding_help)s)", faculty_person_id=remote_identity.person_id, level_code=level_code, exceptional_scholarship=exceptional_scholarship, funding_help=funding_help, **unitapp.vars)
raise status.HTTPFound ("../")
else:
# Report error
subpage, subpage_body = render_accept (unitapp, remote_identity, roles, level_code, willfund, exceptional_scholarship, funding_help)
return 'Error: Cannot Accept Applicant', [
html.p (error),
subpage_body
]