Source code for uw.local.print_.webui.job

"""Job-related URL handlers.

URL handlers for listing jobs and viewing individual jobs.
"""

from operator import attrgetter

from ll.xist.ns import html

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

from uw.web.wsgi import status
from uw.web.wsgi.delegate import delegate_get_post
from uw.web.wsgi.function import return_html, return_pdf

from ...util.identity import use_remote_identity

from ..bin.requisition_received import complete_filename

[docs]def format_status (r): """Format the job status table column. :param r: information about a job. Displays the most advanced available one of five possible date fields. Usually this will be "Files Sent" because the time between a job being marked "Ready" and the rest of the process completing is usually short. Jobs that are "Cancelled" will also stay that way indefinitely. Other status values should show up only briefly after the job is marked "Ready". """ for label, field in ( ('Files Sent', 'requisition_arrived'), ('Arrived', 'requisition_arrived'), ('Submitted', 'requisition_arrived'), ('Ready', 'job_ready'), ('Cancelled', 'job_cancelled'), ): attr = getattr (r, field) if attr is not None: return '%s %s' % (label, format_datetime (attr)) return 'Unknown'
[docs]def format_jobs (jobs, baseurl=""): """Format some jobs as an HTML table. :param jobs: an iterable of job information. :param baseurl: the base URL of the application. Generates an HTML table with columns for the Job ID, when it was created, its current status, a link to the associated requisition PDF if any, and the job title. """ return make_table_format ( ('Job ID', lambda r: html.a ('%d' % r.job_id, href="%sjob/%d/" % (baseurl, r.job_id))), ('Created', lambda r: format_datetime (r.job_created)), ('Status', format_status), ('Requisition', lambda r: None if r.requisition_num is None else html.a ('R%06d' % r.requisition_num, href="%sreq/R%06d/pdf" % (baseurl, r.requisition_num))), ('Title', attrgetter ('requisition_title')), ) (jobs)
@delegate_get_post @return_html def job_index (cursor): """Job index URL handler. Displays a list of all jobs in the system. """ result = [format_return ('Main Menu')] jobs = cursor.all_jobs () result.append (format_jobs (jobs, "../")) return 'Job Index', result @delegate_get_post @use_remote_identity @return_html def job_view (cursor, remote_identity, job): """Job view URL handler. Displays information about the in-context job, including a link to the related requisition if any. """ result = [format_return ('Main Menu', 'Jobs')] if job.requisition_num is None: result.append (html.p ('This job is not associated with a requisition.')) else: result.append (html.p ( 'This job is associated with Requisition ', html.a ('R%06d' % job.requisition_num, href="../../req/R%06d/pdf" % job.requisition_num), ', which arrived ', format_datetime (job.requisition_arrived), '.' )) result.append (html.h2 ('Form Values')) result.append (make_table_format ( ('Field', attrgetter ('field_code')), ('Value', attrgetter ('field_value')), ) (cursor.execute_tuples ("select * from nms_requisition_form_value where job_id = %(job_id)s order by field_code", job_id = job.job_id))) result.append (html.h2 ('Files')) if cursor.check_perm_admin (person_id=remote_identity.person_id): format_file = lambda r: html.a (r.file_code, href="file/%s" % r.file_code) else: format_file = attrgetter ('file_code') result.append (make_table_format ( ('File', format_file), ('Size', attrgetter ('file_size')), ) (cursor.execute_tuples ("select file_code, length (file_contents) as file_size from nms_requisition_file where job_id = %(job_id)s order by file_code", job_id = job.job_id))) title = 'Job %d' % job.job_id if job.requisition_title is not None: title += ': ' + job.requisition_title return title, result @return_pdf def job_pdf (cursor, job, file_code): """Job file PDF download URL handler. Serves the appropriate job PDF file to the client. """ row = cursor.file_by_ids (job_id=job.job_id, file_code=file_code) if row is None: raise status.HTTPNotFound () return (row.file_contents, complete_filename (row))