def location_resolver(internal_loc_pid): """Return the Location record for the given Internal Loc. or raise.""" location_pid = get_field_value(InternalLocation, internal_loc_pid, "location_pid") location = Location.get_record_by_pid(location_pid) del location["$schema"] return location
def serialize_loan_request_book_information(loan): """Serialize loan information.""" location = Location.get_record_by_pid(loan["transaction_location_pid"]) document = Document.get_record_by_pid(loan["document_pid"]) return dict(request_start_date=loan["start_date"], request_end_date=loan["end_date"], library=location["name"], location=location["address"], title=document["title"])
def serialize_on_loan_book_information(loan): """Serialize loan information.""" location = Location.get_record_by_pid(loan["transaction_location_pid"]) document = Document.get_record_by_pid(loan["document_pid"]) return dict(barcode=loan["item"]["barcode"], end_date=loan["end_date"], library=location["name"], location=location["address"], title=document["title"])
def location_resolver(internal_loc_pid): """Return the Location record for the given Internal Loc. or raise.""" location_pid = get_field_value( InternalLocation, internal_loc_pid, "location_pid" ) location = Location.get_record_by_pid(location_pid) return pick( location, "name", "opening_exceptions", "opening_weekdays", "pid", )
def location(): """Create library location.""" click.echo("Creating locations...") location = { "pid": RecordIdProviderV2.create().pid.pid_value, "name": "CERN Central Library", "address": "Rue de Meyrin", "email": "*****@*****.**" } record = Location.create(location) minter(LOCATION_PID_TYPE, "pid", record) record.commit() db.session.commit() indexer = LocationIndexer() indexer.index(record)
def test_on_location_update(): """Test location resolvers.""" indexer = _get_mock() pid = "locid-2" loc = Location.get_record_by_pid(pid) LocationIndexer().index(loc) referenced = _assert_origin(indexer, LOCATION_PID_TYPE, pid) # should re-index internal locations n_intlocs = 1 # from test data _assert_contains(referenced, INTERNAL_LOCATION_PID_TYPE) # should re-index internal items n_items = 1 # from test data _assert_contains(referenced, ITEM_PID_TYPE) assert len(referenced) == n_intlocs + n_items
def testdata(app, db, es_clear, system_user): """Create, index and return test data.""" indexer = RecordIndexer() locations = load_json_from_datadir("locations.json") for location in locations: record = Location.create(location) mint_record_pid(LOCATION_PID_TYPE, "pid", record) record.commit() db.session.commit() indexer.index(record) internal_locations = load_json_from_datadir("internal_locations.json") for internal_location in internal_locations: record = InternalLocation.create(internal_location) mint_record_pid( INTERNAL_LOCATION_PID_TYPE, "pid", record ) record.commit() db.session.commit() indexer.index(record) documents = load_json_from_datadir("documents.json") for doc in documents: record = Document.create(doc) mint_record_pid(DOCUMENT_PID_TYPE, "pid", record) record.commit() db.session.commit() indexer.index(record) items = load_json_from_datadir("items.json") for item in items: record = Item.create(item) mint_record_pid(ITEM_PID_TYPE, "pid", record) record.commit() db.session.commit() indexer.index(record) loans = load_json_from_datadir("loans.json") for loan in loans: record = Loan.create(loan) mint_record_pid(CIRCULATION_LOAN_PID_TYPE, "pid", record) record.commit() db.session.commit() indexer.index(record) series = load_json_from_datadir("series.json") for serie in series: record = Series.create(serie) mint_record_pid(SERIES_PID_TYPE, "pid", record) record.commit() db.session.commit() indexer.index(record) # flush all indices after indexing, otherwise ES won't be ready for tests current_search.flush_and_refresh(index='*') return { "documents": documents, "items": items, "loans": loans, "locations": locations, "series": series, }