Beispiel #1
0
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",
            "circulation",
            "edition",
            "document_type",
            "pid",
            "title",
            # TODO: add the imprint year here
        )

    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 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 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")
Beispiel #6
0
 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 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")
Beispiel #8
0
def field_loan(metadata):
    """Get the loan object and add it to the metadata."""
    loan_pid = metadata.get("loan_pid")
    if not loan_pid:
        return
    Loan = current_app_ils.loan_record_cls
    try:
        loan = Loan.get_record_by_pid(loan_pid)
    except PIDDeletedError:
        metadata["loan"] = {"name": "This loan was deleted."}
        return
    except PIDDoesNotExistError:
        metadata["loan"] = {"name": "Invalid Loan PID."}
        return
    metadata["loan"] = pick(loan, "pid", "start_date", "end_date", "state")
Beispiel #9
0
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:
        item = pick(
            item,
            "barcode",  # not set in BorrowingRequest
            "description",
            "document_pid",
            "medium",  # not set in BorrowingRequest
            "pid",
        )

    return item
Beispiel #10
0
 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, "pid", "title", "edition", "publication_year")