コード例 #1
0
ファイル: utils.py プロジェクト: mhellmic/b2share
def update_requests_statuses(barcode):

    recid = db.get_id_bibrec(barcode)
    description = db.get_item_description(barcode)

    list_of_pending_requests = db.get_requests(recid, description,
                                    CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING)
    some_copy_available = False
    copies_status = db.get_copies_status(recid, description)
    if copies_status is not None:
        for status in copies_status:
            if status in (CFG_BIBCIRCULATION_ITEM_STATUS_ON_SHELF,
                          CFG_BIBCIRCULATION_ITEM_STATUS_IN_PROCESS):
                some_copy_available = True

    if len(list_of_pending_requests) == 1:
        if not some_copy_available:
            db.update_loan_request_status(CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING,
                                          list_of_pending_requests[0][0])
        else:
            return list_of_pending_requests[0][0]

    elif len(list_of_pending_requests) == 0:
        if some_copy_available:
            list_of_waiting_requests = db.get_requests(recid, description,
                                    CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING)
            if len(list_of_waiting_requests) > 0:
                db.update_loan_request_status(CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING,
                                              list_of_waiting_requests[0][0])
                return list_of_waiting_requests[0][0]

    elif len(list_of_pending_requests) > 1:
        for request in list_of_pending_requests:
            db.update_loan_request_status(CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING,
                                          request[0])
        list_of_waiting_requests = db.get_requests(recid, description,
                                    CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING)
        if some_copy_available:
            db.update_loan_request_status(CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING,
                                          list_of_waiting_requests[0][0])
            return list_of_waiting_requests[0][0]

    return None
コード例 #2
0
def update_requests_statuses(barcode):

    recid = db.get_id_bibrec(barcode)
    description = db.get_item_description(barcode)

    list_of_pending_requests = db.get_requests(recid, description,
                                    CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING)
    some_copy_available = False
    copies_status = db.get_copies_status(recid, description)
    if copies_status is not None:
        for status in copies_status:
            if status in (CFG_BIBCIRCULATION_ITEM_STATUS_ON_SHELF,
                          CFG_BIBCIRCULATION_ITEM_STATUS_IN_PROCESS):
                some_copy_available = True

    if len(list_of_pending_requests) == 1:
        if not some_copy_available:
            db.update_loan_request_status(CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING,
                                          list_of_pending_requests[0][0])
        else:
            return list_of_pending_requests[0][0]

    elif len(list_of_pending_requests) == 0:
        if some_copy_available:
            list_of_waiting_requests = db.get_requests(recid, description,
                                    CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING)
            if len(list_of_waiting_requests) > 0:
                db.update_loan_request_status(CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING,
                                              list_of_waiting_requests[0][0])
                return list_of_waiting_requests[0][0]

    elif len(list_of_pending_requests) > 1:
        for request in list_of_pending_requests:
            db.update_loan_request_status(CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING,
                                          request[0])
        list_of_waiting_requests = db.get_requests(recid, description,
                                    CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING)
        if some_copy_available:
            db.update_loan_request_status(CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING,
                                          list_of_waiting_requests[0][0])
            return list_of_waiting_requests[0][0]

    return None
コード例 #3
0
ファイル: utils.py プロジェクト: mhellmic/b2share
def tag_all_requests_as_done(barcode, user_id):
    recid = db.get_id_bibrec(barcode)
    description = db.get_item_description(barcode)
    list_of_barcodes = db.get_barcodes(recid, description)
    for bc in list_of_barcodes:
        db.tag_requests_as_done(user_id, bc)
コード例 #4
0
ファイル: api.py プロジェクト: SCOAP3/invenio
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
コード例 #5
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
コード例 #6
0
def tag_all_requests_as_done(barcode, user_id):
    recid = db.get_id_bibrec(barcode)
    description = db.get_item_description(barcode)
    list_of_barcodes = db.get_barcodes(recid, description)
    for bc in list_of_barcodes:
        db.tag_requests_as_done(user_id, bc)