コード例 #1
0
def perform_loanshistoricaloverview(uid, ln=CFG_SITE_LANG):
    """
    Display Loans historical overview for user uid.

    @param uid: user id
    @param ln: language of the page

    @return body(html)
    """
    invenio_user_email = db.get_invenio_user_email(uid)
    borrower_id = db.get_borrower_id_by_email(invenio_user_email)
    result = db.get_historical_overview(borrower_id)

    body = bc_templates.tmpl_loanshistoricaloverview(result=result, ln=ln)

    return body
コード例 #2
0
def perform_borrower_loans(uid, barcode, borrower_id,
                           request_id, action, ln=CFG_SITE_LANG):
    """
    Display all the loans and the requests of a given borrower.

    @param barcode: identify the item. Primary key of crcITEM.
    @type barcode: string

    @param borrower_id: identify the borrower. Primary key of crcBORROWER.
    @type borrower_id: int

    @param request_id: identify the request: Primary key of crcLOANREQUEST
    @type request_id: int

    @return body(html)
    """

    _ = gettext_set_language(ln)

    infos = []

    borrower_id = db.get_borrower_id_by_email(db.get_invenio_user_email(uid))

    new_due_date = generate_new_due_date(30)

    #renew loan
    if action == 'renew':
        recid = db.get_id_bibrec(barcode)
        item_description = db.get_item_description(barcode)
        queue = db.get_queue_request(recid, item_description)

        if len(queue) != 0 and queue[0][0] != borrower_id:
            message = "It is not possible to renew your loan for %(x_strong_tag_open)s%(x_title)s%(x_strong_tag_close)s" % {'x_title': book_title_from_MARC(recid), 'x_strong_tag_open': '<strong>', 'x_strong_tag_close': '</strong>'}
            message += ' ' + _("Another user is waiting for this book.")
            infos.append(message)

        else:
            loan_id = db.get_current_loan_id(barcode)
            db.renew_loan(loan_id, new_due_date)
            #update_status_if_expired(loan_id)
            tag_all_requests_as_done(barcode, borrower_id)
            infos.append(_("Your loan has been renewed with success."))

    #cancel request
    elif action == 'cancel':
        db.cancel_request(request_id)
        barcode_requested = db.get_requested_barcode(request_id)
        update_requests_statuses(barcode_requested)

    #renew all loans
    elif action == 'renew_all':
        list_of_barcodes = db.get_borrower_loans_barcodes(borrower_id)
        for bc in list_of_barcodes:
            bc_recid = db.get_id_bibrec(bc)
            item_description = db.get_item_description(bc)
            queue = db.get_queue_request(bc_recid, item_description)

            #check if there are requests
            if len(queue) != 0 and queue[0][0] != borrower_id:
                message = "It is not possible to renew your loan for %(x_strong_tag_open)s%(x_title)s%(x_strong_tag_close)s" % {'x_title': book_title_from_MARC(bc_recid), 'x_strong_tag_open': '<strong>', 'x_strong_tag_close': '</strong>'}
                message += ' ' + _("Another user is waiting for this book.")
                infos.append(message)
            else:
                loan_id = db.get_current_loan_id(bc)
                db.renew_loan(loan_id, new_due_date)
                #update_status_if_expired(loan_id)
                tag_all_requests_as_done(barcode, borrower_id)

        if infos == []:
            infos.append(_("All loans have been renewed with success."))

    loans = db.get_borrower_loans(borrower_id)
    requests = db.get_borrower_requests(borrower_id)
    proposals = db.get_borrower_proposals(borrower_id)

    body = bc_templates.tmpl_yourloans(loans=loans, requests=requests, proposals=proposals,
                                       borrower_id=borrower_id, infos=infos, ln=ln)
    return body
コード例 #3
0
def perform_borrower_loans(uid,
                           barcode,
                           borrower_id,
                           request_id,
                           ln=CFG_SITE_LANG):
    """
    Display all the loans and the requests of a given borrower.

    @param barcode: identify the item. Primary key of crcITEM.
    @type barcode: string

    @param borrower_id: identify the borrower. Primary key of crcBORROWER.
    @type borrower_id: int

    @param request_id: identify the request: Primary key of crcLOANREQUEST
    @type request_id: int

    @return body(html)
    """

    infos = []

    is_borrower = db.is_borrower(db.get_invenio_user_email(uid))
    loans = db.get_borrower_loans(is_borrower)
    requests = db.get_borrower_requests(is_borrower)

    tmp_date = datetime.date.today() + datetime.timedelta(days=30)
    new_due_date = get_datetext(tmp_date.year, tmp_date.month, tmp_date.day)

    #renew loan
    if barcode:
        recid = db.get_id_bibrec(barcode)
        queue = db.get_queue_request(recid)

        if len(queue) != 0:
            infos.append("It is not possible to renew your loan for " \
                         "<strong>" + book_title_from_MARC(recid) + "</strong>. Another user " \
                         "is waiting for this book.")
        else:
            db.update_due_date(barcode, new_due_date)
            infos.append("Your loan has been renewed with sucess.")

    #cancel request
    if request_id:
        db.cancel_request(request_id, 'cancelled')
        make_copy_available(request_id)

    #renew all loans
    elif borrower_id:
        list_of_recids = db.get_borrower_recids(borrower_id)
        for (recid) in list_of_recids:
            queue = db.get_queue_request(recid[0])

            #check if there are requests
            if len(queue) != 0:
                infos.append("It is not possible to renew your loan for " \
                             "<strong>" + book_title_from_MARC(recid) + "</strong>. Another user" \
                             " is waiting for this book.")
            else:
                db.update_due_date_borrower(borrower_id, new_due_date)
        infos.append("All loans have been renewed with success.")

    body = bibcirculation_templates.tmpl_yourloans(loans=loans,
                                                   requests=requests,
                                                   borrower_id=is_borrower,
                                                   infos=infos,
                                                   ln=ln)

    return body
コード例 #4
0
def perform_borrower_loans(uid, barcode, borrower_id,
                           request_id, ln=CFG_SITE_LANG):
    """
    Display all the loans and the requests of a given borrower.

    @param barcode: identify the item. Primary key of crcITEM.
    @type barcode: string

    @param borrower_id: identify the borrower. Primary key of crcBORROWER.
    @type borrower_id: int

    @param request_id: identify the request: Primary key of crcLOANREQUEST
    @type request_id: int

    @return body(html)
    """

    infos = []

    is_borrower = db.is_borrower(db.get_invenio_user_email(uid))
    loans = db.get_borrower_loans(is_borrower)
    requests = db.get_borrower_requests(is_borrower)

    tmp_date = datetime.date.today() + datetime.timedelta(days=30)
    new_due_date = get_datetext(tmp_date.year, tmp_date.month, tmp_date.day)

    #renew loan
    if barcode:
        recid = db.get_id_bibrec(barcode)
        queue = db.get_queue_request(recid)

        if len(queue) != 0:
            infos.append("It is not possible to renew your loan for " \
                         "<strong>" + book_title_from_MARC(recid) + "</strong>. Another user " \
                         "is waiting for this book.")
        else:
            db.update_due_date(barcode, new_due_date)
            infos.append("Your loan has been renewed with sucess.")

    #cancel request
    if request_id:
        db.cancel_request(request_id, 'cancelled')
        make_copy_available(request_id)

    #renew all loans
    elif borrower_id:
        list_of_recids = db.get_borrower_recids(borrower_id)
        for (recid) in list_of_recids:
            queue = db.get_queue_request(recid[0])

            #check if there are requests
            if len(queue) != 0:
                infos.append("It is not possible to renew your loan for " \
                             "<strong>" + book_title_from_MARC(recid) + "</strong>. Another user" \
                             " is waiting for this book.")
            else:
                db.update_due_date_borrower(borrower_id,
                                            new_due_date)
        infos.append("All loans have been renewed with success.")

    body = bibcirculation_templates.tmpl_yourloans(loans=loans,
                                                   requests=requests,
                                                   borrower_id=is_borrower,
                                                   infos=infos,
                                                   ln=ln)

    return body