[open-ils-commits] r1141 - in servres/trunk/conifer: syrup/views templates/item (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Dec 28 17:17:56 EST 2010


Author: gfawcett
Date: 2010-12-28 17:17:51 -0500 (Tue, 28 Dec 2010)
New Revision: 1141

Modified:
   servres/trunk/conifer/syrup/views/items.py
   servres/trunk/conifer/templates/item/item_add_url.xhtml
Log:
experimental: import URL item from RIS citation

I'd like to show this to the Leddy reserves staff, and see if it might
expedite their workflow. Maybe they are using (or can use) RefWorks or Zotero
to process new items?

Modified: servres/trunk/conifer/syrup/views/items.py
===================================================================
--- servres/trunk/conifer/syrup/views/items.py	2010-12-28 21:13:47 UTC (rev 1140)
+++ servres/trunk/conifer/syrup/views/items.py	2010-12-28 22:17:51 UTC (rev 1141)
@@ -2,6 +2,7 @@
 from conifer.plumbing.hooksystem import *
 from conifer.syrup               import integration
 from xml.etree                   import ElementTree as ET
+from collections                 import defaultdict
 
 @members_only
 def item_detail(request, site_id, item_id):
@@ -95,9 +96,46 @@
         # fixme, this will need refactoring. But not yet.
         author = request.user.get_full_name() or request.user.username
         item = models.Item()    # dummy object
-            
+        POST = request.POST.copy()
+        def clean(key):
+            return POST.get(key, '').strip()
+
+        # Just for fun and experimentation: a basic Refworks/RIS importer. If
+        # 'ris' appears in the POST, parse it as an RIS citation and expand
+        # its components into the POST object.
+
+        if clean('ris'):
+            # use RIS (refworks) to populate fields
+            pat = re.compile('^([A-Z][A-Z0-9])  - (.*)$')
+            tmp = [x.groups() for x in 
+                   [pat.match(line.strip()) for line in POST['ris'].split('\r\n')]
+                   if x is not None]
+            ris = defaultdict(list)
+            for k, v in tmp:
+                ris[k].append(v)
+            def update(field, risfield, xlate=lambda x: x):
+                if risfield in ris:
+                    replacement = '; '.join(ris[risfield])
+                    POST[field] = xlate(replacement)
+            def space_comments(names):
+                # RIS doesn't put spaces after commas in names
+                return re.sub(',(?=[^ ])', ', ', names)
+
+            update('title', 'TI') # first try TI, then T1
+            update('title', 'T1')
+            update('source_title', 'JO') # first try JO, then JF
+            update('source_title', 'JF')
+            update('author', 'A1', space_comments)
+            update('url', 'UR')
+            update('volume', 'VL')
+            update('issue', 'IS')
+            if 'SP' in ris and 'EP' in ris:
+                POST['pages'] = ris['SP'][0] + '-' + ris['EP'][0]
+            update('published', 'PY', lambda v: v.split('/')[0])
+
+
         if item_type == 'HEADING':
-            title = request.POST.get('title', '').strip()
+            title = clean('title')
             if not title:
                 # fixme, better error handling.
                 return HttpResponseRedirect(request.get_full_path())
@@ -110,12 +148,13 @@
                     )
                 item.save()
         elif item_type == 'URL':
-            title = request.POST.get('title', '').strip()
-            url = request.POST.get('url', '').strip()
-            author = request.POST.get('author', '').strip()
-            publisher = request.POST.get('publisher', '').strip()
-            published = request.POST.get('published', '').strip()
+            title = clean('title')
+            url = clean('url')
+            author = clean('author')
+            publisher = clean('publisher')
+            published = clean('published')
             if not (title and url):
+                raise Exception(locals())
                 # fixme, better error handling.
                 return HttpResponseRedirect(request.get_full_path())
             else:
@@ -127,16 +166,22 @@
                     url = url,
                     author = author,
                     publisher = publisher,
-                    published = published)
+                    published = published,
+                    source_title=clean('source_title'),
+                    volume=clean('volume'),
+                    issue=clean('issue'),
+                    pages=clean('pages'),
+                    isbn=clean('isbn'),
+                    )
                 item.save()
         elif item_type == 'ELEC':
-            title = request.POST.get('title', '').strip()
+            title = clean('title')
             upload = request.FILES.get('file')
             if not (title and upload):
                 # fixme, better error handling.
                 return HttpResponseRedirect(request.get_full_path())
 
-            data = dict((k.encode('ascii'), v.strip()) for k, v in request.POST.items())
+            data = dict((k.encode('ascii'), v.strip()) for k, v in POST.items())
             if data['author2']:
                 data['author'] = '%s; %s' % (data['author1'], data['author2'])
             else:

Modified: servres/trunk/conifer/templates/item/item_add_url.xhtml
===================================================================
--- servres/trunk/conifer/templates/item/item_add_url.xhtml	2010-12-28 21:13:47 UTC (rev 1140)
+++ servres/trunk/conifer/templates/item/item_add_url.xhtml	2010-12-28 22:17:51 UTC (rev 1141)
@@ -22,8 +22,16 @@
     ${site_banner(site)}
     ${nested_title(parent_item)}
     ${offer_to_delete(item)}
+    <div py:if="not is_edit" style="float:right;">
+      <a href="javascript:void($('#refworks,.metadata_table').toggle());">Import RefWorks/RIS citation</a>
+    </div>
     <h2>${title}</h2>
+
     <form action=".?item_type=${item_type}" method="POST">
+      <div id="refworks" style="display:none;">
+	<p style="font-size: 90%;">Paste the Refworks/RIS citation in the space below. Note, the citation must include a "UR" (URL) attribute. (Tip: RIS citations can be dragged and dropped from Zotero; ask Graham for details.)</p>
+	<textarea name="ris" style="width: 100%; height: 12em;"/>
+      </div>
       <table class="metadata_table">
 	<tbody>
 	<tr><th>URL</th><td><input type="text" name="url" value="${item.url}"/></td></tr>



More information about the open-ils-commits mailing list