예제 #1
0
def perform_new_request_send(uid, recid, period_from, period_to,
                             barcode, ln=CFG_SITE_LANG):

    """
    @param recid: recID - Invenio record identifier
    @param ln: language of the page
    """

    nb_requests = 0
    all_copies_on_loan = True
    description = db.get_item_description(barcode)
    copies = db.get_barcodes(recid, description)
    for bc in copies:
        nb_requests += db.get_number_requests_per_copy(bc)
        if db.is_item_on_loan(bc) is None:
            all_copies_on_loan = False

    if nb_requests == 0:
        if all_copies_on_loan:
            status = CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING
        else:
            status = CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING
    else:
        status = CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING

    return perform_new_request_send_message(uid, recid, period_from, period_to, barcode,
                                            status, mail_subject='New request',
                                            mail_template='notification',
					    mail_remarks='', ln=ln)
예제 #2
0
def update_request_data(request_id):
    """
    Update the status of a given request.

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

    barcode = db.get_request_barcode(request_id)
    is_on_loan = db.is_item_on_loan(barcode)

    if is_on_loan is not None:
        db.update_item_status(CFG_BIBCIRCULATION_ITEM_STATUS_ON_LOAN, barcode)
    else:
        db.update_item_status(CFG_BIBCIRCULATION_ITEM_STATUS_ON_SHELF, barcode)

    update_requests_statuses(barcode)

    return True
예제 #3
0
def update_request_data(request_id):
    """
    Update the status of a given request.

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

    barcode = db.get_request_barcode(request_id)
    is_on_loan = db.is_item_on_loan(barcode)

    if is_on_loan is not None:
        db.update_item_status(CFG_BIBCIRCULATION_ITEM_STATUS_ON_LOAN, barcode)
    else:
        db.update_item_status(CFG_BIBCIRCULATION_ITEM_STATUS_ON_SHELF, barcode)

    update_requests_statuses(barcode)

    return True
def update_request_data(request_id):
    """
    Update the status of a given request.

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

    barcode = db.get_request_barcode(request_id)
    nb_requests = db.get_number_requests_per_copy(barcode)
    is_on_loan = db.is_item_on_loan(barcode)

    if nb_requests == 0 and is_on_loan is not None:
        db.update_item_status('on loan', barcode)
    elif nb_requests == 0 and is_on_loan is None:
        db.update_item_status('available', barcode)
    else:
        db.update_item_status('requested', barcode)

    return
def update_request_data(request_id):
    """
    Update the status of a given request.

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

    barcode = db.get_request_barcode(request_id)
    nb_requests = db.get_number_requests_per_copy(barcode)
    is_on_loan = db.is_item_on_loan(barcode)

    if nb_requests == 0 and is_on_loan is not None:
        db.update_item_status('on loan', barcode)
    elif nb_requests == 0 and is_on_loan is None:
        db.update_item_status('available', barcode)
    else:
        db.update_item_status('requested', barcode)

    return
예제 #6
0
def perform_new_request_send(uid, recid, period_from, period_to,
                             barcode, ln=CFG_SITE_LANG):

    """
    @param recid: recID - Invenio record identifier
    @param ln: language of the page
    """

    nb_requests = 0
    all_copies_on_loan = True
    copies = db.get_barcodes(recid)
    for bc in copies:
        nb_requests += db.get_number_requests_per_copy(bc)
        if db.is_item_on_loan(bc) is None:
            all_copies_on_loan = False

    if nb_requests == 0:
        if all_copies_on_loan:
            status = CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING
        else:
            status = CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING
    else:
        status = CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING

    user = collect_user_info(uid)
    if CFG_CERN_SITE:
        try:
            borrower = search_user('ccid', user['external_hidden_personid'])
        except:
            borrower = ()
    else:
        borrower = search_user('email', user['email'])

    if borrower != ():
        borrower = borrower[0]
        borrower_id = borrower[0]
        borrower_details = db.get_borrower_details(borrower_id)
        (_id, ccid, name, email, _phone, address, mailbox) = borrower_details

        (title, year, author,
         isbn, publisher) = book_information_from_MARC(recid)

        req_id = db.new_hold_request(borrower_id, recid, barcode,
                                period_from, period_to, status)

        details = db.get_loan_request_details(req_id)
        if details:
            library = details[3]
            location = details[4]
            request_date = details[7]
        else:
            location = ''
            library = ''
            request_date = ''

        link_to_holdings_details = CFG_SITE_URL + \
                                   '/record/%s/holdings' % str(recid)

        link_to_item_request_details = CFG_SITE_URL + \
            "/admin2/bibcirculation/get_item_requests_details?ln=%s&recid=%s" \
                % (ln, str(recid))

        subject = 'New request'
        message_template = load_template('notification')

        message_for_user = message_template % (name, ccid, email, address,
                                        mailbox, title, author, publisher,
                                        year, isbn, location, library,
                                        link_to_holdings_details, request_date)

        message_for_librarian = message_template % (name, ccid, email, address,
                                        mailbox, title, author, publisher,
                                        year, isbn, location, library,
                                        link_to_item_request_details,
                                        request_date)

        if status == CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING:
            send_email(fromaddr = CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
                       toaddr   = CFG_BIBCIRCULATION_LOANS_EMAIL,
                       subject  = subject,
                       content  = message_for_librarian,
                       header   = '',
                       footer   = '',
                       attempt_times=1,
                       attempt_sleeptime=10
                      )

        send_email(fromaddr = CFG_BIBCIRCULATION_LOANS_EMAIL,
                   toaddr   = email,
                   subject  = subject,
                   content  = message_for_user,
                   header   = '',
                   footer   = '',
                   attempt_times=1,
                   attempt_sleeptime=10
                  )

        if CFG_CERN_SITE:
            message = bc_templates.tmpl_message_request_send_ok_cern()
        else:
            message = bc_templates.tmpl_message_request_send_ok_other()

    else:
        if CFG_CERN_SITE:
            message = bc_templates.tmpl_message_request_send_fail_cern()
        else:
            message = bc_templates.tmpl_message_request_send_fail_other()

    body = bc_templates.tmpl_new_request_send(message=message, ln=ln)

    return body
예제 #7
0
def perform_new_request_send(uid,
                             recid,
                             period_from,
                             period_to,
                             barcode,
                             ln=CFG_SITE_LANG):
    """
    @param recid: recID - Invenio record identifier
    @param ln: language of the page
    """

    nb_requests = db.get_number_requests_per_copy(barcode)
    is_on_loan = db.is_item_on_loan(barcode)

    if nb_requests == 0 and is_on_loan is not None:
        status = 'waiting'
    elif nb_requests == 0 and is_on_loan is None:
        status = 'pending'
    else:
        status = 'waiting'

    user = collect_user_info(uid)
    is_borrower = db.is_borrower(user['email'])

    if is_borrower != 0:
        address = db.get_borrower_address(user['email'])
        if address != 0:

            db.new_hold_request(is_borrower, recid, barcode, period_from,
                                period_to, status)

            is_on_loan = db.is_item_on_loan(barcode)

            db.update_item_status('requested', barcode)

            if not is_on_loan:
                send_email(fromaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
                           toaddr=CFG_SITE_SUPPORT_EMAIL,
                           subject='Hold request for books confirmation',
                           content=hold_request_mail(recid, is_borrower),
                           attempt_times=1,
                           attempt_sleeptime=10)
            if CFG_CERN_SITE == 1:
                message = bibcirculation_templates.tmpl_message_request_send_ok_cern(
                )
            else:
                message = bibcirculation_templates.tmpl_message_request_send_ok_other(
                )

        else:
            if CFG_CERN_SITE == 1:
                email = user['email']
                result = get_user_info_from_ldap(email)

                try:
                    ldap_address = result['physicalDeliveryOfficeName'][0]
                except KeyError:
                    ldap_address = None

                if ldap_address is not None:
                    db.add_borrower_address(ldap_address, email)

                    db.new_hold_request(is_borrower, recid, barcode,
                                        period_from, period_to, status)

                    db.update_item_status('requested', barcode)

                    send_email(fromaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
                               toaddr=CFG_SITE_SUPPORT_EMAIL,
                               subject='Hold request for books confirmation',
                               content=hold_request_mail(recid, is_borrower),
                               attempt_times=1,
                               attempt_sleeptime=10)

                    message = bibcirculation_templates.tmpl_message_request_send_ok_cern(
                        ln=ln)

                else:
                    message = bibcirculation_templates.tmpl_message_request_send_fail_cern(
                        ln=ln)

            else:
                message = bibcirculation_templates.tmpl_message_request_send_fail_other(
                    ln=ln)

    else:
        if CFG_CERN_SITE == 1:
            result = get_user_info_from_ldap(email=user['email'])

            try:
                name = result['cn'][0]
            except KeyError:
                name = None

            try:
                email = result['mail'][0]
            except KeyError:
                email = None

            try:
                phone = result['telephoneNumber'][0]
            except KeyError:
                phone = None

            try:
                address = result['physicalDeliveryOfficeName'][0]
            except KeyError:
                address = None

            try:
                mailbox = result['postOfficeBox'][0]
            except KeyError:
                mailbox = None

            if address is not None:
                db.new_borrower(name, email, phone, address, mailbox, '')

                is_borrower = db.is_borrower(email)

                db.new_hold_request(is_borrower, recid, barcode, period_from,
                                    period_to, status)

                db.update_item_status('requested', barcode)

                send_email(fromaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
                           toaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
                           subject='Hold request for books confirmation',
                           content=hold_request_mail(recid, is_borrower),
                           attempt_times=1,
                           attempt_sleeptime=10)
                message = bibcirculation_templates.tmpl_message_request_send_ok_cern(
                )

            else:
                message = bibcirculation_templates.tmpl_message_request_send_fail_cern(
                )

        else:
            message = bibcirculation_templates.tmpl_message_request_send_ok_other(
            )

    body = bibcirculation_templates.tmpl_new_request_send(message=message,
                                                          ln=ln)

    return body
예제 #8
0
def perform_new_request_send(uid, recid,
                             period_from, period_to,
                             barcode, ln=CFG_SITE_LANG):

    """
    @param recid: recID - Invenio record identifier
    @param ln: language of the page
    """

    nb_requests = db.get_number_requests_per_copy(barcode)
    is_on_loan = db.is_item_on_loan(barcode)

    if nb_requests == 0 and is_on_loan is not None:
        status = 'waiting'
    elif nb_requests == 0 and is_on_loan is None:
        status = 'pending'
    else:
        status = 'waiting'

    user = collect_user_info(uid)
    is_borrower = db.is_borrower(user['email'])

    if is_borrower != 0:
        address = db.get_borrower_address(user['email'])
        if address != 0:

            db.new_hold_request(is_borrower, recid, barcode,
                                period_from, period_to, status)

            is_on_loan=db.is_item_on_loan(barcode)

            db.update_item_status('requested', barcode)

            if not is_on_loan:
                send_email(fromaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
                       toaddr=CFG_SITE_SUPPORT_EMAIL,
                       subject='Hold request for books confirmation',
                       content=hold_request_mail(recid, is_borrower),
                       attempt_times=1,
                       attempt_sleeptime=10
                       )
            if CFG_CERN_SITE == 1:
                message = bibcirculation_templates.tmpl_message_request_send_ok_cern()
            else:
                message = bibcirculation_templates.tmpl_message_request_send_ok_other()

        else:
            if CFG_CERN_SITE == 1:
                email=user['email']
                result = get_user_info_from_ldap(email)

                try:
                    ldap_address = result['physicalDeliveryOfficeName'][0]
                except KeyError:
                    ldap_address = None

                if ldap_address is not None:
                    db.add_borrower_address(ldap_address, email)

                    db.new_hold_request(is_borrower, recid, barcode,
                                        period_from, period_to, status)

                    db.update_item_status('requested', barcode)

                    send_email(fromaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
                               toaddr=CFG_SITE_SUPPORT_EMAIL,
                               subject='Hold request for books confirmation',
                               content=hold_request_mail(recid, is_borrower),
                               attempt_times=1,
                               attempt_sleeptime=10
                               )

                    message = bibcirculation_templates.tmpl_message_request_send_ok_cern(ln=ln)

                else:
                    message = bibcirculation_templates.tmpl_message_request_send_fail_cern(ln=ln)

            else:
                message = bibcirculation_templates.tmpl_message_request_send_fail_other(ln=ln)


    else:
        if CFG_CERN_SITE == 1:
            result = get_user_info_from_ldap(email=user['email'])

            try:
                name = result['cn'][0]
            except KeyError:
                name = None

            try:
                email = result['mail'][0]
            except KeyError:
                email = None

            try:
                phone = result['telephoneNumber'][0]
            except KeyError:
                phone = None

            try:
                address = result['physicalDeliveryOfficeName'][0]
            except KeyError:
                address = None

            try:
                mailbox = result['postOfficeBox'][0]
            except KeyError:
                mailbox = None

            if address is not None:
                db.new_borrower(name, email, phone, address, mailbox, '')

                is_borrower = db.is_borrower(email)

                db.new_hold_request(is_borrower, recid, barcode,
                                    period_from, period_to, status)

                db.update_item_status('requested', barcode)

                send_email(fromaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
                           toaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
                           subject='Hold request for books confirmation',
                           content=hold_request_mail(recid, is_borrower),
                           attempt_times=1,
                           attempt_sleeptime=10
                           )
                message = bibcirculation_templates.tmpl_message_request_send_ok_cern()

            else:
                message = bibcirculation_templates.tmpl_message_request_send_fail_cern()

        else:
            message = bibcirculation_templates.tmpl_message_request_send_ok_other()

    body = bibcirculation_templates.tmpl_new_request_send(message=message, ln=ln)

    return body
예제 #9
0
def perform_new_request_send(
    uid, recid, from_year, from_month, from_day, to_year, to_month, to_day, barcode, ln=CFG_SITE_LANG
):

    """
    @param recid: recID - CDS Invenio record identifier
    @param ln: language of the page
    """

    request_from = get_datetext(from_year, from_month, from_day)
    request_to = get_datetext(to_year, to_month, to_day)

    nb_requests = db.get_number_requests_per_copy(barcode)
    is_on_loan = db.is_item_on_loan(barcode)

    if nb_requests == 0 and is_on_loan is not None:
        status = "waiting"
    elif nb_requests == 0 and is_on_loan is None:
        status = "pending"
    else:
        status = "waiting"

    user = collect_user_info(uid)
    is_borrower = db.is_borrower(user["email"])

    if is_borrower != 0:
        address = db.get_borrower_address(user["email"])
        if address != 0:

            db.new_hold_request(is_borrower, recid, barcode, request_from, request_to, status)
            db.update_item_status("requested", barcode)

            send_email(
                fromaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
                toaddr=CFG_SITE_SUPPORT_EMAIL,
                subject="Hold request for books confirmation",
                content=hold_request_mail(recid, is_borrower),
                attempt_times=1,
                attempt_sleeptime=10,
            )
            if CFG_CERN_SITE == 1:
                message = bibcirculation_templates.tmpl_message_request_send_ok_cern(ln=ln)
            else:
                message = bibcirculation_templates.tmpl_message_request_send_ok_other(ln=ln)

        else:
            if CFG_CERN_SITE == 1:
                email = user["email"]
                result = get_user_info_from_ldap(email)

                try:
                    ldap_address = result["physicalDeliveryOfficeName"][0]
                except KeyError:
                    ldap_address = None

                if ldap_address is not None:
                    db.add_borrower_address(ldap_address, email)

                    db.new_hold_request(is_borrower, recid, barcode, request_from, request_to, status)

                    db.update_item_status("requested", barcode)

                    send_email(
                        fromaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
                        toaddr=CFG_SITE_SUPPORT_EMAIL,
                        subject="Hold request for books confirmation",
                        content=hold_request_mail(recid, is_borrower),
                        attempt_times=1,
                        attempt_sleeptime=10,
                    )

                    message = bibcirculation_templates.tmpl_message_request_send_ok_cern(ln=ln)

                else:
                    message = bibcirculation_templates.tmpl_message_request_send_fail_cern(ln=ln)

            else:
                message = bibcirculation_templates.tmpl_message_request_send_fail_other(ln=ln)

    else:
        if CFG_CERN_SITE == 1:
            result = get_user_info_from_ldap(email=user["email"])

            try:
                name = result["cn"][0]
            except KeyError:
                name = None

            try:
                email = result["mail"][0]
            except KeyError:
                email = None

            try:
                phone = result["telephoneNumber"][0]
            except KeyError:
                phone = None

            try:
                address = result["physicalDeliveryOfficeName"][0]
            except KeyError:
                address = None

            try:
                mailbox = result["postOfficeBox"][0]
            except KeyError:
                mailbox = None

            if address is not None:
                db.new_borrower(name, email, phone, address, mailbox, "")

                is_borrower = db.is_borrower(email)

                db.new_hold_request(is_borrower, recid, barcode, request_from, request_to, status)

                db.update_item_status("requested", barcode)

                send_email(
                    fromaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
                    toaddr=CFG_SITE_SUPPORT_EMAIL,
                    subject="Hold request for books confirmation",
                    content=hold_request_mail(recid, is_borrower),
                    attempt_times=1,
                    attempt_sleeptime=10,
                )
                message = bibcirculation_templates.tmpl_message_request_send_ok_cern(ln=ln)

            else:
                message = bibcirculation_templates.tmpl_message_request_send_fail_cern(ln=ln)

        else:
            message = bibcirculation_templates.tmpl_message_request_send_ok_other(ln=ln)

    body = bibcirculation_templates.tmpl_new_request_send(message=message, ln=ln)

    return body
예제 #10
0
def perform_new_request_send(uid,
                             recid,
                             period_from,
                             period_to,
                             barcode,
                             ln=CFG_SITE_LANG):
    """
    @param recid: recID - Invenio record identifier
    @param ln: language of the page
    """

    nb_requests = 0
    all_copies_on_loan = True
    copies = db.get_barcodes(recid)
    for bc in copies:
        nb_requests += db.get_number_requests_per_copy(bc)
        if db.is_item_on_loan(bc) is None:
            all_copies_on_loan = False

    if nb_requests == 0:
        if all_copies_on_loan:
            status = CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING
        else:
            status = CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING
    else:
        status = CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING

    user = collect_user_info(uid)
    if CFG_CERN_SITE:
        try:
            borrower = search_user('ccid', user['external_hidden_personid'])
        except:
            borrower = ()
    else:
        borrower = search_user('email', user['email'])

    if borrower != ():
        borrower = borrower[0]
        borrower_id = borrower[0]
        borrower_details = db.get_borrower_details(borrower_id)
        (_id, ccid, name, email, _phone, address, mailbox) = borrower_details

        (title, year, author, isbn,
         publisher) = book_information_from_MARC(recid)

        req_id = db.new_hold_request(borrower_id, recid, barcode, period_from,
                                     period_to, status)

        details = db.get_loan_request_details(req_id)
        if details:
            library = details[3]
            location = details[4]
            request_date = details[7]
        else:
            location = ''
            library = ''
            request_date = ''

        link_to_holdings_details = CFG_SITE_URL + \
                                   '/record/%s/holdings' % str(recid)

        link_to_item_request_details = CFG_SITE_URL + \
            "/admin2/bibcirculation/get_item_requests_details?ln=%s&recid=%s" \
                % (ln, str(recid))

        subject = 'New request'
        message_template = load_template('notification')

        message_for_user = message_template % (
            name, ccid, email, address, mailbox, title, author, publisher,
            year, isbn, location, library, link_to_holdings_details,
            request_date)

        message_for_librarian = message_template % (
            name, ccid, email, address, mailbox, title, author, publisher,
            year, isbn, location, library, link_to_item_request_details,
            request_date)

        if status == CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING:
            send_email(fromaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
                       toaddr=CFG_BIBCIRCULATION_LOANS_EMAIL,
                       subject=subject,
                       content=message_for_librarian,
                       header='',
                       footer='',
                       attempt_times=1,
                       attempt_sleeptime=10)

        send_email(fromaddr=CFG_BIBCIRCULATION_LOANS_EMAIL,
                   toaddr=email,
                   subject=subject,
                   content=message_for_user,
                   header='',
                   footer='',
                   attempt_times=1,
                   attempt_sleeptime=10)

        if CFG_CERN_SITE:
            message = bc_templates.tmpl_message_request_send_ok_cern()
        else:
            message = bc_templates.tmpl_message_request_send_ok_other()

    else:
        if CFG_CERN_SITE:
            message = bc_templates.tmpl_message_request_send_fail_cern()
        else:
            message = bc_templates.tmpl_message_request_send_fail_other()

    body = bc_templates.tmpl_new_request_send(message=message, ln=ln)

    return body