# $Id$
# $URL$
import paginate, availability
logger = logging.getLogger('meresco.resultlist')
logger.debug("Starting logger")
serverConfig = configs ['server']
serverConfig.setSection('proxies')
websiteConfig = configs ['website']
websiteConfig.setSection('searchform')
COVERS_ISSN = serverConfig.get('Covers_ISSN',section='proxies')
COVERS_ISBN = serverConfig.get('Covers_ISBN',section='proxies')
def renderSingleItem(index, link, recordId):
logger.debug('recordId: ' + recordId)
record = any.createRecord(recordId)
# logging.debug(infra.prpt('record',record))
authors=''
if 'Author(s)' in record: authors = record['Author(s)']
elif 'Editor(s)' in record: authors = record['Editor(s)'] + ' (Ed.)'
#foo=''
#if 'bar' in record foo=record['bar']
#
source=''
if 'Source' in record: source=record['Source']
genre = ''
if 'Publication type' in record: genre = record['Publication type']
date=''
if 'Publication date' in record: date=record['Publication date']
title=''
if 'Title' in record: title=record['Title']
emptyImage = '/files/' + websiteConfig.get('empty', section='images')
coverImage = ''
coverUrl = getCoverUrlFor(record)
if coverUrl:
coverImage ="""
"""% {'coverUrl':coverUrl,'emptyImage':emptyImage}
availabilityLabel = websiteConfig.get('availability',section="availability")
recordToggler = """
"""%{'index':index, 'recordId':recordId}
yield """
"""
yield """
%(authors)s
%(source)s
%(recordToggler)s
"""%{'link':link, 'title':title, 'authors':authors, 'source':source, 'recordToggler':recordToggler}
yield """
%(index)s.
%(genre)s
%(date)s
%(coverImage)s
"""%{'index':index, 'genre':genre, 'date':date, 'coverImage':coverImage}
yield """
%(availability)s
""" %{'availability':availabilityLabel}
if (record):
yield availability.main(index=index, record=record, recordId=recordId)
yield """
"""
def getCoverUrlFor(record):
if 'ISSN' in record:
return COVERS_ISSN + '/' + record['ISSN']
if 'ISBN' in record:
return COVERS_ISBN + '/' + record['ISBN']
def main(total=0, recordIds=[], duration=0, cqlQuery=None, httpQuery='', arguments={}, path='', *args, **kwargs):
language = 'en' #path.startswith('/en/') and 'en' or 'nl'
# logger.debug(infra.prpt('arguments',arguments))
# logger = logging.getLogger('meresco.resultlist')
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
resultString= {'nl':'Resultaten %s - %s van %d (%.5s seconden).', 'en': 'Results %s - %s of %d (%.5s seconds).'}[language] % (lo, hi, total, duration)
yield """
"""
yield resultString
yield """
"""
if total == 0:
yield '
%s
' % websiteConfig.get('searchTips','Better luck next time!')
yield paginate.main(offset, total, arguments=arguments, path=path, *args, **kwargs)
# yield """
"""
yield '
'
index = offset
for recordId in recordIds:
link = 'page/recordview?' + urlencode({
'recordId': recordId})
index += 1
yield renderSingleItem(index, link, recordId)
yield "
"
yield paginate.main(offset, total, arguments=arguments, path=path, *args, **kwargs)
yield """
"""