# $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') DOWNLOADCENTER_URL =serverConfig.get('url', section='downloadCenter', default='') 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] record["Publication date"] = arguments.get('date',[''])[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' or genre == '': 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 = 'openurl:openurl' singleRecord = False openurl = "/locator1/Locator?" + arguments['openurl'] yield """
Exact match:
""" yield renderSingleItem(index, link, recordId, record, singleRecord, OpenURLResolver=True, openurl=openurl, *args, **kwargs) yield """

""" if arguments.get("total") > 0: yield """
Based on this title, the following publications may also be of interest:
""" 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
   
"""%{'index': index, '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, dataset, recordId, link, index, language): if singleRecord: yield """
%(singleRecordDetails)s
   
"""%{'index': index, 'title':title, 'authors':authors, 'source':source, 'singleRecordDetails':singleRecordDetails, 'recordId':recordId} else: datasetInfo = "" if dataset: datasetInfo='%s' %websiteConfig.get('datasetInfo','Dataset available!', section="vocabulary", language=language) yield """
%(info)s
"""%{'info':datasetInfo, 'index':index} if index: yield """"""%{'link': link} yield title if index: yield "" yield "
" if recordId.startswith("evs-uvt-nl"): yield """ """%{'index':index, 'recordId':recordId} yield """
%(authors)s
%(source)s
%(recordToggler)s
"""%{'index': index, 'authors':authors, 'source':source, 'recordToggler':recordToggler} def displayCover(singleRecord, index, recordId, genre, date, coverImage, openurl=''): yield """ """ if index: if EXPORT_YN == "yes": row1Type = "checkbox" else: row1Type = "hidden" if singleRecord: if EXPORT_YN == "yes": yield """
 
"""%{'openurl': openurl, 'type': row1Type, 'recordId':recordId} else: yield """
%(index)s.
"""%{'openurl': openurl, 'type': row1Type, 'index':index, 'recordId':recordId} if not singleRecord: yield """
%(genre)s
%(date)s
""" %{'genre':genre, 'date':date} yield """
%(coverImage)s
"""%{ 'coverImage':coverImage} def displayAvailability(singleRecord, availabilityLabel, index, record, recordId, OpenURLResolver=False, openurl='', resolver={}, *args, **kwargs): yield """
%(availability)s
""" %{'availability':availabilityLabel} if OpenURLResolver and openurl: yield availability.getAvailabilityByOpenurl(recordId, index, openurl=openurl) elif openurl: yield availability.main(index=index, record=record, openurl=openurl, recordId=recordId, resolver=resolver, *args, **kwargs) elif (record): yield availability.main(index=index, record=record, recordId=recordId, resolver=resolver, *args, **kwargs) yield """ """ def renderSingleItem(index, link, recordId, record, singleRecord, OpenURLResolver=False, 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='' dataset='' 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'] if 'Dataset' in record : dataset=record['Dataset'] 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, openurl=openurl) yield displayRecord(singleRecord, singleRecordDetails, recordToggler, title, authors, source, dataset, recordId, link, index, language) yield displayAvailability(singleRecord, availabilityLabel, index, record, recordId, OpenURLResolver=OpenURLResolver, 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] if "nancy2.lm.worldcat.org" in resolver["baseurl"]: resolver = getResolver("137.56.000.000") return resolver; def exportSubmit(): return """ Export citation(s) """ %{'baseurl': BASEURL, 'downloadcenter-url': DOWNLOADCENTER_URL} def main(total=0, recordIds=[], records={}, duration=0, cqlQuery=None, httpQuery='', errorString = '', arguments={}, path='', *args, **kwargs): resolver = {} # moet link naar externe resolver worden getoond in plaats van availability info van locator? if websiteConfig.get("useResolver", section="behavior", default="no") == "yes": ip = kwargs['Headers']['X-Forwarded-For'] 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 OpenURLResolver = False # isOpenURLResolver: test of pad van URI begint met "/openurl?" # 'queryisforresolver' in arguments: query is gemaakt in openurl.sf en is dus niet afkomstig van gebruiker if isOpenURLResolver(**kwargs) and offset == 0 and 'queryisforresolver' in arguments: arguments["total"] = total yield displayResolvedOpenURL(arguments, **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 """
""" elif OpenURLResolver: pass else: yield displaySearchTips(errorString, language=language) yield """
""" if total: yield""" """%(DOWNLOADCENTER_URL) if EXPORT_YN == "yes": yield exportSubmit() index = offset for recordId in recordIds: link = '/search?displayType=single&query=' + recordId index += 1 record = {} if recordId in records: record = records[recordId] openurl = "" if EXPORT_YN == "yes": mods = any.getMods(recordId) openurl = any.createOpenURL(mods, recordId) yield """ """ yield renderSingleItem(index, link, recordId, record, singleRecord, OpenURLResolver=OpenURLResolver, resolver=resolver, language=language, openurl=openurl, *args, **kwargs) yield """ """ yield """
""" yield """
""" yield paginate.main(offset, total, arguments=arguments, path=path, *args, **kwargs)