From: gfawcett Date: Sun, 5 Apr 2009 18:33:55 +0000 (+0000) Subject: various & sundry z3950 and MARC-related improvements X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=e672a52bf14c9c159ad54fcf6a1b900a79d6ca9e;p=Syrup.git various & sundry z3950 and MARC-related improvements Search queries no longer need explicit @and prefixes (they are now implicit); a cleaner phys-item search-results page. Still only max 10 results showing, though. various visual improvements. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@275 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- diff --git a/conifer/TODO b/conifer/TODO index 188c0b0..1b73ba8 100644 --- a/conifer/TODO +++ b/conifer/TODO @@ -13,6 +13,8 @@ IMPORTANT: * People should be able to register themselves into open courses. That is, actually become a member of them. +* accented characters in z3950 queries seem to fail. More tests needed. + MAYBE: * Generating barcodes in emails, printable screens? (3 of 9 enough?) diff --git a/conifer/libsystems/z3950/marcxml.py b/conifer/libsystems/z3950/marcxml.py index 1a208fb..741556a 100644 --- a/conifer/libsystems/z3950/marcxml.py +++ b/conifer/libsystems/z3950/marcxml.py @@ -38,8 +38,16 @@ def marcxml_dictionary_to_dc(dct): value = dct.get(marc) if value: out[dc] = value - if '245b' in meta and 'dc:title' in out: - out['dc:title'] += (' %s' % meta['245b']) + title = out.get('dc:title') + if title: + if '245b' in dct: + title += (' %s' % dct['245b']) + # if title ends with a single character, strip it. usually a + # spurious punctuation character. + init, last = title.rsplit(' ',1) + if len(last) == 1: + title = init + out['dc:title'] = title return out diff --git a/conifer/libsystems/z3950/yaz_search.py b/conifer/libsystems/z3950/yaz_search.py index 242dd62..8f1c996 100644 --- a/conifer/libsystems/z3950/yaz_search.py +++ b/conifer/libsystems/z3950/yaz_search.py @@ -12,14 +12,26 @@ from marcxml import marcxml_to_dictionary LOG = sys.stderr #None # for pexpect debugging, try LOG = sys.stderr YAZ_CLIENT = 'yaz-client' -GENERAL_TIMEOUT = 20 -PRESENT_TIMEOUT = 30 +GENERAL_TIMEOUT = 40 +PRESENT_TIMEOUT = 60 def search(host, database, query, start=1, limit=None): + # first, let's look at our query. I'm assuming @prefix queries for + # now, so we need to put queries in that form if they aren't + # yet. I'm also assuming query is a conjunction (terms are + # AND'ed) if a '@' query isn't provided. + if not query.startswith('@'): + words = [w for w in query.split(' ') if w.strip()] + tmp = (['@and'] * (len(words) - 1)) + words + query = ' '.join(tmp) + query = query.encode('utf-8') # is this okay? Is it enough?? + server = pexpect.spawn('yaz-client', timeout=GENERAL_TIMEOUT, logfile=LOG) #server.expect('Z>') - for line in ('open %s' % host, 'base %s' % database, 'format xml'): + for line in ('open %s' % host, + 'base %s' % database, + 'format xml'): server.sendline(line) server.expect('Z>') diff --git a/conifer/static/main.css b/conifer/static/main.css index 8be1ac7..32f787c 100644 --- a/conifer/static/main.css +++ b/conifer/static/main.css @@ -245,6 +245,7 @@ p.todo, div.todo { background-color: #fdd; padding: 6; margin: 12; border-left: .metadata_table tbody td { padding: 8; border: #ddd 1px solid; } +.metadata_table input { width: 600; } .metadata_table tbody th { background-color: #eee; @@ -271,4 +272,4 @@ li.sort_item:hover { background-color: #eee; } ul.heading_tree li { list-style: none; } ul.heading_tree { margin: 0; padding-left: 0; } -ul.heading_tree ul { margin: 0; padding-left: 25; } \ No newline at end of file +ul.heading_tree ul { margin: 0; padding-left: 25; } diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index 671ee19..0b77000 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -275,23 +275,6 @@ def z3950_test(request): res_str = "" . join(collector) return g.render('z3950_test.xhtml', res_str=res_str) -def graham_z3950_test(request): - raise NotImplementedError # delete this function, its template, etc. - query = request.GET.get('query', '@and "Denis" "Gravel"') - from conifer.libsystems.z3950 import yaz_search - from conifer.libsystems.evergreen.item_status import lookup_availability - host, db, query = ('dwarf.cs.uoguelph.ca:2210', 'conifer', query) - #host, db, query = ('z3950.loc.gov:7090', 'VOYAGER', '@attr 1=4 @attr 4=1 "dylan"') - results = yaz_search.search(host, db, query) - for result in results: - bibid = result.get('901c') - if bibid: - # it would be better to do these asynchronously. - avail = lookup_availability(bibid) - if avail: - result['avail'] = avail - return g.render('graham_z3950_test.xhtml', results=results, query=query) - def browse(request, browse_option=''): #the defaults should be moved into a config file or something... page_num = int(request.GET.get('page', 1)) @@ -728,7 +711,7 @@ def item_add(request, course_id, item_id): @instructors_only 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') + return g.render('item_add_cat_search.xhtml', results=[], query='') # POST handler query = request.POST.get('query','').strip() @@ -743,7 +726,8 @@ def item_add_cat_search(request, course_id, item_id): # 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': + if parent_item_id == '0': + # no heading (toplevel) parent_item = None course = get_object_or_404(models.Course, pk=course_id) else: @@ -757,14 +741,13 @@ def item_add_cat_search(request, course_id, item_id): dublin = marcxml_dictionary_to_dc(pickitem) item = course.item_set.create(parent_heading=parent_item, - title=pickitem.get('245a', 'Untitled'), + title=dublin.get('dc:title','Untitled'), item_type='PHYS') item.save() for dc, value in dublin.items(): md = item.metadata_set.create(item=item, name=dc, value=value) - # store the whole darn MARC-dict as well. - json = simplejson.dumps(pickitem) + # 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) diff --git a/conifer/templates/components/course.xhtml b/conifer/templates/components/course.xhtml index 779b331..712aa8a 100644 --- a/conifer/templates/components/course.xhtml +++ b/conifer/templates/components/course.xhtml @@ -93,7 +93,7 @@ searchtext = _('search this course...')

Show more attributes

${Markup(metadata_formset.management_form)} - +
diff --git a/conifer/templates/graham_z3950_test.xhtml b/conifer/templates/graham_z3950_test.xhtml deleted file mode 100644 index 0ba131f..0000000 --- a/conifer/templates/graham_z3950_test.xhtml +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - ${title} - - - - -

${title}

-
- - - -

show more detail

-
- - - - - - - - - - - - - - -
${title}${res[k]}
Availability -
- ${'%s = %s' % (k,v)} -
-
${k}${res[k]}
- - diff --git a/conifer/templates/item_add_cat_search.xhtml b/conifer/templates/item_add_cat_search.xhtml index 2681c1a..ed6f011 100644 --- a/conifer/templates/item_add_cat_search.xhtml +++ b/conifer/templates/item_add_cat_search.xhtml @@ -1,8 +1,8 @@ ${title} -