Source code for uw.local.teaching.webui.enrolment

'''Enrolment display.

Web UI pages for viewing student enrolment for an offering.
'''

from operator import attrgetter

from ll.xist.ns import html

from uw.web.html.format import make_table_format, format_email, format_return, format_tabs

from uw.web.wsgi.delegate import delegate_get_post
from uw.web.wsgi.function import return_html

from .division import render_enrol_division

[docs]def get_sections (cursor, term, admin): return cursor.execute_tuples ("select section_id, off_instruct_section_format (term_id, section_id) AS section_description, is_enrol_total from teaching_admin_section_mapping join off_instruct_section using (term_id, section_id) where (term_id, admin_id) = (%(term_id)s, %(admin_id)s) order by section_description", term_id=term.code (), admin_id=admin.admin_id)
[docs]def format_sections (sections): enrol_total = sum (r.is_enrol_total for r in sections) footer_row = html.tr ( html.th ('Total:', colspan=2), html.td (enrol_total), ) return make_table_format ( ('Section ID', attrgetter ('section_id')), ('Section Number', attrgetter ('section_description')), ('Enrolment', attrgetter ('is_enrol_total')), footer_row=lambda: footer_row ) (sections)
[docs]def format_problem_userid (r): if r.activated: return 'OK' else: return 'Missing — Student must claim their identity within WatIAM'
[docs]def format_problem_person_id (r): if r.person_id is not None: return 'OK' else: return 'Missing — Problem with identity mapping'
[docs]def format_problem_enrolments (cursor, term, admin): result = [] problem_enrolments = cursor.execute_tuples ("select * from teaching_admin_class_student natural left join adm_std_email natural left join std_name_primary where (term_id, admin_id) = (%(term_id)s, %(admin_id)s) and (not activated or person_id is null)", term_id=term.code (), admin_id=admin.admin_id) if problem_enrolments: result.append (html.h2 ('Enrolment Problem Warning')) result.append (html.p ('The following students are enrolled in this class, but there is a problem with their identity record. Until this is corrected, they cannot be processed and will not appear on the class list within Odyssey.')) result.append (make_table_format ( ('UW ID', attrgetter ('uw_id')), ('Names', lambda r: '%s, %s' % (r.last_name, r.first_name)), ('Applicant Email', lambda r: format_email (r.applicant_email)), ('Userid', format_problem_userid), ('Person ID', format_problem_person_id), ) (problem_enrolments)) return result
@delegate_get_post @return_html def enrol_handler (cursor, term, admin, roles): result = [format_return ('Main Menu', None, None, dot='Offering')] problem_enrolments = format_problem_enrolments (cursor, term, admin) if problem_enrolments: result.append (problem_enrolments) links = [] if 'ADMIN' in roles: links.append (html.a ('Move Sections…', href="edit")) if set (['ISC', 'INST']) & roles: links.append (html.a ('Grade Revisions…', href="grades/")) if admin.enrolment: links.append ([ html.a ('Download Current Students', href="classlist"), ' (', admin.enrolment, ' enrolled)', ]) links.append ([ html.a ('Download Former Students', href="classlist?dropped"), ' (dropped or withdrawn since beginning of classes)', ]) if links: result.append (html.h2 ('Quick Links')) result.append (html.ul (html.li (link) for link in links)) sections = get_sections (cursor, term, admin) sections_content = [] if sections: sections_content.append (html.p ('The following enrolment sections are attached to this offering:')) sections_content.append (format_sections (sections)) if admin.enrolment: sections_content.append (html.p ('The enrolment numbers in this table include withdrawn students. Accordingly, their total may not match the total enrolment shown in the downloadable enrolment list above.')) else: sections_content.append (html.p ('The enrolment numbers shown in this table are the Quest numbers. Enrolments will be imported into this system on the first day of classes. At that time, they will become available for download at the top of this page.')) else: sections_content.append (html.p ('No sections are attached to this offering.')) divisions_content, divisions_count = render_enrol_division (cursor, term, admin, roles, "division/", True) tab_lst = [ ('Divisions (%s)' % divisions_count, 'divisions', divisions_content), ('Sections (%s)' % len (sections), 'sections', sections_content) ] result.append (format_tabs (tab_lst)) return "%s (%s) Enrollment" % (admin.admin_description, term.description ()), result