Source code for uw.local.dbtools

from uw.sql.wrap import Cursor
from uw.sql.dbapi import *

from uw.web.wsgi.delegate import *

from uw.local import termtools

[docs]class Cursor (Cursor): unit_by_code = make_execute_optional_tuple ("select * from uw_unit where unit_code=%(unit_code)s") term_by_code = make_execute_optional_tuple ("select * from uw_term where term_id=%(term_id)s") person_by_userid = make_execute_optional_value ("select person_id from person_identity_complete where userid=%(userid)s")
person_int_from_arc = make_int_from_arc (8)
[docs]def person_from_arc (arc, cursor, **params): arc = person_int_from_arc (arc) if arc is None: return None return cursor.execute_optional_tuple ("select * from person_identity_complete where person_id=%(person_id)s", person_id=arc)
[docs]def person_delegate (dir_handler, arc_handler): return delegate_value ('person', dir_handler, always (arc_handler), convert_arc=person_from_arc)
[docs]def unit_from_arc (arc, cursor, **params): if arc is None: return None return cursor.unit_by_code (unit_code=arc)
[docs]def unit_delegate (dir_handler, arc_handler): return delegate_value ('unit', dir_handler, always (arc_handler), convert_arc=unit_from_arc)
# Term stuff doesn't really belong here yet because it doesn't touch the DB. # Eventually we anticipate pulling the class start/end dates etc. from the DB.
[docs]def term_from_arc (arc, cursor, **params): try: return termtools.fromCode (arc) except ValueError: return None
[docs]def term_delegate (dir_handler, arc_handler): return delegate_value ('term', dir_handler, always (arc_handler), convert_arc=term_from_arc)