import paginate, drilldown
BASEURLJOURNALCOVERS = 'http://drcwww.uvt.nl/~place/elsevier/'
import rating
def xpath(node, path):
result = node.xpath(path, {'mods':'http://www.loc.gov/mods/v3'})
return result and result[0] or ''
def nodeset(node, path):
return node.xpath(path, {'mods':'http://www.loc.gov/mods/v3'})
def renderSingleItem(index, link, metadata, recordId):
### the paths for the xpath function are adapted because of the use of metadata instead of mods
mods = xpath(metadata, '//mods:mods')
#authors = ', '.join(
# ' '.join(namepart for namePart in xpath(name, '/mods:namePart/text()'))
# for name in xpath(metadata, 'mods:mods/mods:name'))
authors = ""
for name in nodeset(metadata, '//mods:mods/mods:name'):
for namePart in nodeset(name, 'mods:namePart/text()'):
authors += namePart
authors += ' '
authors = authors.rstrip(' ')
authors += ', '
genre = ''.join(xpath(metadata, '//mods:mods/mods:genre/text()'))
if genre and '/' in genre:
genre = genre.split('/')[-1]
title = ''.join(xpath(metadata, '//mods:mods/mods:titleInfo/mods:title/text()')) or '[NO TITLE AVAILABLE]'
yield '
'
yield '%s. | ' % index
yield '%s | ' % genre
yield '%s | ' % (
link,
title
)
yield '%s | ' % ", ".join(nodeset(metadata, '//mods:originInfo/mods:dateIssued/text()'))
yield '%s | ' % authors.rstrip(' ,')
yield ''
yield rating.showRating(recordId, imageSize='small')
yield ' | '
yield '
\n'
url = any.createOpenURL(mods)
coverUrl = getCoverUrlFor(recordId, mods)
if coverUrl:
#yield """ | | %(journalTitle)s |
\n""" % {
yield """ | | %(title)s | Locator |
\n""" % {
'coverUrl': coverUrl,
#'journalTitle': ''.join(xpath(metadata, '//mods:mods/mods:relatedItem/mods:titleInfo/mods:title/text()'))
'title': ''.join(xpath(metadata, '//mods:mods/mods:relatedItem/mods:titleInfo/mods:title/text()')),
'url' : url
}
else:
yield """ | Locator |
\n""" % url
# yield """
#
# |
\n""" % url
def getCoverUrlFor(recordId, mods):
identifier = ''.join(xpath(mods, '//mods:identifier/text()'))
if not identifier: return
idParts = identifier.split(':')
### urn:{issn|issbn}:
if len(idParts) < 3: return
if idParts[1] == 'issn' or idParts[1] == 'ISSN':
return '%s/%s.gif' % (BASEURLJOURNALCOVERS, idParts[2])
if idParts[1] == 'isbn' or idParts == 'ISBN':
return 'http://syndetics.com/index.aspx?isbn=%s/sc.gif&client=univantilburg' % idParts[2]
def main(hits=None, duration=0, cqlQuery=None, httpQuery='', arguments={}, path='', *args, **kwargs):
language = path.startswith('/en/') and 'en' or 'nl'
rssLink = 'http://%s/rss?%s' % (any.configuration().get('host', ''), urlencode({'query': cqlQuery}))
yield """'
offset = int(arguments.get('offset', ['0'])[0])
lo, hi = offset + 1, min(offset + 10, len(hits))
yield ""
yield '
'
yield {'nl':'Resultaten %s - %s van %d (%.5s seconden).', 'en': 'Results %s - %s of %d (%.5s seconds).'}[language] % (lo, hi, len(hits), duration)
yield '
\n'
yield "
"
yield paginate.main(offset, len(hits), arguments=arguments, path=path, *args, **kwargs)
yield "
\n"
yield "
\n"
yield "
\n"
index = offset
for recordId in hits[offset:offset+10]:
####### using the complete metadata record instead of only the mods part
metadata = parse(any.getStream(recordId, 'metadata'))
link = '/recordview?' + urlencode({
'recordId': recordId})
index += 1
yield renderSingleItem(index, link, metadata, recordId)
yield "
\n"
yield "
\n"
yield "
"
yield paginate.main(offset, len(hits), arguments=arguments, path=path, *args, **kwargs)
yield "
\n"
yield "
\n"
yield drilldown.main(hits=hits, httpQuery=httpQuery, arguments=arguments, path=path, *args, **kwargs)