def item_resolver(loan_pid): """Resolve an Item given a Loan PID.""" Loan = current_circulation.loan_record_cls loan = Loan.get_record_by_pid(loan_pid) if not loan.get("item_pid"): return {} try: # can resolve to an Item or BorrowingRequest item = resolve_item_from_loan(loan["item_pid"]) except PIDDeletedError: item = {} else: # if it the item is a BorrowingRequest, then some of these # fields might not be there item = pick( item, "barcode", "description", "document_pid", "medium", "pid", ) return item
def document_resolver(loan_pid): """Resolve a Document given a Loan PID.""" Loan = current_circulation.loan_record_cls try: document_pid = get_field_value(Loan, loan_pid, "document_pid") except KeyError: return {} Document = current_app_ils.document_record_cls try: document = Document.get_record_by_pid(document_pid) except PIDDeletedError: obj = {} else: obj = pick( document, "authors", "cover_metadata", "document_type", "edition", "identifiers", "open_access", "pid", "publication_year", "title", ) return obj
def vendor_resolver(order_pid): """Return the Vendor for the given Order.""" Order = current_ils_acq.order_record_cls Vendor = current_ils_acq.vendor_record_cls vendor_pid = get_field_value(Order, order_pid, "vendor_pid") vendor = Vendor.get_record_by_pid(vendor_pid) return pick(vendor, "pid", "name", "address", "email", "phone", "notes")
def get_document(document_pid): """Return the Document record.""" Document = current_app_ils.document_record_cls document = Document.get_record_by_pid(document_pid) obj = pick(document, "authors", "cover_metadata", "edition", "pid", "publication_year", "title", "document_type") obj["authors"] = flatten_authors(obj["authors"]) return obj
def borrowing_request_resolver(request_pid): """Return the Library record for the given Brw Request or raise.""" request_record_cls = current_ils_ill.borrowing_request_record_cls library_pid = get_field_value(request_record_cls, request_pid, "library_pid") library_record_cls = current_ils_ill.library_record_cls library = library_record_cls.get_record_by_pid(library_pid) return pick(library, "pid", "name")
def field_transaction_user(metadata): """Get the transaction location object and add it a property.""" transaction_user_pid = metadata.get("transaction_user_pid") if not transaction_user_pid: return Patron = current_app_ils.patron_cls try: transaction_user = Patron.get_patron(transaction_user_pid) except PIDDeletedError: return metadata["transaction_user"] = pick(transaction_user, "name")
def get_document(document_pid): """Return the Document record.""" Document = current_app_ils.document_record_cls document = Document.get_record_by_pid(document_pid) return pick( document, "cover_metadata", "edition", "pid", "publication_year", "title", )
def get_relevant_fields_from(self, record): """Get relevant fields from the related record.""" fields = pick( record, "title", "edition", "publication_year", "languages", "document_type", "mode_of_issuance", ) return dict(record_metadata=fields)
def document_resolver(order_line, doc): """Resolve the Document for the given Order Line.""" order_line["document"] = pick( doc, "authors", "cover_metadata", "edition", "pid", "publication_year", "title", ) order_line["document"]["authors"] = flatten_authors( order_line["document"]["authors"]) return doc
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 field_pickup_location(metadata): """Get the pickup location object and add it a property.""" pickup_location_pid = metadata.get("pickup_location_pid") if not pickup_location_pid: return Location = current_app_ils.location_record_cls try: pickup_location = Location.get_record_by_pid(pickup_location_pid) except PIDDeletedError: metadata["pickup_location"] = {"name": "This location was deleted."} return except PIDDoesNotExistError: metadata["pickup_location"] = {"name": "Location PID invalid."} return metadata["pickup_location"] = pick(pickup_location, "name")
def provider_resolver(order_pid): """Return the Provider for the given Order.""" Order = current_ils_acq.order_record_cls Provider = current_ils_prov.provider_record_cls provider_pid = get_field_value(Order, order_pid, "provider_pid") provider = Provider.get_record_by_pid(provider_pid) return pick( provider, "pid", "name", "address", "email", "phone", "notes", "type", )
def field_loan(metadata): """Get the loan object and add it to the metadata.""" loan_pid = metadata.get("patron_loan", {}).get("pid") if not loan_pid: return Loan = current_circulation.loan_record_cls try: loan = Loan.get_record_by_pid(loan_pid) except PIDDeletedError: metadata["patron_loan"]["loan"] = {"pid": "This loan was deleted."} return except PIDDoesNotExistError: metadata["patron_loan"]["loan"] = {"pid": "Invalid Loan PID."} return metadata["patron_loan"]["loan"] = pick( loan, "pid", "start_date", "end_date", "state", "extension_count" )
def borrowing_request_resolver(request_pid): """Return the Provider record for the given Brw Request or raise.""" request_record_cls = current_ils_ill.borrowing_request_record_cls provider_pid = get_field_value(request_record_cls, request_pid, "provider_pid") provider_record_cls = current_ils_prov.provider_record_cls provider = provider_record_cls.get_record_by_pid(provider_pid) return pick( provider, "pid", "name", "address", "email", "phone", "notes", "type", )
def dump(self): """Dump email data.""" data = pick( self.__dict__, "attachments", "bcc", "cc", "date", "extra_headers", "id", "mail_options", "msgId", "recipients", "reply_to", "sender", "subject", "template", ) data["msg_cls"] = self.__class__.__name__ return data
def document_resolver(order_line, doc): """Resolve the Document for the given Order Line.""" order_line["document"] = pick(doc, "cover_metadata", "pid", "title") return doc
def document_resolver(order_line, doc): """Resolve the Document for the given Order Line.""" order_line["document"] = pick(doc, 'cover_metadata', 'pid', 'title') return doc