[open-ils-commits] r1161 - in servres/trunk/conifer: syrup/views templates/components templates/unapi (gfawcett)
svn at svn.open-ils.org
svn at svn.open-ils.org
Wed Jan 5 21:35:54 EST 2011
Author: gfawcett
Date: 2011-01-05 21:35:52 -0500 (Wed, 05 Jan 2011)
New Revision: 1161
Modified:
servres/trunk/conifer/syrup/views/unapi.py
servres/trunk/conifer/templates/components/site.xhtml
servres/trunk/conifer/templates/unapi/formats.xml
Log:
added unapi support for non-physical items (uses RIS instead of MODS)
Modified: servres/trunk/conifer/syrup/views/unapi.py
===================================================================
--- servres/trunk/conifer/syrup/views/unapi.py 2011-01-05 21:17:36 UTC (rev 1160)
+++ servres/trunk/conifer/syrup/views/unapi.py 2011-01-06 02:35:52 UTC (rev 1161)
@@ -9,15 +9,56 @@
def unapi(request):
id = request.GET.get('id')
+ if not id:
+ return g.render_xml('unapi/formats.xml', item=None)
+ item = get_object_or_404(models.Item, pk=id)
format = request.GET.get('format')
if not format:
- return g.render_xml('unapi/formats.xml', id=id)
- elif format=='mods3':
- item = get_object_or_404(models.Item, pk=id)
+ return g.render_xml('unapi/formats.xml', item=item)
+ print (format, item.item_type)
+ if format=='mods3':
xml = item.marcxml
if xml:
doc = etree.fromstring(xml)
mods = xform(doc)
return HttpResponse(etree.tostring(mods),
content_type='application/xml')
+ elif format=='ris':
+ # for non-physical items (so we have no MARC to MODS-ify)
+ # FIXME: This is probably broken in a jillion ways.
+ ris = []
+ a = ris.append
+ a('TY - JOUR') # FIXME, should not be hardcoded.
+ a('ID - %s' % item.id)
+ a('T1 - %s' % item.title)
+ if item.source_title:
+ a('JF - %s' % item.source_title)
+ if item.author:
+ for author in [x.strip() for x in item.author.split(';')]:
+ a('A1 - %s' % author)
+ if item.volume:
+ a('VL - %s' % item.volume)
+ if item.issue:
+ a('IS - %s' % item.issue)
+ if item.publisher:
+ a('PB - %s' % item.publisher)
+ if item.published:
+ m = re.search(r'(\d{4})', item.published)
+ if m:
+ year = m.group(1)
+ a('PY - %s///' % year)
+ if item.pages:
+ pages = re.findall(r'(\d+)', item.pages)
+ if len(pages) > 0:
+ a('SP - %s' % pages[0])
+ if len(pages) > 1:
+ a('EP - %s' % pages[1])
+ a('UR - %s' % (item.url or item.item_url()))
+ a('ER - ')
+ ris = '\n'.join(ris)
+ print ris
+ return HttpResponse(ris, content_type='text/plain')
+
+
return HttpResponseNotFound()
+
Modified: servres/trunk/conifer/templates/components/site.xhtml
===================================================================
--- servres/trunk/conifer/templates/components/site.xhtml 2011-01-05 21:17:36 UTC (rev 1160)
+++ servres/trunk/conifer/templates/components/site.xhtml 2011-01-06 02:35:52 UTC (rev 1161)
@@ -32,7 +32,7 @@
class="itemtree">
<li py:for="item, subs in tree" py:with="forbidden=not item.copyright_status_ok()" class="item_${item.item_type} an_item ${forbidden and 'forbidden' or ''}"
id="item_${item.id}">
- <abbr py:if="item.marcxml" class="unapi-id" title="${item.id}"/>
+ <abbr py:if="not item.item_type=='HEADING'" class="unapi-id" title="${item.id}"/>
<div class="availability" py:if="item.item_type == 'PHYS'">
<?python
stat = callhook('item_status', item) if (item.item_type == 'PHYS') else None
Modified: servres/trunk/conifer/templates/unapi/formats.xml
===================================================================
--- servres/trunk/conifer/templates/unapi/formats.xml 2011-01-05 21:17:36 UTC (rev 1160)
+++ servres/trunk/conifer/templates/unapi/formats.xml 2011-01-06 02:35:52 UTC (rev 1161)
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<formats xmlns:py="http://genshi.edgewall.org/"
xmlns:xi="http://www.w3.org/2001/XInclude"
- py:attrs="{'id': id}">
- <format name='mods3' type='application/xml'
+ py:attrs="{'id': item and item.id}">
+ <format py:if="item and item.marcxml" name='mods3' type='application/xml'
namespace_uri='http://www.loc.gov/mods/v3'
docs='http://www.loc.gov/mods/'
schema_location='http://www.loc.gov/standards/mods/v3/mods-3-1.xsd'/>
+ <format py:if="item and (not item.marcxml)" name="ris" type="text/plain"/>
</formats>
More information about the open-ils-commits
mailing list