From 44a0ed5b3a753d7adb065a9a31acfa2e50e95156 Mon Sep 17 00:00:00 2001 From: artunit Date: Sun, 9 Jan 2011 23:04:00 +0000 Subject: [PATCH] display earliest due date git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@1176 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/integration/uwindsor.py | 47 ++++++++++++++++++++++----------- conifer/templates/components/site.xhtml | 4 +-- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/conifer/integration/uwindsor.py b/conifer/integration/uwindsor.py index ef3eeee..33c5913 100644 --- a/conifer/integration/uwindsor.py +++ b/conifer/integration/uwindsor.py @@ -10,15 +10,24 @@ from django.conf import settings from memoization import memoize from xml.etree import ElementTree as ET import csv +import datetime +import time import os import re +import traceback import subprocess import uwindsor_campus_info +#TODO: move these into settings +TIME_FORMAT = "%Y-%m-%dT%H:%M:%S" +DUE_FORMAT = "%b %d %Y, %r" +OPENSRF_CN_CALL = "open-ils.search.asset.copy.retrieve_by_cn_label" +OPENSRF_FLESHED2_CALL = "open-ils.search.asset.copy.fleshed2.retrieve" +OPENSRF_COPY_COUNTS = "open-ils.search.biblio.copy_counts.location.summary.retrieve" + # USE_Z3950: if True, use Z39.50 for catalogue search; if False, use OpenSRF. # Don't set this value directly here: rather, if there is a valid Z3950_CONFIG # settings in local_settings.py, then Z39.50 will be used. - USE_Z3950 = getattr(settings, 'Z3950_CONFIG', None) is not None @@ -91,8 +100,7 @@ def _item_status(bib_id): if bib_id: try: - counts = E1('open-ils.search.biblio.copy_counts.location.summary.retrieve', - bib_id, 1, 0) + counts = E1(OPENSRF_COPY_COUNTS, bib_id, 1, 0) lib = desk = avail = 0 dueinfo = '' callno = '' @@ -105,28 +113,37 @@ def _item_status(bib_id): desk += anystatus_here avail += avail_here lib += anystatus_here - copyids = E1('open-ils.search.asset.copy.retrieve_by_cn_label', - bib_id, callnum, org) + copyids = E1(OPENSRF_CN_CALL, bib_id, callnum, org) """ - we will need to determine the first available copy, will look - at date/time logic for this + we want to return the resource that will be returned first if + already checked out """ for copyid in copyids: - circinfo = E1('open-ils.search.asset.copy.fleshed2.retrieve', copyid) + circinfo = E1(OPENSRF_FLESHED2_CALL, copyid) circs = circinfo.get("circulations") if circs: - # just grab the first for now, not much point iterating - #until compare is done - if len(circs) > 0: circ = circs[0] - dueinfo = circ.get("due_date") - callno = callnum + rawdate = circ.get("due_date") + #remove offset info, %z is flakey for some reason + rawdate = rawdate[:-5] + duetime = time.strptime(rawdate, TIME_FORMAT) + if len(dueinfo) == 0: + earliestdue = duetime + dueinfo = time.strftime(DUE_FORMAT,earliestdue) + callno = callnum + if duetime < earliestdue: + earliestdue = duetime + dueinfo = time.strftime(DUE_FORMAT,earliestdue) + callno = callnum + return (lib, desk, avail, callno, dueinfo) except: - print "problem: ", bib_id - pass # fail silently if there's an opensrf related error. + print "due date/call problem: ", bib_id + print "*** print_exc:" + traceback.print_exc() + pass # fail silently in production if there's an opensrf or time related error. return None def cat_search(query, start=1, limit=10): diff --git a/conifer/templates/components/site.xhtml b/conifer/templates/components/site.xhtml index 311436c..c63596a 100644 --- a/conifer/templates/components/site.xhtml +++ b/conifer/templates/components/site.xhtml @@ -43,9 +43,7 @@ searchtext = _('search this site...') class="${_avail > 0 and 'available' or 'unavailable'}" title="${_avail} of ${_desk} copies available at reserves desk; ${_lib} total copies in library system">
${_avail and 'Available' or 'Unavailable'} (${_avail}/${_desk})
- +
DUE: ${_dueinfo}
-- 2.11.0