[docs]class nms_requisition (object):
def __init__ (self, cursor, job_id=None):
"""Create a New Media Services requisition.
Parameters:
cursor -- the database connection cursor;
job_id -- the Job ID of an existing job to edit that job, or omit
(or None) to create a new job. This is not the NMS requisition
number; that is assigned when the job is submitted to NMS.
"""
self.__cursor = cursor
if job_id is None:
self.__job_id = cursor.callproc_required_value ("nms_create_job")
else:
self.__job_id = job_id
@property
def cursor (self):
return self.__cursor
@property
def job_id (self):
return self.__job_id
[docs] def set_value (self, field_code, field_value):
"""Set a requisition field value.
Parameters:
field_code -- the HTML form element ID;
field_value -- the value to send in the Graphics requisition.
"""
self.cursor.callproc_none ("nms_job_set_value",
self.job_id, field_code, field_value)
[docs] def set_value_choice (self, field_code, allowed_values, error_message, given_value):
"""Set a requisition field value to one of a set of allowed values.
Parameters:
field_code -- the HTML form element ID;
allowed_values -- the set of allowed values;
error_message -- error message to include if given value not allowed;
given_value -- the value to send in the Graphics requisition.
Intended for use by other more specific field-setting methods.
"""
if given_value is not None:
if given_value not in allowed_values:
raise ValueError ('%s: %s' % (error_message, given_value))
self.set_value (field_code, given_value)
# *** TODO: improve and move to Identity
[docs] def person_details (self, person_id):
return self.cursor.execute_optional_tuple ("select we.campus_email as email, we.givennames || ' ' || we.surname as name, (select string_agg (dept_name, '/') from watiam_dept_name where pdbid = we.pdbid) as dept, (select string_agg (office, '/') from watiam_office where pdbid = we.pdbid) as address, (select string_agg (phone, '/') from watiam_phone where pdbid = we.pdbid) as phone from watiam_entry we join person_identity_complete pic on (we.pdbid = pic.pdbid::integer) where person_id = %(person_id)s", person_id=person_id)
# *** TODO: validate against ^[0-9]{31}$
[docs] def set_flexfield (self, flexfield):
"""Set the accounting flexfield to charge for this requisition.
Parameters:
flexfield -- the 31-digit UW accounting flexfield.
"""
self.set_value ('paytype', 'uwaccount')
self.set_value ('flexfield', flexfield)
[docs] def set_title (self, title):
"""Set the job title for this requisition.
Parameters:
title -- the title to use on the requisition.
"""
self.set_value ('jobtitle', title)
[docs] def set_date_required (self, required):
"""Set the date required for this requisition.
Parameters:
required -- the date the resulting print job is required to be done.
"""
self.set_value ('date', required.strftime ('%b %d, %Y'))
[docs] def set_end_use (self, use):
"""Set the end use for this requisition.
Parameters:
use -- The end use, one of 'administration', 'research', 'resale',
'teaching', or 'educational'.
"""
self.set_value_choice ('enduse', ['administration', 'research', 'resale', 'teaching', 'educational'], 'Invalid end use', use)
# *** TODO: support electronic submission (esub, filename)?
[docs] def set_shipping (self, ship_type, ship_to):
"""Set the shipping choice for this requisition.
Parameters:
ship_type -- the shipping type, one of 'call', 'emailwhendone',
'email', or 'uwmail'.
ship_to -- the text to fill in on the requisition for shipping
destination.
"""
self.set_value_choice ('shiptype', ['call', 'emailwhendone', 'email', 'uwmail'], 'Invalid shipping type', ship_type)
self.set_value ('shipaddress', ship_to)
[docs] def set_courier (self, person_id):
"""Set the shipping for this requisition for delivery to a person.
Parameters:
person_id -- the Person ID of the person who should take delivery.
This invokes set_shipping with appropriate values to request delivery
to the indicated person according to their office location according to
WatIAM.
"""
contact = self.person_details (person_id)._asdict ()
self.set_shipping ('call', 'Please courier to %(name)s in %(address)s\n(%(email)s, %(phone)s)' % contact)
# *** TODO: support non-bond paper types
[docs] def set_copyprint (self, pages=None, copies=None,
simplex=False, duplex=False,
paper_bond=False,
size_letter=False, size_legal=False, size_ledger=False, size_other=None,
paper_white=False, paper_other=None,
ink_black=False, ink_colour=False, ink_pantone=None
):
self.set_value ('copyprint', 'yes')
# Job size
if pages is not None:
self.set_value ('pages', '%d' % pages)
if copies is not None:
self.set_value ('copies', '%d' % copies)
# Plexing
if simplex:
if duplex:
self.set_value ('sides', 'mixed')
else:
self.set_value ('sides', 'single')
elif duplex:
self.set_value ('sides', 'double')
# Paper types
if paper_bond:
self.set_value ('stock_bond', 'yes')
# Paper sizes
if size_letter:
self.set_value ('papersize_letter', 'yes')
if size_legal:
self.set_value ('papersize_legal', 'yes')
if size_ledger:
self.set_value ('papersize_tabloid', 'yes')
if size_other is not None:
self.set_value ('papersize_other', 'yes')
self.set_value ('otherpapersize', size_other)
# Paper colours
if paper_white:
self.set_value ('papercolour_white', 'yes')
if paper_other is not None:
self.set_value ('papercolour_other', 'yes')
self.set_value ('otherpapercolour', paper_other)
# Ink colours
if ink_black:
self.set_value ('inkcolour_black', 'yes')
if ink_colour:
self.set_value ('inkcolour_full', 'yes')
if ink_pantone is not None:
self.set_value ('inkcolour_other', 'yes')
self.set_value ('otherinkcolour', ink_pantone)
[docs] def set_binding (self, stapling='none', padding=False
):
self.set_value ('bindfinish', 'yes')
# *** TODO: support binding
self.set_value ('bindingtype', 'none')
self.set_value_choice ('staplingtype', ['none', 'corner', 'book', 'saddle'], 'Invalid stapling type', stapling)
# *** TODO: support folding
self.set_value ('foldingtype', 'none')
# *** TODO: support punching, collating, laminating, scoring, numbering
if padding:
self.set_value ('padding', 'yes')
# *** TODO: support cutting
# *** TODO: support posting printing/scanning
# *** TODO: support graphic/multimedia
# *** TODO: support digital archiving
# *** TODO: support CD/DVD duplicating
[docs] def set_instructions (self, instructions):
self.set_value ('specialinstructions', 'yes')
self.set_value ('instructions', instructions)
[docs] def attach_file (self, file_code, file_contents):
"""Attach a file to be submitted with the requisition.
"""
self.cursor.callproc_none ("nms_job_attach_file",
self.job_id, file_code, bytearray (file_contents))
[docs] def cancel (self):
"""Cancel the requisition.
"""
self.cursor.callproc_none ("nms_job_cancel", self.job_id)
[docs] def ready (self):
"""Mark the requisition as ready to be submitted to New Media Services.
"""
self.cursor.callproc_none ("nms_job_ready", self.job_id)