# $Id$ # $URL$ #testLBS = True #testServer = "https://pichu.uvt.nl/loandesk" 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): locator = getLocator(recordId, mods) yield """ """ % {'locator' : locator, '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('depot', section="storageList", default='IN DEPOT', language=language) library = availabilityConfig.get('library', section="storageList", default='IN LIBRARY', language=language) journal = availabilityConfig.get('journal', section="storageList", default='JOURNAL', language=language) ebook = availabilityConfig.get('ebook', section="storageList", default='Electronic Book', language=language) data = {} documentStorageList = ['locator','depot','library','journal'] 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) ######### 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': #EPN = copyInformation.xpath("mods:note[@type='epn']/text()", namespaceMap)[0] if inDepot(location): data['locator'].append(copyInformation) #if testLBS: # backURL = baseURL + RequestURI # url = testServer + "/order?epn=" + EPN + '&' + urlencode({'back': backURL}) #else: # url = "http://dbiref.uvt.nl/iPort?request=full_record&db=tucat&searchField=sgn&query=%(loc)s" %{'loc': location} #data['depot'].append('%(loc)s (not for loan)' %{'loc': location, 'url': url}) # niet in depot: # FIXME is dit nog nodig??? loandesk? elif genre == 'journal': # FIXME: config (tuts) col = copyInformation.xpath("mods:enumerationAndChronology[@unitType='3']/text()", namespaceMap) data['journal'].append('%(loc)s %(col)s' %{'loc': location, 'col': col[0]}) else: data['library'].append(location) elif uitleencode[0] == 'u' or uitleencode[0] == 'b': data['locator'].append(copyInformation) elif url: #yield '%ebooks' %(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) + "&epn=" + EPN yield """ """ %{'id':ID, 'loc': location, 'inDepot': inDepot(location), 'genre': genre, 'locator': locator} break if locator: break elif storage == 'depot' and data[storage]: yield '' elif storage == 'library' and data[storage]: yield '' elif storage == 'journal' and data[storage]: yield '' def main(index=0, record={}, recordId='', *args, **kwargs): language = getLanguage( kwargs['Headers'] ) fulltext = availabilityConfig.get('fulltext', section="storageList",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 '' if db == "opc-uvt-nl": #if not urls: #if (genre == 'series') and 'Related Titles' in record: # yield record['Related Titles'] if genre == 'series': yield 'Display the items in the series' %(db, rid) else: if mods: 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')