# $Id$
# $URL$
logger = logging.getLogger('meresco.availability')
logger.debug("Starting logger")
availabilityConfig = infra.configRoot
collectionString = availabilityConfig.get('collectionList', section="collections")
if collectionString == None:
logger.error("No collections found!")
collectionString = "NO,COLLECTIONS,FOUND"
exceptionString = availabilityConfig.get('exceptionList', section="collections")
if exceptionString == None:
logger.error("No exceptions found!")
exceptionString = "NO,EXCEPTIONS,FOUND"
collections = collectionString.split("\n")
exceptions = exceptionString.split("\n")
#infra.dd('collections', collections)
#FIXME: config
namespaceMap = {
'mods': 'http://www.loc.gov/mods/v3'
}
def inDepot(location):
global collections
global exceptions
# logging.debug("location:" + location)
for exception in exceptions:
# logging.debug("exception: " + exception)
if re.match(exception+'\s',location):
return False
for collection in collections:
# logging.debug("collection: " + collection)
if re.match(collection+'\s',location):
return True
return False
def getLocator(recordId, mods):
locator = any.createOpenURL(mods, recordId)
return locator
def getAvailabilityByOpenurl(recordId, mods, ID, resolver={}):
locator = getLocator(recordId, mods)
if resolver:
function = """resolver("%(id)s", "%(openurl)s", "%(linkicon)s", "%(linktext)s");""" %{'id': ID,
'openurl' : resolver["baseurl"] + "&" + locator.split('?')[1],
'linkicon' : resolver["linkicon"],
'linktext' : resolver['linktext']}
else: function = """openurl("%(id)s", "", "%(locator)s", "unknown");""" % {'locator' : locator, 'id' : ID }
yield """
""" % {'function' : function, 'id' : ID }
def getAvailabilityByUitleencode(mods, genre, recordId, ID, language='en'):
# uitleencodes
# a = titel in bestelling
# b = beperkt uitleenbaar
# c = niet balie, wel IBL
# d = wel balie, niet IBL
# e = elektronisch beschikbaar
# f = niet uitleenbaar, wel fotokopie
# g = geblokkeerd
# i = niet uitleenbaar, geen fotokopie, wel inzage
# o = onbekend
# s = speciale toestemming
# u = normaal uitleenbaar
# z = boek zoek
depot = availabilityConfig.get('indepot', section="availabilityGroups", default='IN DEPOT', language=language)
library = availabilityConfig.get('inlibrary', section="availabilityGroups", default='IN LIBRARY', language=language)
journal = availabilityConfig.get('journal', section="availabilityGroups", default='JOURNAL', language=language)
series = availabilityConfig.get('series', section="availabilityGroups", default='SERIES', language=language)
ebook = availabilityConfig.get('ebook', section="availabilityGroups", default='Electronic Book', language=language)
displaySeries = availabilityConfig.get('displayseries', section="availDisplayText", default='Display items in series', language=language)
notForLoan = availabilityConfig.get('notforloan', section="availDisplayText", default='NOT FOR LOAN', language=language)
data = {}
documentStorageList = ['locator','depot','library','journal', 'series']
for storage in documentStorageList:
data[storage] = []
for copyInformation in mods.xpath("//mods:location/mods:holdingSimple/mods:copyInformation", namespaceMap):
uitleencode = copyInformation.xpath("mods:note[@type='status']/text()", namespaceMap)
if genre == 'series' and not uitleencode:
data['series'].append('%s' %(recordId.split(':')[1], displaySeries))
#yield '%s' %(recordId.split(':')[1], displaySeries)
break
####### Er zijn ook elektronische boeken, hebben geen shelfLocator, maar een electronicLocator
####### met URL.
url = ""
l = copyInformation.xpath("mods:shelfLocator/text()", namespaceMap)
if l: location = l[0]
else:
u = copyInformation.xpath("mods:electronicLocator/text()", namespaceMap)
if u: url = u[0]
if uitleencode and location:
# niet uitleenbaar
if uitleencode[0] == 'i' or uitleencode[0] == 'f':
if inDepot(location) or genre == 'journal':
data['locator'].append(copyInformation)
else:
# FIXME: text layout moet door bzv.js
data['library'].append(location + " (" + notForLoan + ")")
elif uitleencode[0] == 'u' or uitleencode[0] == 'b':
data['locator'].append(copyInformation)
elif url:
yield '' + ebook + ''
locator = ""
for storage in documentStorageList:
if storage == 'locator' and data[storage]:
for copyInformation in data['locator']:
EPN = copyInformation.xpath("mods:note[@type='epn']/text()", namespaceMap)[0]
if EPN:
location = copyInformation.xpath("mods:shelfLocator/text()", namespaceMap)
location = location and location[0] or ''
if location:
locator = getLocator(recordId, mods)
action = "stack"
if inDepot(location): action = "depot"
yield """
""" %{'id':ID, 'loc':location, 'locator':locator, 'action':action}
break
if locator: break
title = ""
if storage == 'depot' and data[storage]:
title = depot
if storage == 'library' and data[storage]:
title = library
if storage == 'journal' and data[storage]:
title = journal
if storage == 'series' and data[storage]:
title = series
if title:
# FIXME: deze structuur moet overeenkomen met die van bzv.js
# daarom moeten de data doorgegeven worden aan bzv.js voor
# een consistent layout. Optie is een aangepaste availability()
yield ''
yield '- %s
' %(title)
for el in data[storage]:
yield '- %(el)s
' %{'el':el}
yield '
'
def main(index=0, record={}, recordId='', resolver={}, *args, **kwargs):
language = getLanguage( kwargs['Headers'] )
fulltext = availabilityConfig.get('fulltext', section="availabilityGroups",default='DIRECT LINK', language=language)
# logger.debug(infra.prpt('recordId',recordId))
# logger.debug(infra.prpt('record',record))
db, rid = recordId.split(':', 1)
urls = 0
if 'URL(s)' in record: urls = 1
genre = ''
if 'Publication type' in record: genre = record['Publication type']
mods = any.getMods(recordId)
# logger.debug(infra.prpt('*mods*', mods))
# Note: 'id' is a python builtin
# NOTE: 'id' IS A PYTHON BUILTIN!!!!!!
ID = 'AvID' + str(index)
if urls:
yield '' % {'id' : ID}
yield '- %(title)s
' %{'title':fulltext}
for url in record['URL(s)']:
# FIXME config
yield '- '
if not isMobile(**kwargs):
yield ''
yield 'full text
' %(url)
yield '
'
if db == "opc-uvt-nl":
yield getAvailabilityByUitleencode(mods, genre, recordId, ID + '-ulc', language=language)
else: # not opc
if urls and (genre != 'article'): pass
else:
yield getAvailabilityByOpenurl(recordId, mods, ID + '-ourl', resolver=resolver)