Пример #1
0
def perform_book_proposal_send(uid, recid, period_from, period_to,
                                        remarks, ln=CFG_SITE_LANG):
    """
    The subfield containing the information about the source of importation
    of the record acts as the marker for the records put up for acquisition
    proposals.

    Register the user's book proposal, his period of interest and his remarks
    in the 'ILLREQUEST' table. Add a new 'dummy' copy for the proposed book.

    Create a loan(hold) request on behalf of the user for that copy and send
    a confirmation e-mail to her/him.
    """
    _ = gettext_set_language(ln)

    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 != ():
        if not db.has_copies(recid):
            tmp_barcode = generate_tmp_barcode()
            ill_register_request_with_recid(recid, uid, period_from, period_to, remarks,
                                            conditions='register_acquisition_suggestion',
                                            only_edition='False', barcode=tmp_barcode, ln=CFG_SITE_LANG)

            db.add_new_copy(tmp_barcode, recid, library_id=CFG_BIBCIRCULATION_DEFAULT_LIBRARY_ID,
                            collection='', location='',
                            description=_("This book was suggested for acquisition"), loan_period='',
                            status=CFG_BIBCIRCULATION_ITEM_STATUS_UNDER_REVIEW, expected_arrival_date='')

            db.delete_brief_format_cache(recid)

            return perform_new_request_send_message(uid, recid, period_from, period_to, tmp_barcode,
                                                    status=CFG_BIBCIRCULATION_REQUEST_STATUS_PROPOSED,
                                                    mail_subject='Acquisition Suggestion',
                                                    mail_template='proposal_notification',
                                                    mail_remarks=remarks, ln=CFG_SITE_LANG)
        return _("This item already has copies.")
    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
Пример #2
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
Пример #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 = 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
Пример #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