From 18e89ba1bda5858fe07d717148994906c0e387ea Mon Sep 17 00:00:00 2001 From: gfawcett Date: Thu, 6 Jan 2011 02:35:52 +0000 Subject: [PATCH] added unapi support for non-physical items (uses RIS instead of MODS) git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@1161 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/syrup/views/unapi.py | 47 ++++++++++++++++++++++++++++++--- conifer/templates/components/site.xhtml | 2 +- conifer/templates/unapi/formats.xml | 5 ++-- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/conifer/syrup/views/unapi.py b/conifer/syrup/views/unapi.py index f26ebc1..56c84cc 100644 --- a/conifer/syrup/views/unapi.py +++ b/conifer/syrup/views/unapi.py @@ -9,15 +9,56 @@ xform = etree.XSLT(stylesheet) 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() + diff --git a/conifer/templates/components/site.xhtml b/conifer/templates/components/site.xhtml index b0b5d19..7d9cc92 100644 --- a/conifer/templates/components/site.xhtml +++ b/conifer/templates/components/site.xhtml @@ -32,7 +32,7 @@ searchtext = _('search this site...') class="itemtree">
  • - +
    - + + -- 2.11.0