# $Id$
# $URL$
import paginate, availability
logger = logging.getLogger('meresco.resultlist')
logger.debug("Starting logger")
serverConfig = infra.configRoot
systemConfig = infra.configRoot
websiteConfig = infra.configRoot
#websiteConfig.setSection('searchform')
COVERS_ISSN = serverConfig.get('Covers_ISSN',section='proxies')
COVERS_ISBN = serverConfig.get('Covers_ISBN',section='proxies')
BASEURL = systemConfig.get('baseURL' ,section='system')
EXPORT_YN = websiteConfig.get('useExport' ,section='behavior', default='no')
def displayResolvedOpenURL(arguments, *args, **kwargs):
index = 0
link = ''
record = {}
genre = arguments.get('genre',[''])[0]
if genre == 'bookitem':
record["Publication type"] = 'chapter'
else: record["Publication type"] = genre
record["Title"] = arguments.get('atitle',[''])[0]
if not record["Title"]:
record["Title"] = arguments.get('title',[''])[0]
author = ""
if 'rft.au' in arguments:
au = arguments['rft.au']
nau = len(au)
for i in range(0, nau):
if i == 0:
author = au[0]
else:
author += '; ' + au[i]
else:
aulast = arguments.get('aulast',[''])[0]
aufirst = arguments.get('aufirst',[''])[0]
if aulast:
author = aulast
if aufirst: author += ", " + aufirst
if author: record["Author(s)"] = author
record["ISSN"] = arguments.get('issn',[''])[0]
record["ISBN"] = arguments.get('isbn',[''])[0]
if genre == 'article' or genre == 'bookitem':
title = arguments.get('title', [''])[0]
date = arguments.get('date', [''])[0]
volume = arguments.get('volume',[''])[0]
issue = arguments.get('issue', [''])[0]
spage = arguments.get('spage', [''])[0]
epage = arguments.get('epage', [''])[0]
source = ''
source += title
if volume: source += " vol. " + volume
if date: source += " (" + date + ")"
if issue: source += " nr. " + issue
if spage: source += " p." + spage
if epage: source += "-" + epage
if source: record['Source'] = source
recordId = 'openulr:openurl'
singleRecord = False
openurl = "/locator1/Locator?" + arguments['openurl']
yield """
"""
yield renderSingleItem(index, link, recordId, record, singleRecord, openurl=openurl, *args, **kwargs)
yield """
"""
def displaySearchTips(errorString, language='en'):
# FIXME Translation
s = errorString
s += '%s
' % websiteConfig.get('searchTips','Better luck next time!', section="searchform", language=language)
return s
def displayMobileRecord(singleRecord, singleRecordDetails, recordToggler, title, authors, source, recordId, link, availabilityLabel, index, record, genre, date, coverImage, *args, **kwargs):
yield ""
if singleRecord:
yield """
"""%{'title':title, 'authors':authors, 'source':source, 'singleRecordDetails':singleRecordDetails, 'recordId':recordId}
else:
yield """
%(index)s.
,
%(authors)s.
%(source)s
"""%{'index':index, 'link':link, 'title':title, 'authors':authors, 'source':source }
if (record):
yield """
%(availability)s """ % {'availability':availabilityLabel}
yield availability.main(index=index, record=record, recordId=recordId, *args, **kwargs)
yield " "
yield " | "
def displayRecord(singleRecord, singleRecordDetails, recordToggler, title, authors, source, recordId, link, index):
if singleRecord:
yield """
|
"""%{'title':title, 'authors':authors, 'source':source, 'singleRecordDetails':singleRecordDetails, 'recordId':recordId}
else:
yield """
"
if recordId.startswith("evs-uvt-nl"):
yield """
"""%{'index':index, 'recordId':recordId}
yield """
%(authors)s
%(source)s
|
"""%{'authors':authors, 'source':source, 'recordToggler':recordToggler}
def displayCover(singleRecord, index, recordId, genre, date, coverImage):
if singleRecord:
yield """
%(coverImage)s
| """%{'coverImage':coverImage}
else:
yield """
"""
if index:
if EXPORT_YN == "yes": row1Type = "checkbox"
else: row1Type = "hidden"
yield """
"""%{'type': row1Type, 'index':index, 'recordId':recordId}
yield """
%(genre)s
%(date)s
%(coverImage)s
| """%{'genre':genre, 'date':date, 'coverImage':coverImage}
def displayAvailability(singleRecord, availabilityLabel, index, record, recordId, openurl='', resolver={}, *args, **kwargs):
yield """
%(availability)s """ %{'availability':availabilityLabel}
if openurl:
yield availability.getAvailabilityByOpenurl(recordId, index, openurl=openurl)
elif (record):
yield availability.main(index=index, record=record, recordId=recordId, resolver=resolver, *args, **kwargs)
yield """
| """
def renderSingleItem(index, link, recordId, record, singleRecord, resolver={}, language='en', openurl='', *args, **kwargs):
context = "normal"
if isPermaLink(**kwargs): context = "permalink"
logger.debug('recordId: ' + recordId)
if not record:
record = any.createRecord(recordId, format="short")
logger.debug(infra.prpt('record',record))
### record dependent fields
authors=''
source=''
genre = ''
date=''
title=''
coverUrl = ''
if record:
if 'Author(s)' in record : authors = record['Author(s)']
elif 'Editor(s)' in record : authors = record['Editor(s)'] + ' (Ed.)'
if 'Source' in record : source=record['Source']
if 'Publication type' in record: genre = record['Publication type']
if 'Publication date' in record: date=record['Publication date']
if 'Title' in record : title=record['Title']
coverUrl = getCoverUrlFor(record)
else: ### FIXME fatsoenlijke error genereren
title = "Problem: %s cannot be retrieved" %(recordId)
emptyImage = fixedPathForIE7(**kwargs) + 'files/' + websiteConfig.get('empty', section='images')
coverImage = ''
useHighSlide = websiteConfig.get('useHighSlide', section='behavior')
if coverUrl:
if (useHighSlide == 'True'):
coverImage ="""
"""% {'coverUrl':coverUrl,'emptyImage':emptyImage}
else:
coverImage ="""
"""% {'coverUrl':coverUrl,'emptyImage':emptyImage}
else:
coverImage ="""
"""% {'emptyImage':emptyImage}
availabilityLabel = websiteConfig.get('availability',section="availability", language=language)
recordToggler = ""
if index: recordToggler = """
"""%{'index':index, 'recordId':recordId}
singleRecordDetails = """
"""%{'index':index, 'recordId':recordId, 'context':context}
if isMobile(**kwargs):
yield displayMobileRecord(singleRecord, singleRecordDetails,
recordToggler, title, authors, source,
recordId, link, availabilityLabel,
index, record, genre, date, coverImage,
*args, **kwargs)
else:
yield displayCover(singleRecord, index, recordId, genre, date, coverImage)
yield displayRecord(singleRecord, singleRecordDetails,
recordToggler, title, authors, source,
recordId, link, index)
yield displayAvailability(singleRecord, availabilityLabel, index,
record, recordId, openurl=openurl, resolver=resolver, *args, **kwargs)
def getCoverUrlFor(record):
if 'ISSN' in record:
return COVERS_ISSN + '/' + record['ISSN']
if 'ISBN' in record:
return COVERS_ISBN + '/' + record['ISBN'].split()[0].replace('-', '')
logger.debug("No ISSN or ISBN, so no cover " + infra.prpt('record',record))
def getResolver(ip):
resolver = {}
namespaceMap = {
'reg': 'http://worldcatlibraries.org/registry',
'res': 'http://worldcatlibraries.org/registry/resolver'
}
records = parse(urlopen("http://www.worldcat.org/registry/lookup?IP=" + ip))
regEntry = records.xpath("/reg:records/res:resolverRegistryEntry", namespaceMap)
if regEntry:
regEntry = regEntry[0]
resolver["baseurl"] = regEntry.xpath("//res:baseURL/text()", namespaceMap)[0]
resolver["linkicon"] = regEntry.xpath("//res:linkIcon/text()", namespaceMap)[0]
resolver["linktext"] = regEntry.xpath("//res:linkText/text()", namespaceMap)[0]
return resolver;
def exportSubmit():
return """
Export citation(s)
|
""" %{'baseurl': BASEURL + '/sru'}
def main(total=0, recordIds=[], records={}, duration=0, cqlQuery=None, httpQuery='', errorString = '', arguments={}, path='', *args, **kwargs):
ip = kwargs['Headers']['X-Forwarded-For']
resolver = {}
if websiteConfig.get("useResolver", section="behavior", default="no") == "yes": resolver = getResolver(ip)
language = getLanguage( kwargs['Headers'] )
query = arguments.get('query', [''])[0]
httpQuery = escapeHtml(query)
offset = int(arguments.get('offset', ['0'])[0])
lo, hi = offset + 1, min(offset + len(recordIds), total)
if total == 0: lo = 0
displayType = arguments.get('displayType',['multiple'])[0]
if displayType == 'single':
singleRecord = True
else:
singleRecord = False
if isOpenURLResolver(**kwargs) and offset == 0 and 'queryisforresolver' in arguments:
yield displayResolvedOpenURL(arguments, *args, **kwargs)
if not singleRecord:
if query or websiteConfig.get("resultsifnoquery", section="behavior", default="no") == 'yes':
if total:
#FIXME!
resultString= {'nl':'Resultaten %s - %s van %d.',
'en': 'Results %s - %s of %d.'}[language] % (lo, hi, total)
yield """
"""
yield resultString
yield paginate.main(offset, total, arguments=arguments, path=path, *args, **kwargs)
yield """
"""
else:
yield displaySearchTips(errorString, language=language)
yield """
"""
if total:
yield"""
"""
yield """
"""
yield paginate.main(offset, total, arguments=arguments, path=path, *args, **kwargs)