# $Id$ # $URL$ import paginate, availability logger = logging.getLogger('meresco.resultlist') logger.debug("Starting logger") serverConfig = infra.configRoot websiteConfig = infra.configRoot #websiteConfig.setSection('searchform') COVERS_ISSN = serverConfig.get('Covers_ISSN',section='proxies') COVERS_ISBN = serverConfig.get('Covers_ISBN',section='proxies') 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 """
%(singleRecordDetails)s
   
"""%{'title':title, 'authors':authors, 'source':source, 'singleRecordDetails':singleRecordDetails, 'recordId':recordId} else: yield """
%(index)s.
%(title)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 """
%(singleRecordDetails)s
   
"""%{'title':title, 'authors':authors, 'source':source, 'singleRecordDetails':singleRecordDetails, 'recordId':recordId} else: yield """
%(title)s
"""%{'index':index, 'link':link, 'title':title} if recordId.startswith("evs-uvt-nl"): yield """ """%{'index':index, 'recordId':recordId} yield """
%(authors)s
%(source)s
%(recordToggler)s
"""%{'authors':authors, 'source':source, 'recordToggler':recordToggler} def displayCover(singleRecord, index, genre, date, coverImage): if singleRecord: yield """
%(coverImage)s
"""%{'index':index, 'genre':genre, 'date':date, 'coverImage':coverImage} else: yield """
%(index)s.
%(genre)s
%(date)s
%(coverImage)s
"""%{'index':index, 'genre':genre, 'date':date, 'coverImage':coverImage} def displayAvailability(singleRecord, availabilityLabel, index, record, recordId, resolver={}, *args, **kwargs): yield """
%(availability)s
""" %{'availability':availabilityLabel} if (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', *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 = """
"""%{'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, genre, date, coverImage) yield displayRecord(singleRecord, singleRecordDetails, recordToggler, title, authors, source, recordId, link, index) yield displayAvailability(singleRecord, availabilityLabel, index, record, recordId, 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 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 not singleRecord: if query: if total: #FIXME! resultString= {'nl':'Resultaten %s - %s van %d.', 'en': 'Results %s - %s of %d.'}[language] % (lo, hi, total) yield """
""" yield resultString yield """
""" else: yield displaySearchTips(errorString, language=language) yield paginate.main(offset, total, arguments=arguments, path=path, *args, **kwargs) yield """
""" index = offset for recordId in recordIds: link = '/search?displayType=single&query=' + recordId index += 1 record = {} if recordId in records: record = records[recordId] yield """ """ yield renderSingleItem(index, link, recordId, record, singleRecord, resolver=resolver, language=language, *args, **kwargs) yield """ """ yield """
""" yield paginate.main(offset, total, arguments=arguments, path=path, *args, **kwargs)