Пример #1
0
def get_loans(document_pid):
    """Get referenced loans."""
    referenced = []
    loan_record_cls = current_app_ils.loan_record_cls
    for loan in search_loans_by_pid(document_pid=document_pid).scan():
        loan = loan_record_cls.get_record_by_pid(loan["pid"])
        referenced.append(dict(pid_type=CIRCULATION_LOAN_PID_TYPE,
                               record=loan))
    return referenced
Пример #2
0
def index_loans_after_item_indexed(item_pid):
    """Index loan to refresh item reference."""
    log_func = partial(_log,
                       origin_rec_type='Item',
                       origin_recid=item_pid,
                       dest_rec_type='Loan')

    log_func(msg=MSG_ORIGIN)
    for loan in search_loans_by_pid(item_pid=item_pid).scan():
        loan_pid = loan["pid"]
        _index_record_by_pid(Loan, loan_pid, log_func)
Пример #3
0
def index_referenced_records(item):
    """Index referenced records."""
    indexer = ReferencedRecordsIndexer()
    indexed = dict(pid_type=ITEM_PID_TYPE, record=item)
    referenced = []

    # fetch and index loans
    loan_record_cls = current_circulation.loan_record_cls
    item_pid = dict(type=ITEM_PID_TYPE, value=item["pid"])
    for loan in search_loans_by_pid(item_pid=item_pid).scan():
        loan = loan_record_cls.get_record_by_pid(loan["pid"])
        referenced.append(dict(pid_type=CIRCULATION_LOAN_PID_TYPE,
                               record=loan))

    # fetch and index the document
    document_cls = current_app_ils.document_record_cls
    document = document_cls.get_record_by_pid(item["document_pid"])
    referenced.append(dict(pid_type=DOCUMENT_PID_TYPE, record=document))

    indexer.index(indexed, referenced)