From 6d43b63ea61e43d43174d86a495395dffceaebef Mon Sep 17 00:00:00 2001 From: artunit Date: Tue, 17 Mar 2009 13:16:45 +0000 Subject: [PATCH] browsing z39.50 using paginator git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@193 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/syrup/views.py | 56 ++++++++++++++++++++++++++------- conifer/templates/admin/index.xhtml | 3 +- conifer/templates/paginate.xhtml | 8 ++--- conifer/templates/zsearch_results.xhtml | 12 +++++-- 4 files changed, 60 insertions(+), 19 deletions(-) diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index e392d9c..9816038 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -811,24 +811,47 @@ def search(request, in_course=None): 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: @@ -839,11 +862,11 @@ def zsearch(request): # 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]]) @@ -857,10 +880,19 @@ def zsearch(request): 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()) diff --git a/conifer/templates/admin/index.xhtml b/conifer/templates/admin/index.xhtml index 466f907..ebe9aa2 100644 --- a/conifer/templates/admin/index.xhtml +++ b/conifer/templates/admin/index.xhtml @@ -17,7 +17,8 @@ title = _('Administrative Options')
  • Items
  • News Items
  • Manage Z39.50 Targets
  • -
  • Search Z39.50 Targets
  • + +
  • Search Z39.50 Targets
  • diff --git a/conifer/templates/paginate.xhtml b/conifer/templates/paginate.xhtml index 4f29a33..2fe6e41 100644 --- a/conifer/templates/paginate.xhtml +++ b/conifer/templates/paginate.xhtml @@ -2,7 +2,7 @@ xmlns:py="http://genshi.edgewall.org/" xmlns:xi="http://www.w3.org/2001/XInclude" py:strip=""> -
    @@ -18,16 +18,16 @@
    - Previous + Previous ${pp} + href=".?page=${pp}&count=${count}&query=${query}&target=${target}">${pp} - Next + Next
    diff --git a/conifer/templates/zsearch_results.xhtml b/conifer/templates/zsearch_results.xhtml index 05aac02..dc269b6 100644 --- a/conifer/templates/zsearch_results.xhtml +++ b/conifer/templates/zsearch_results.xhtml @@ -15,14 +15,22 @@ title_list = collector -

    ${title}

    - + +

    ${title}

    + + Name + + + ${item[1]} + + ${pagetable(paginator, count, pagerow, pageheader, tquery, target)} -- 2.11.0