* 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.
> 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.
+
# 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
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)
if err:
warnings.warn('error during z3950 conversation.')
server.close()
- return []
+ return [], 0
raw_records = []
err = None
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.
#----------
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':
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():
# 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)
#------------------------------------------------------------
<li><a href="${prefix}add/?item_type=HEADING">Subheading</a></li>
<li><a href="${prefix}add/?item_type=URL">URL</a></li>
<li><a href="${prefix}add/?item_type=ELEC">Electronic Document</a></li>
- <li><a href="${prefix}add/?item_type=PHYS">Physical Book/Document</a></li>
+ <li><a href="${prefix}add/?item_type=PHYS">Physical Item or Catalogued Electronic Item</a></li>
</ul>
</div>
<?python
from django.utils.simplejson import dumps
from conifer.libsystems.z3950.marcxml import marcxml_dictionary_to_dc as to_dublin
-title = _('Add physical item: Catalogue search')
+title = _('Add physical or electronic item, by catalogue search')
dc_keys = ['dc:title', 'dc:creator', 'dc:publisher', 'dc:date']
?>
<html xmlns="http://www.w3.org/1999/xhtml"
<!-- !This ought to be in paginate.xhtml, not here. how to do? -->
$(function() { $('.pagetable').tablesorter(); });
</script>
- <script py:if="request.method != 'POST'"> <!-- !focus on query box if nothing to scroll. -->
+ <script py:if="not 'query' in request.GET"> <!-- !focus on query box if nothing to scroll. -->
$(function() { $('#query').focus(); });
</script>
</head>
${course_banner(course)}
${nested_title(parent_item)}
<h2>${title}</h2>
- <form method="POST" action=".">
+ <form method="GET" action=".">
<input type="text" id="query" name="query" value="${query}"
style="font-size: larger; width: 600px;"/>
<input type="submit" value="Search"/>
${go_back_link()}
</form>
-
- <table class="pagetable" py:if="request.method == 'POST'">
+ <div py:def="page_control" py:if="results">
+ <p>
+ ${start}–${min(numhits, start+limit-1)} of ${numhits} results.
+ <span py:if="start-limit>0">
+ <a href=".?query=${query}&start=${start-limit}&limit=${limit}">Previous ${limit}</a>
+ •
+ </span>
+ <span py:if="start+limit<numhits">
+ <a href=".?query=${query}&start=${start+limit}&limit=${limit}">Next ${limit}</a>
+ </span>
+ </p>
+ </div>
+ ${page_control()}
+ <table class="pagetable" py:if="'query' in request.GET">
<thead>
- <tr><th>Title</th><th>Author</th><th>Publisher</th><th>PubDate</th></tr>
+ <tr><th>#</th><th>Title</th><th>Author</th><th>Publisher</th><th>PubDate</th></tr>
</thead>
<tbody py:for="resultnum, res in enumerate(results)"
py:with="dc=to_dublin(res)">
<tr>
+ <td>${resultnum+start}.</td>
<td>
${dc.get('dc:title', '???')}
<a href="javascript:$('#full_${resultnum}').toggle(); void(0);">details</a>
+ <p py:if="res.get('8569')" style="margin: 8px 0; font-size: 90%; color: darkred;">
+ Electronic resource. <a href="${res.get('856u')}">view</a>
+ </p>
</td>
<td py:for="k in dc_keys[1:]">${dc.get(k) or '—'}</td>
<td>
</tr>
</tbody>
</table>
+ ${page_control()}
</body>
</html>