def zsearch(request):
'''
'''
- if request.method == 'GET':
+
+ if request.GET.get('page')==None:
+ print("nope")
+ page_num = int(request.GET.get('page', 1))
+ count = int(request.POST.get('count', 5))
+
+ if request.GET.get('page')==None and request.method == 'GET':
targets_list = models.Target.objects.filter(active=True).order_by('name')
targets_len = len(targets_list)
return g.render('zsearch.xhtml', **locals())
else:
- start = int(request.POST.get('start', 1))
- count = int(request.POST.get('count', 5))
- search_target= models.Target.objects.get(name=request.POST['target'])
+
+ target = request.GET.get('target')
+ if request.method == 'POST':
+ target = request.POST['target']
+ print("target is %s" % target)
+
+ tquery = request.GET.get('query')
+ if request.method == 'POST':
+ tquery = request.POST['ztitle']
+ search_target= models.Target.objects.get(name=target)
conn = zoom.Connection (search_target.host, search_target.port)
conn.databaseName = search_target.db
conn.preferredRecordSyntax = search_target.syntax
- # query = zoom.Query ('CCL', '%s="%s"' % ('ti','1066 and all that'))
- query = zoom.Query ('CCL', '%s="%s"' % ('ti',request.POST['ztitle']))
- # print("connecting...")
+ query = zoom.Query ('CCL', '%s="%s"' % ('ti',tquery))
res = conn.search (query)
+ print("results are %d" % len(res))
collector = []
- for r in res[start: start + count]:
+ '''
+ need to add some plumbing for scan if possible
+ suspect this is too much overhead, though it could just be
+ the target z39.50 server that is slow
+ '''
+ # we fudge this since it has more overhead
+ start = (page_num - 1) * count
+ end = (page_num * count) + 1
+ for r in res[0: start]:
+ print("none")
+ collector.append ((None, None))
+ for r in res[start + 1: end]:
if r.syntax <> 'USMARC':
collector.append ((None, 'Unsupported syntax: ' + r.syntax, None))
else:
# print marcdata
# Convert to MARCXML
- marcxml = marcdata.toMARCXML()
- print marcxml
+ # marcxml = marcdata.toMARCXML()
+ # print marcxml
# How to Remove non-ascii characters (in case this is a problem)
- marcxmlascii = unicode(marcxml, 'ascii', 'ignore').encode('ascii')
+ #marcxmlascii = unicode(marcxml, 'ascii', 'ignore').encode('ascii')
bibid = marcdata.fields[1][0]
title = " ".join ([v[1] for v in marcdata.fields [245][0][2]])
title = t[0].xml_text_content()
'''
- collector.append ((bibid, title))
+ # collector.append ((bibid, title))
+ #this is not a good situation but will leave for now
+ collector.append ((bibid, unicode(title, 'ascii', 'ignore')))
+ if end < len(res):
+ for r in res[end + 1:len(res)]:
+ print("end none")
+ collector.append ((None, None))
conn.close ()
# print("done searching...")
+ paginator = Paginator(collector, count)
+ print("page_num is %d" % page_num)
+ print("returning...")
return g.render('zsearch_results.xhtml', **locals())
xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude"
py:strip="">
-<div py:def="pagetable(paginator, count, pagerow, pagehead=None)"
+<div py:def="pagetable(paginator, count, pagerow, pagehead=None, query=None, target=None)"
py:with="page = paginator.page(page_num)">
<table class="pagetable" py:with="cls = cycle(('odd', 'even'))">
<thead py:if="pagehead">
</table>
<div class="pagination_controls" py:if="paginator.num_pages > 1">
<span py:if="page.has_previous()" class="prev">
- <a href=".?page=${page.previous_page_number()}&count=${count}">Previous</a>
+ <a href=".?page=${page.previous_page_number()}&count=${count}&query=${query}&target=${target}">Previous</a>
</span>
<span class="nums">
<span py:for="pp in range(1, 1+paginator.num_pages)">
<a style="font-weight: ${pp == page_num and 'bold' or 'normal'}"
- href=".?page=${pp}&count=${count}">${pp}</a>
+ href=".?page=${pp}&count=${count}&query=${query}&target=${target}">${pp}</a>
</span>
</span>
<span py:if="page.has_next()" class="next">
- <a href=".?page=${page.next_page_number()}&count=${count}">Next</a>
+ <a href=".?page=${page.next_page_number()}&count=${count}&query=${query}&target=${target}">Next</a>
</span>
</div>
</div>