From: gfawcett Date: Wed, 6 May 2009 02:12:39 +0000 (+0000) Subject: Z39.50 madness! Now will paginate through all hits. Items with 856$9 added as URLs... X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=1a54d1d4658c6e83a6dedf6b33a6cbcbaff6f3cb;p=Syrup.git Z39.50 madness! Now will paginate through all hits. Items with 856$9 added as URLs, not Physical Items. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@455 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- diff --git a/conifer/TODO b/conifer/TODO index 0c60e0d..4f818dc 100644 --- a/conifer/TODO +++ b/conifer/TODO @@ -8,10 +8,6 @@ IMPORTANT: * set up a proper issue-tracker? -* Z39.50 may return e-journal records (with 856u hyperlinks) and other - non-physical items. 859$9 is a definitive indicator in the Conifer - (Evergreen?) context. - * opensrf alternatives for SIP calls? * need more than 10 results on physical-item search results. @@ -70,3 +66,7 @@ RECENTLY DONE: > Sequencing -- easy! Save -- maybe make a button? [where's my narrative?] [I didn't make it a button, but I did add the narrative back.] +* Z39.50 may return e-journal records (with 856u hyperlinks) and other + non-physical items. 856$9 is a definitive indicator in the Conifer + (Evergreen?) context. + diff --git a/conifer/custom/lib_integration.py b/conifer/custom/lib_integration.py index 3de2070..294e010 100644 --- a/conifer/custom/lib_integration.py +++ b/conifer/custom/lib_integration.py @@ -85,7 +85,8 @@ def cat_search(query, start=1, limit=10): # title-detail URL, then return just that one item. if query.startswith(EG_BASE): results = marcxml_to_dictionary(I.url_to_marcxml(query), multiples=True) + numhits = len(results) else: cat_host, cat_db = settings.Z3950_CONFIG - results = yaz_search.search(cat_host, cat_db, query, start, limit) - return results + results, numhits = yaz_search.search(cat_host, cat_db, query, start, limit) + return results, numhits diff --git a/conifer/libsystems/z3950/yaz_search.py b/conifer/libsystems/z3950/yaz_search.py index fcd2767..3eb1f74 100644 --- a/conifer/libsystems/z3950/yaz_search.py +++ b/conifer/libsystems/z3950/yaz_search.py @@ -43,7 +43,7 @@ def search(host, database, query, start=1, limit=10): numhits = int(server.match.group(1)) if start > numhits: warnings.warn('asked z3950 to start at %d, but only %d results.' % (start, numhits)) - return [] + return [], 0 # how many to present? At most 10 for now. to_show = min(numhits-1, limit) @@ -56,7 +56,7 @@ def search(host, database, query, start=1, limit=10): if err: warnings.warn('error during z3950 conversation.') server.close() - return [] + return [], 0 raw_records = [] err = None @@ -73,12 +73,11 @@ def search(host, database, query, start=1, limit=10): for rec in raw_records: try: rec = _marc_utf8_pattern.sub(_decode_marc_utf8, rec) - print type(rec) dct = marcxml_to_dictionary(rec) except 'x': raise rec parsed.append(dct) - return parsed + return parsed, numhits # decoding MARC \X.. UTF-8 patterns. diff --git a/conifer/syrup/views/items.py b/conifer/syrup/views/items.py index 0ffb38c..230565f 100644 --- a/conifer/syrup/views/items.py +++ b/conifer/syrup/views/items.py @@ -165,22 +165,19 @@ def item_add_cat_search(request, course_id, item_id): #---------- if request.method != 'POST': - return g.render('item/item_add_cat_search.xhtml', results=[], query='', - course=course, parent_item=parent_item) - - # POST handler - query = request.POST.get('query','').strip() - raw_pickitem = request.POST.get('pickitem', '').strip() - if not raw_pickitem: - # process the query. - assert query, 'must provide a query.' - start, limit = (1, 20) - results = lib_integration.cat_search(query, start, limit) + if not 'query' in request.GET: + return g.render('item/item_add_cat_search.xhtml', results=[], query='', + course=course, parent_item=parent_item) + query = request.GET.get('query','').strip() + start, limit = (int(request.GET.get(k,v)) for k,v in (('start',1),('limit',10))) + results, numhits = lib_integration.cat_search(query, start, limit) return g.render('item/item_add_cat_search.xhtml', results=results, query=query, + start=start, limit=limit, numhits=numhits, course=course, parent_item=parent_item) else: # User has selected an item; add it to course site. + raw_pickitem = request.POST.get('pickitem', '').strip() #fixme, this block copied from item_add. refactor. parent_item_id = item_id if parent_item_id == '0': @@ -197,10 +194,18 @@ def item_add_cat_search(request, course_id, item_id): pickitem = simplejson.loads(raw_pickitem) dublin = marcxml_dictionary_to_dc(pickitem) + # one last thing. If this picked item has an 856$9 field, then + # it's an electronic resource, not a physical item. In that + # case, we add it as a URL, not a PHYS. + if '8569' in pickitem: + dct = dict(item_type='URL', url=pickitem.get('856u')) + else: + dct = dict(item_type='PHYS') + item = course.item_set.create(parent_heading=parent_item, sort_order=next_order, title=dublin.get('dc:title','Untitled'), - item_type='PHYS') + **dct) item.save() for dc, value in dublin.items(): @@ -208,7 +213,7 @@ def item_add_cat_search(request, course_id, item_id): # store the whole darn MARC-dict as well (JSON) item.metadata_set.create(item=item, name='syrup:marc', value=raw_pickitem) item.save() - return HttpResponseRedirect('../../../%d/' % item.id) + return HttpResponseRedirect('../../../%d/meta' % item.id) #------------------------------------------------------------ diff --git a/conifer/templates/components/course.xhtml b/conifer/templates/components/course.xhtml index 9268873..304b62a 100644 --- a/conifer/templates/components/course.xhtml +++ b/conifer/templates/components/course.xhtml @@ -73,7 +73,7 @@ searchtext = _('search this course...')
  • Subheading
  • URL
  • Electronic Document
  • -
  • Physical Book/Document
  • +
  • Physical Item or Catalogued Electronic Item
  • diff --git a/conifer/templates/item/item_add_cat_search.xhtml b/conifer/templates/item/item_add_cat_search.xhtml index 249e9bb..bc24896 100644 --- a/conifer/templates/item/item_add_cat_search.xhtml +++ b/conifer/templates/item/item_add_cat_search.xhtml @@ -1,7 +1,7 @@ $(function() { $('.pagetable').tablesorter(); }); - @@ -24,24 +24,40 @@ dc_keys = ['dc:title', 'dc:creator', 'dc:publisher', 'dc:date'] ${course_banner(course)} ${nested_title(parent_item)}

    ${title}

    -
    + ${go_back_link()}
    - - +
    +

    + ${start}–${min(numhits, start+limit-1)} of ${numhits} results. + + Previous ${limit} + • + + + Next ${limit} + +

    +
    + ${page_control()} +
    - + +
    TitleAuthorPublisherPubDate
    #TitleAuthorPublisherPubDate
    ${resultnum+start}. ${dc.get('dc:title', '???')} details +

    + Electronic resource. view +

    ${dc.get(k) or '—'} @@ -63,5 +79,6 @@ dc_keys = ['dc:title', 'dc:creator', 'dc:publisher', 'dc:date']
    + ${page_control()}