def __initializeMARC(): "Initializes all MARC Redis supportting keys" marc_rdf_files = ['00X.rdf', '0XX.rdf', '1XX.rdf', '2XX.rdf', '3XX.rdf', '4XX.rdf', '5XX.rdf'] print("Initializing MARC labels") for marc_filename in marc_rdf_files: marc_rdf_file = os.path.join(PROJECT_HOME, 'marc_batch', 'fixures', marc_filename) marc_rdf = etree.parse(marc_rdf_file) all_descriptions = marc_rdf.findall("{{{0}}}Description".format(RDF)) for description in all_descriptions: label = description.find('{{{0}}}label'.format(RDFS)) if label is not None: raw_name = description.attrib.get('{{{0}}}about'.format(RDF)) redis_key = 'marc:{0}'.format(os.path.split(raw_name)[-1][1:]) if not REDIS_DATASTORE.hexists('marc:labels', redis_key): REDIS_DATASTORE.hset('marc:labels', redis_key, label.text) sys.stderr.write(".") print("\n\tFinished {0}".format(marc_filename)) print("Finished Initializing MARC labels")
def add_ils_location(place_key, code_list, REDIS_DATASTORE): if len(code_list) < 1: pass elif len(code_list) == 1: REDIS_DATASTORE.hset(place_key, 'ils-location-code', code_list[0]) else: REDIS_DATASTORE.sadd('{0}:ils-location-codes'.format(place_key), code_list)
def __initializeBIBFRAME(): "Initializes all BIBFRAME Keys" print("Initializing BIBFRAME labels") bf_rdf = etree.parse(os.path.join(PROJECT_HOME, 'bibframe', 'fixures', 'vocab.rdf')) rdfs_resources_elems = bf_rdf.findall("{{{0}}}Resource".format(RDFS)) for row in rdfs_resources_elems: attribute_uri = row.attrib.get('{{{0}}}about'.format(RDF)) attrib_name = os.path.split(attribute_uri)[-1] if not REDIS_DATASTORE.hexists('bf:vocab:labels', attrib_name): label = row.find('{{{0}}}label'.format(RDFS)) REDIS_DATASTORE.hset('bf:vocab:labels', attrib_name, label.text) sys.stderr.write(".") print("\nFinished Initializing BIBFRAME labels")
def feedback(request): """ Feedback view for the Aristotle Library Apps Project :param request: Web request from client """ if request.method != 'POST': return Http404 today = datetime.datetime.utcnow() feedback_id = REDIS_DATASTORE.incr( "global feedback:{0}:{1}".format(today.year, today.month)) feedback_key = "feedback:{0}:{1}:{2}".format(today.year, today.month, feedback_id) REDIS_DATASTORE.hset(feedback_key, "created", today.isoformat()) REDIS_DATASTORE.hset(feedback_key, "comment", request.POST.get('comment')) REDIS_DATASTORE.hset(feedback_key, "context", request.POST.get('context')) if request.POST.has_key('sender'): REDIS_DATASTORE.hset(feedback_key, "sender", request.POST.get('sender')) return redirect(REDIS_DATASTORE.hget(feedback_key, "context"))
def load_institution_places(prospector_code, json_filename, authority_ds=REDIS_DATASTORE): """Function loads an Institution's Places codes into RLSP Parameters: prospector_code -- Prospector code json_filename -- Filename of an institution's places encoded in JSON """ institution_key = authority_ds.hget('prospector-institution-codes', prospector_code) places = json.load(os.path.join(PROJECT_HOME, "themes", "prospector", "fixures", json_filename)) for name, info in places.iteritems(): place_key = add_place(institution_key, REDIS_DATASTORE) REDIS_DATASTORE.hset(place_key, 'name', name) # Should be the standard case, a listing of ils codes associated if type(info) == list: add_ils_location(place_key, info, REDIS_DATASTORE) elif type(info) == dict: sub_place_keys = [] for key, value in info.iteritems(): sub_place_key = add_place(institution_key, REDIS_DATASTORE) REDIS_DATASTORE.hset(sub_place_key, 'name', key) REDIS_DATASTORE.hset(sub_place_key, 'schema:containedIn', place_key) add_ils_location(sub_place_key, info, REDIS_DATASTORE) sub_place_keys.append(sub_place_key) if len(sub_place_keys) < 1: pass elif len(sub_place_keys) == 1: REDIS_DATASTORE.hset(place_key, "contains", sub_place_keys[0]) else: REDIS_DATASTORE.sadd('{0}:contains'.format(place_key), sub_place_keys)