[open-ils-commits] r191 - in servres/trunk/conifer: syrup templates templates/admin (artunit)
svn at svn.open-ils.org
svn at svn.open-ils.org
Mon Mar 16 23:31:21 EDT 2009
Author: artunit
Date: 2009-03-16 23:31:19 -0400 (Mon, 16 Mar 2009)
New Revision: 191
Added:
servres/trunk/conifer/templates/zsearch.xhtml
servres/trunk/conifer/templates/zsearch_results.xhtml
Modified:
servres/trunk/conifer/syrup/admin.py
servres/trunk/conifer/syrup/models.py
servres/trunk/conifer/syrup/urls.py
servres/trunk/conifer/syrup/views.py
servres/trunk/conifer/templates/admin/index.xhtml
Log:
adding some z39.50 searching support
Modified: servres/trunk/conifer/syrup/admin.py
===================================================================
--- servres/trunk/conifer/syrup/admin.py 2009-03-16 22:51:35 UTC (rev 190)
+++ servres/trunk/conifer/syrup/admin.py 2009-03-17 03:31:19 UTC (rev 191)
@@ -23,5 +23,5 @@
# admin.site.register(value)
for m in [LibraryUnit, ServiceDesk, Member, Department, Course, Term, UserProfile, NewsItem,
- Item]:
+ Item, Target]:
admin.site.register(m)
Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py 2009-03-16 22:51:35 UTC (rev 190)
+++ servres/trunk/conifer/syrup/models.py 2009-03-17 03:31:19 UTC (rev 191)
@@ -391,6 +391,11 @@
# Physical Item properties
+ '''
+ want to add enumeration and chronology info
+ '''
+ # enumeration = m.CharField(max_length=255, blank=True, null=True)
+ # chronology = m.CharField(max_length=255, blank=True, null=True)
call_number = m.CharField(max_length=30, blank=True, null=True) # long enough?
barcode = m.CharField(max_length=30, blank=True, null=True) # long enough?
@@ -506,3 +511,17 @@
return Markup(self.body)
elif self.encoding == 'markdown':
return Markup(do_markdown(self.body))
+
+#----------------------------------------------------------------------
+# Z39.50 Support
+
+class Target(m.Model):
+ name = m.CharField(max_length=100)
+ host = m.CharField(max_length=50)
+ db = m.CharField(max_length=50)
+ port = m.IntegerField(default=210)
+ syntax = m.CharField(max_length=10,default='USMARC')
+ active = m.BooleanField(default=True)
+
+ def __unicode__(self):
+ return self.name
Modified: servres/trunk/conifer/syrup/urls.py
===================================================================
--- servres/trunk/conifer/syrup/urls.py 2009-03-16 22:51:35 UTC (rev 190)
+++ servres/trunk/conifer/syrup/urls.py 2009-03-17 03:31:19 UTC (rev 191)
@@ -18,6 +18,7 @@
(r'^z3950test/$', 'z3950_test'),
(r'^opencourse/$', 'open_courses'),
(r'^search/$', 'search'),
+ (r'^zsearch/$', 'zsearch'),
(r'^instructors/$', 'instructors'),
(r'^departments/$', 'departments'),
(r'^course/(?P<course_id>\d+)/$', 'course_detail'),
@@ -39,6 +40,7 @@
(r'^admin/items/' + GENERIC_REGEX, 'admin_items'),
(r'^admin/depts/' + GENERIC_REGEX, 'admin_depts'),
(r'^admin/news/' + GENERIC_REGEX, 'admin_news'),
+ (r'^admin/targets/' + GENERIC_REGEX, 'admin_targets'),
# (r'^admin/terms/(?P<term_id>\d+)/$', 'admin_term_edit'),
# (r'^admin/terms/(?P<term_id>\d+)/delete$', 'admin_term_delete'),
# (r'^admin/terms/$', 'admin_term'),
Modified: servres/trunk/conifer/syrup/views.py
===================================================================
--- servres/trunk/conifer/syrup/views.py 2009-03-16 22:51:35 UTC (rev 190)
+++ servres/trunk/conifer/syrup/views.py 2009-03-17 03:31:19 UTC (rev 191)
@@ -60,7 +60,7 @@
# for Z39.50 support, not sure whether this is the way to go yet but
# as generic as it gets
- from PyZ3950 import zoom
+ from PyZ3950 import zoom, zmarc
except:
warnings.warn('Could not load Z39.50 support.')
@@ -210,10 +210,11 @@
def z3950_test(request):
conn = zoom.Connection ('z3950.loc.gov', 7090)
+ #conn = zoom.Connection ('webvoy.uwindsor.ca', 9000)
conn.databaseName = 'VOYAGER'
conn.preferredRecordSyntax = 'USMARC'
query = zoom.Query ('CCL', 'ti="1066 and all that"')
- # print("connecting...")
+ print("connecting...")
res = conn.search (query)
collector = []
for r in res:
@@ -804,7 +805,65 @@
return g.render('search_results.xhtml', **locals())
+#-----------------------------------------------------------------------------
+# Z39.50 support
+def zsearch(request):
+ '''
+ '''
+ if 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'])
+ 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...")
+ res = conn.search (query)
+ collector = []
+
+ for r in res[start: start + count]:
+ if r.syntax <> 'USMARC':
+ collector.append ((None, 'Unsupported syntax: ' + r.syntax, None))
+ else:
+ raw = r.data
+
+ # Convert to MARC
+ marcdata = zmarc.MARC(raw)
+ # print marcdata
+
+ # Convert to 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')
+
+ bibid = marcdata.fields[1][0]
+ title = " ".join ([v[1] for v in marcdata.fields [245][0][2]])
+
+ # And then Amara XML tools would allow using xpath
+ '''
+ title = ""
+ doc = binderytools.bind_string(marcxml)
+ t = doc.xml_xpath("//datafield[@tag='245']/subfield[@code='a']")
+ if len(title)>0:
+ title = t[0].xml_text_content()
+ '''
+
+ collector.append ((bibid, title))
+ conn.close ()
+ # print("done searching...")
+
+ return g.render('zsearch_results.xhtml', **locals())
+
+
#-----------------------------------------------------------------------------
# Administrative options
@@ -883,6 +942,21 @@
clean_author = strip_and_nonblank('author')
admin_items = generic_handler(ItemForm, decorator=admin_only)
+
+class TargetForm(ModelForm):
+ class Meta:
+ model = models.Target
+
+ class Index:
+ title = _('Targets')
+ all = models.Target.objects.order_by('name').all
+ cols = ['name', 'host']
+ links = [0,1]
+
+ clean_name = strip_and_nonblank('name')
+ clean_host = strip_and_nonblank('host')
+
+admin_targets = generic_handler(TargetForm, decorator=admin_only)
###
Modified: servres/trunk/conifer/templates/admin/index.xhtml
===================================================================
--- servres/trunk/conifer/templates/admin/index.xhtml 2009-03-16 22:51:35 UTC (rev 190)
+++ servres/trunk/conifer/templates/admin/index.xhtml 2009-03-17 03:31:19 UTC (rev 191)
@@ -16,6 +16,7 @@
<li><a href="courses/">Courses</a></li>
<li><a href="items/">Items</a></li>
<li><a href="news/">News Items</a></li>
+ <li><a href="targets/">Z39.50 Targets</a></li>
</ul>
</body>
</html>
Added: servres/trunk/conifer/templates/zsearch.xhtml
===================================================================
--- servres/trunk/conifer/templates/zsearch.xhtml (rev 0)
+++ servres/trunk/conifer/templates/zsearch.xhtml 2009-03-17 03:31:19 UTC (rev 191)
@@ -0,0 +1,23 @@
+<?python
+title = _('Search via Z39.50')
+targets = targets_list
+?>
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:py="http://genshi.edgewall.org/">
+<xi:include href="master.xhtml"/>
+<head>
+ <title>${title}</title>
+</head>
+<body>
+ <h1>${title}</h1>
+ <form py:if="targets" action="." method="POST">
+ <select name="target" py:for="target in targets">
+ <option>${target.name}</option>
+ </select>
+ Title: <input id="ztitle" name="ztitle" maxlength="100" size="100" type="text"/>
+ <p><input type="submit" value="Search target"/></p>
+ </form>
+ <div class="gap"/>
+</body>
+</html>
Added: servres/trunk/conifer/templates/zsearch_results.xhtml
===================================================================
--- servres/trunk/conifer/templates/zsearch_results.xhtml (rev 0)
+++ servres/trunk/conifer/templates/zsearch_results.xhtml 2009-03-17 03:31:19 UTC (rev 191)
@@ -0,0 +1,28 @@
+<?python
+title = _('Z39.50 Search Results')
+title_list = collector
+?>
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:py="http://genshi.edgewall.org/">
+<xi:include href="master.xhtml"/>
+<xi:include href="paginate.xhtml"/>
+<head>
+ <title>${title}</title>
+ <script type="text/javascript">
+ <!-- !This ought to be in paginate.xhtml, not here. how to do? -->
+ $(function() { $('.pagetable').tablesorter(); });
+ </script>
+</head>
+<body>
+ <h1>${title}</h1>
+
+ <table py:if="title_list" width="100%">
+ <tr py:for="item in title_list">
+ <td>${item[0]}</td>
+ <td>${item[1]}</td>
+ </tr>
+ </table>
+
+</body>
+</html>
More information about the open-ils-commits
mailing list