Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

Commit

Permalink
basic COinS citation logic to allow harvesting items via Zotero #131
Browse files Browse the repository at this point in the history
  • Loading branch information
rlskoeser committed Aug 9, 2013
1 parent ca6d32c commit be7c13e
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
33 changes: 32 additions & 1 deletion smartstash/core/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

import urllib

class DisplayItem(object):
# common item to be used for display
Expand Down Expand Up @@ -27,6 +27,37 @@ def __init__(self, **kwargs):
def __repr__(self):
return u'<%s %s>' % (self.title, self.thumbnail or '<no url>')

@property
def coins_citation_info(self):
# generate a dictionary with info to build COinS citation
info = {
'rfr_id': 'info:sid/serendipomatic.org', # referrer id is recommended
'rft_val_fmt': 'info:ofi/fmt:kev:mtx:dc', # think this basically means we are using Dublin Core metadata
'rft.identifier': self.url
}
if self.title is not None:
info['rft.title'] = self.title
if self.date is not None:
info['rft.date'] = self.date

# may not be exact mapping; for books, this is place of publication
if self.location is not None:
info['rft.place'] = self.location
if self.source is not None:
info['rft.source'] = self.source
if self.format is not None:
info['rft.format'] = self.format

return info


@property
def coins_citation(self):
# COinS citation for this item to be embedded in the title attribute of a span
return 'ctx_ver=Z39.88-2004&' + \
'&'.join(['%s=%s' % (k, urllib.quote(v))
for k, v in self.coins_citation_info.iteritems()])


# common result item
'''
Expand Down
4 changes: 4 additions & 0 deletions smartstash/core/templates/core/view.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@
</div>
{% endif %}
</div>
{# span with citation information as COinS for zotero harvest #}
<span class="Z3988" title="{{ item.coins_citation }}"></span>


</div>

<!-- Change the number in the add filter depending on the number of tabindexes required before results. -->
Expand Down
44 changes: 43 additions & 1 deletion smartstash/core/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,51 @@
"""

from django.test import TestCase

from smartstash.core.forms import InputForm
from smartstash.core.models import DisplayItem

class FormTest(TestCase):

def test_whitespace_validation(self):
form = InputForm({'text': " "})
self.assertFalse(form.is_valid())
self.assertFalse(form.is_valid())


class DisplayItemTest(TestCase):

def test_coins_citation_info(self):
# minimal record
item = DisplayItem(title='Hippo', url='http://some.url/to/a/hippo/pic')

info = item.coins_citation_info
self.assert_('rfr_id' in info, 'referrer id should be set in COinS info')
self.assert_('rft_val_fmt' in info, 'format is specified in COinS info')
self.assertEqual(item.title, info['rft.title'])
self.assertEqual(item.url, info['rft.identifier'])

for key in ['rft.date', 'rft.place', 'rft.source', 'rft.format']:
self.assert_(key not in info,
'unavailable data should not be set in COinS info')

# add all fields to simulate a complete record
item.date = '1887'
item.format = 'Image'
item.source = 'Smithsonian'
item.location = 'USA'

info = item.coins_citation_info
self.assertEqual(item.date, info['rft.date'])
self.assertEqual(item.format, info['rft.format'])
self.assertEqual(item.source, info['rft.source'])
self.assertEqual(item.location, info['rft.place'])

def test_coins_citation(self):
# minimal record
item = DisplayItem(title='Hippo', url='http://some.url/to/a/hippo/pic')

cit = item.coins_citation
# just some basic sanity checks
self.assert_(cit.startswith('ctx_ver=Z39.88-2004'))
self.assert_('rft.title=%s' % item.title in cit)

0 comments on commit be7c13e

Please sign in to comment.