* testing on broken browsers (you know who you are)
+* the code is littered with 'dwarf' refrences. Factor out into config.
+
MAYBE:
* Generating barcodes in emails, printable screens? (3 of 9 enough?)
from conifer.libsystems.evergreen import item_status as I
from conifer.libsystems.sip.sipclient import SIP
+from conifer.libsystems.z3950 import yaz_search
+from conifer.libsystems.z3950.marcxml import marcxml_to_dictionary
@SIP
@caching('bimx', timeout=3600)
def bib_id_to_marcxml(bib_id):
return I.bib_id_to_marcxml(bib_id)
+
+
+def cat_search(query, start=1, limit=10):
+ # this is a total hack for conifer. If the query is a Conifer
+ # title-detail URL, then return just that one item.
+ if query.startswith('http://dwarf'):
+ results = [marcxml_to_dictionary(I.url_to_marcxml(query))]
+ else:
+ cat_host, cat_db = ('dwarf.cs.uoguelph.ca:2210', 'conifer')
+ results = yaz_search.search(cat_host, cat_db, query, start, limit)
+ return results
from support import ER, E1
+import re
+import urllib2
def barcode_to_bib_id(barcode):
bib_id = (E1('open-ils.search.bib_id.by_barcode', barcode))
def bib_id_to_marcxml(bib_id):
return E1('open-ils.supercat.record.marcxml.retrieve', bib_id)
+def url_to_marcxml(url):
+ # this is a hack. Given a opac Title Details url, return marcxml.
+ if url.startswith('http://dwarf.cs.uoguelph.ca'):
+ m = re.match(r'.*r=(\d+).*', url)
+ item_id = m and m.group(1) or None
+ if item_id:
+ marc_url = ("http://dwarf.cs.uoguelph.ca/opac/extras"
+ "/supercat/retrieve/marcxml/record/" + item_id)
+ xml = urllib2.urlopen(marc_url).read()
+ return xml
+
if __name__ == '__main__':
- from pprint import pprint
- print bib_id_to_marcxml(barcode_to_bib_id(31862016799294))
+# from pprint import pprint
+# print bib_id_to_marcxml(barcode_to_bib_id(31862016799294))
+ print url_to_marcxml('http://dwarf.cs.uoguelph.ca/opac/en-US/skin/default/xml/rdetail.xml?r=1082665&t=dylan%20thomas%20ralph&tp=keyword&d=0&hc=14&rt=keyword')
def marcxml_to_dictionary(rec):
tree = ElementTree.fromstring(rec)
+ if tree.tag == '{http://www.loc.gov/MARC21/slim}collection':
+ # thenwe only look at the first record.
+ tree = tree.find('{http://www.loc.gov/MARC21/slim}record')
dct = {}
for df in tree.findall('{http://www.loc.gov/MARC21/slim}datafield'):
t = df.attrib['tag']
def item_add_cat_search(request, course_id, item_id):
if request.method != 'POST':
return g.render('item_add_cat_search.xhtml', results=[], query='@and dylan thomas')
- query = request.POST.get('query','').strip()
+
+ # POST handler
+ query = request.POST.get('query','').strip()
_pickitem = request.POST.get('pickitem', '').strip()
if not _pickitem:
+ # process the query.
assert query, 'must provide a query.'
- from conifer.libsystems.z3950 import yaz_search
- host, db, query = ('dwarf.cs.uoguelph.ca:2210', 'conifer', query)
- #host, db = ('z3950.loc.gov:7090', 'VOYAGER')
- results = yaz_search.search(host, db, query)
- return g.render('item_add_cat_search.xhtml', results=results, query=query)
+ results = lib_integration.cat_search(query)
+ return g.render('item_add_cat_search.xhtml',
+ results=results, query=query)
else:
+ # User has selected an item; add it to course site.
#fixme, this block copied from item_add. refactor.
parent_item_id = item_id
if parent_item_id=='0':
item.save()
return HttpResponseRedirect('../../../%d/' % item.id)
+#------------------------------------------------------------
+
+#this is used in item_edit.
metadata_formset_class = modelformset_factory(models.Metadata,
fields=['name','value'],
extra=3, can_delete=True)
-
@instructors_only
def item_edit(request, course_id, item_id):
course = get_object_or_404(models.Course, pk=course_id)