Esempio n. 1
0
def perform_new_request_send_message(uid, recid, period_from, period_to, barcode,
                                     status, mail_subject, mail_template,
                                     mail_remarks='', ln=CFG_SITE_LANG):

    user = collect_user_info(uid)

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

    if borrower != ():
        borrower_id = borrower[0][0]
        if db.is_doc_already_requested(recid, barcode, borrower_id):
            message = bc_templates.tmpl_message_send_already_requested()
            return bc_templates.tmpl_new_request_send(message=message, ln=ln)

        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)


        location = '-'
        library = ''
        request_date = ''
        if status != CFG_BIBCIRCULATION_REQUEST_STATUS_PROPOSED:
            details = db.get_loan_request_details(req_id)
            if details:
                library = details[3]
                location = details[4]
                request_date = details[7]

        message_template = load_template(mail_template)

        # A message to be sent to the user detailing his loan request
        # or his new book proposal.
        if status == CFG_BIBCIRCULATION_REQUEST_STATUS_PROPOSED:
            message_for_user = message_template % (title)
        else:
            link_to_holdings_details = CFG_SITE_URL + \
                '/record/%s/holdings' % str(recid)
            message_for_user = message_template % (name, ccid, email, address,
                                            mailbox, title, author, publisher,
                                            year, isbn, location, library,
                                            link_to_holdings_details, request_date)

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

        if status == CFG_BIBCIRCULATION_REQUEST_STATUS_PENDING:
            # A message to be sent to the librarian about the pending status.
            link_to_item_request_details = CFG_SITE_URL + \
                "/admin2/bibcirculation/get_item_requests_details?ln=%s&recid=%s" \
                % (ln, str(recid))
            message_for_librarian = message_template % (name, ccid, email, address,
                                        mailbox, title, author, publisher,
                                        year, isbn, location, library,
                                        link_to_item_request_details,
                                        request_date)
            send_email(fromaddr = CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
                       toaddr   = CFG_BIBCIRCULATION_LOANS_EMAIL,
                       subject  = mail_subject,
                       content  = message_for_librarian,
                       header   = '',
                       footer   = '',
                       attempt_times=1,
                       attempt_sleeptime=10
                      )

        if CFG_CERN_SITE:
            if status == CFG_BIBCIRCULATION_REQUEST_STATUS_PROPOSED:
                message = bc_templates.tmpl_message_proposal_send_ok_cern()
            else:
                message = bc_templates.tmpl_message_request_send_ok_cern()
        else:
            if status == CFG_BIBCIRCULATION_REQUEST_STATUS_PROPOSED:
                message = bc_templates.tmpl_message_proposal_send_ok_other()
            else:
                message = bc_templates.tmpl_message_request_send_ok_other()

    else:
        if CFG_CERN_SITE:
            message = bc_templates.tmpl_message_request_send_fail_cern("Borrower ID not found")
        else:
            message = bc_templates.tmpl_message_request_send_fail_other("Borrower ID not found")

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

    return body
Esempio n. 2
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
Esempio n. 3
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
Esempio n. 4
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
Esempio n. 5
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
Esempio n. 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