Ejemplo n.º 1
0
def hold_request_mail(recid, borrower_id):
    """
    Create the mail who will be sent for each hold requests.

    @param recid: identify the record. Primary key of bibrec.
    @type recid: int

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

    @return email(body)
    """

    (book_title, book_year, book_author, book_isbn, book_editor) = book_information_from_MARC(recid)

    ############## need some code refactoring ###############

    more_holdings_infos = db.get_holdings_details(recid)
    borrower_infos = db.get_borrower_details(borrower_id)

    #########################################################

    title_link = create_html_link(
        CFG_SITE_URL + "/admin/bibcirculation/bibcirculationadmin.py/get_item_details", {"recid": recid}, (book_title)
    )

    out = """

           This is an automatic email for confirming the hold request for a
           book on behalf of:

            %s (email: %s)

            title: %s
            author: %s
            location: %s
            library: %s
            publisher: %s
            year: %s
            isbn: %s

    """ % (
        borrower_infos[1],
        borrower_infos[2],
        title_link,
        book_author,
        more_holdings_infos[0][1],
        more_holdings_infos[0][2],
        book_editor,
        book_year,
        book_isbn,
    )

    return out
Ejemplo n.º 2
0
def hold_request_mail(recid, borrower_id):
    """
    Create the mail who will be sent for each hold requests.

    @param recid: identify the record. Primary key of bibrec.
    @type recid: int

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

    @return email(body)
    """

    (book_title, book_year, book_author,
    book_isbn, book_editor) = book_information_from_MARC(recid)

    ############## need some code refactoring ###############

    more_holdings_infos = db.get_holdings_details(recid)
    borrower_infos = db.get_borrower_details(borrower_id)

    #########################################################

    title_link = create_html_link(CFG_SITE_URL +
                                  '/admin/bibcirculation/bibcirculationadmin.py/get_item_details',
                                  {'recid': recid},
                                  (book_title))

    out = """

           This is an automatic email for confirming the hold request for a
           book on behalf of:

            %s (email: %s)

            title: %s
            author: %s
            location: %s
            library: %s
            publisher: %s
            year: %s
            isbn: %s

    """ % (borrower_infos[1], borrower_infos[2],
           title_link, book_author, more_holdings_infos[0][1],
           more_holdings_infos[0][2],
           book_editor, book_year, book_isbn)

    return out
Ejemplo n.º 3
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
Ejemplo 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 = 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
Ejemplo n.º 5
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