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

"""Crowdmark-specific UI implementation.

This contains the implementation of Crowdmark-specific pages, including the
list of Crowdmark examinations.
"""

from functools import partial
from operator import attrgetter

from ll.xist.ns import html

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

from uw.web.html.format import make_table_format, format_return, format_time, format_datetime

from uw.local.config import read_config

from .ui import bool_to_yes_no

api_key_config = read_config ()



[docs]def format_pages (exam): """Render as HTML an estimate of how many pages of scanning there will be. :param exam: a database row representing an examination. :return: estimate of how many pages of scanning there will be :rtype: int """ if exam.master_pages_gross is None: return None return exam.count_selected_candidates * exam.master_pages_gross
@delegate_get_post @return_html def crowdmark_handler (cursor): """Crowdmark examination listing handler. :param cursor: DB connection cursor :return: a list of recent and future Crowdmark examinations :rtype: (str, list) """ result = [format_return (dot='Main Menu')] table_div = html.div (class_="datatable-container") table = (make_table_format ( ('Start Time', lambda r: format_datetime (r.primary_start_time)), ('End Time', lambda r: None if r.exam_duration is None or r.primary_start_time is None else format_time (r.primary_start_time + r.exam_duration)), ('Assessment', lambda r: html.a (r.full_title, href="term/%s/%s/exam/%s/" % (r.term_id, r.admin_id, r.exam_id))), ('Candidates', attrgetter ('count_selected_candidates')), ('Pages', format_pages), ('Crowdmark Upload', partial (format_crowdmark_link, url="uploads")), ('Marking Start Date', lambda r: format_datetime (r.exam_marking_start)), ('Request Sample', lambda r: bool_to_yes_no (r.exam_scan_request_sample)), ('Drop Off/Courier Pick Up Date', lambda r: format_datetime (r.scan_pickup_when)), ('Drop Off/Courier Pick Up Location', attrgetter ('scan_pickup_where')), ('Return Date', lambda r: format_datetime (r.scan_return_when)), ('Return Location', attrgetter ('scan_return_where')), ) (cursor.execute_tuples ("select ee.*, exam_exam_count_selected_candidates (exam_id) AS count_selected_candidates, master_pages_gross, exam_exam_full_title (exam_id) AS full_title, crowdmark_exam_code, exam_marking_start, exam_scan_request_sample, scan_pickup_when, scan_pickup_where, scan_return_when, scan_return_where from exam_exam ee natural join exam_exam_crowdmark natural join exam_exam_scan left join (select exam_id, type_code, max (master_pages_gross) as master_pages_gross from exam_exam_master_plus where type_code = 'A' group by exam_id, type_code) as t using (exam_id) where primary_start_time is null or primary_start_time >= uw_business_day_offset (uw_this_next_business_day (current_date), -15) order by primary_start_time") )) table_div.append (table) result.append (table_div) return 'Crowdmark Assessments', result @return_html def crowdmark_upload_master_post_handler (cursor, term, admin, roles, exam): master_pdf = cursor.execute_required_value ("select master_pdf from exam_exam_master where (exam_id, type_code, version_seq) = (%(exam_id)s, 'A', 0)", exam_id=exam.exam_id) master_description = cursor.execute_required_value ("select master_description from exam_exam_master_plus where (exam_id, type_code, version_seq) = (%(exam_id)s, 'A', 0)", exam_id=exam.exam_id) success, response = crowdmark_upload_pdf (cursor, exam, master_pdf) result = [format_return ('Main Menu', None, None, 'Offering', None, dot='Assessment')] if success: result.append (html.p ('The %s master has been uploaded to Crowdmark. You should now be able to see it in the Crowdmark question editor.' % master_description)) return 'Successfully Uploaded PDF', result else: result.append (html.p ('Status %d was reported attempting to upload the PDF, with the following message:' % response.status)) result.append (html.pre (response.data.decode ())) return 'Unable to Upload PDF', result crowdmark_upload_master = delegate_get_post (None, crowdmark_upload_master_post_handler)