Exemple #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)
def tag_all_requests_as_done(barcode, user_id):
    recid = db.get_recid(barcode)
    list_of_barcodes = db.get_barcodes(recid)
    for bc in list_of_barcodes:
        db.tag_requests_as_done(bc, user_id)
Exemple #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
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)
Exemple #5
0
def task_run_core():
    """
    Run daemon
    """
    write_message("Starting...")
    if task_get_option("update-borrowers"):
        write_message("Started update-borrowers")
        list_of_borrowers = db.get_all_borrowers()
        total_borrowers = len(list_of_borrowers)

        for done, borrower in enumerate(list_of_borrowers):
            user_id = borrower[0]
            update_user_info_from_ldap(user_id)
            if done % 10 == 0:
                task_update_progress("Borrower: updated %d out of %d." %
                                     (done, total_borrowers))
                task_sleep_now_if_required(can_stop_too=True)
        task_update_progress("Borrower: updated %d out of %d." %
                             (done + 1, total_borrowers))
        write_message("Updated %d out of %d total borrowers" %
                      (done + 1, total_borrowers))

    if task_get_option("update-requests"):
        write_message("Started update-requests")
        list_of_reqs = db.get_loan_request_by_status(
            CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING)

        for (_request_id, recid, bc, _name, borrower_id, _library, _call_no,
             _location, _date_from, _date_to, _request_date) in list_of_reqs:
            description = db.get_item_description(bc)
            list_of_barcodes = db.get_barcodes(recid, description)
            for barcode in list_of_barcodes:
                update_requests_statuses(barcode)
                task_sleep_now_if_required(can_stop_too=True)
        task_update_progress(
            "Requests due updated from 'waiting' to 'pending'.")
        write_message("Requests due updated from 'waiting' to 'pending'.")

    if task_get_option("overdue-letters"):
        write_message("Started overdue-letters")
        expired_loans = db.get_all_expired_loans()
        total_expired_loans = len(expired_loans)

        for done, (borrower_id, _bor_name, recid, _barcode, _loaned_on,
                   _due_date, _number_of_renewals, number_of_letters,
                   date_letters, _notes, loan_id) in enumerate(expired_loans):

            number_of_letters = int(number_of_letters)

            content = ''
            if number_of_letters == 0:
                content = generate_email_body(
                    CFG_BIBCIRCULATION_TEMPLATES['RECALL1'], loan_id)
            elif number_of_letters == 1 and must_send_second_recall(
                    date_letters):
                content = generate_email_body(
                    CFG_BIBCIRCULATION_TEMPLATES['RECALL2'], loan_id)
            elif number_of_letters == 2 and must_send_third_recall(
                    date_letters):
                content = generate_email_body(
                    CFG_BIBCIRCULATION_TEMPLATES['RECALL3'], loan_id)
            elif number_of_letters >= 3 and must_send_third_recall(
                    date_letters):
                content = generate_email_body(
                    CFG_BIBCIRCULATION_TEMPLATES['RECALL3'], loan_id)

            if content != '':
                title = book_title_from_MARC(recid)
                subject = "LOAN RECALL: " + title

                update_expired_loan(loan_id)
                send_overdue_letter(borrower_id,
                                    CFG_BIBCIRCULATION_LOANS_EMAIL, subject,
                                    content)

            if done % 10 == 0:
                task_update_progress("Loan recall: sent %d out of %d." %
                                     (done, total_expired_loans))
                task_sleep_now_if_required(can_stop_too=True)
        task_update_progress(
            "Loan recall: processed %d out of %d expires loans." %
            (done + 1, total_expired_loans))
        write_message("Processed %d out of %d expired loans." %
                      (done + 1, total_expired_loans))

        # Recalls for expired ILLs
        write_message("Started overdue-letters for Inter Library Loans")
        expired_ills = db.get_all_expired_ills()
        total_expired_ills = len(expired_ills)

        for done, (ill_id, borrower_id, item_info, number_of_letters,
                   date_letters) in enumerate(expired_ills):

            number_of_letters = int(number_of_letters)

            content = ''
            if number_of_letters == 0:
                content = generate_email_body(
                    CFG_BIBCIRCULATION_TEMPLATES['ILL_RECALL1'], ill_id, ill=1)
            elif number_of_letters == 1 and must_send_second_recall(
                    date_letters):
                content = generate_email_body(
                    CFG_BIBCIRCULATION_TEMPLATES['ILL_RECALL2'], ill_id, ill=1)
            elif number_of_letters == 2 and must_send_third_recall(
                    date_letters):
                content = generate_email_body(
                    CFG_BIBCIRCULATION_TEMPLATES['ILL_RECALL3'], ill_id, ill=1)
            elif number_of_letters >= 3 and must_send_third_recall(
                    date_letters):
                content = generate_email_body(
                    CFG_BIBCIRCULATION_TEMPLATES['ILL_RECALL3'], ill_id, ill=1)

            if content != '' and looks_like_dictionary(item_info):
                item_info = eval(item_info)
                if item_info.has_key('title'):
                    book_title = item_info['title']
                    subject = "ILL RECALL: " + str(book_title)
                    update_expired_loan(loan_id=ill_id, ill=1)
                    send_overdue_letter(borrower_id,
                                        CFG_BIBCIRCULATION_ILLS_EMAIL, subject,
                                        content)
            if done % 10 == 0:
                task_update_progress("ILL recall: sent %d out of %d." %
                                     (done, total_expired_ills))
                task_sleep_now_if_required(can_stop_too=True)
        task_update_progress(
            "ILL recall: processed %d out of %d expired ills." %
            (done + 1, total_expired_ills))
        write_message("Processed %d out of %d expired ills." %
                      (done + 1, total_expired_ills))

    return 1
def task_run_core():
    """
    Run daemon
    """
    write_message("Starting...")
    if task_get_option("update-borrowers"):
        write_message("Started update-borrowers")
        list_of_borrowers = db.get_all_borrowers()
        total_borrowers = len(list_of_borrowers)

        for done, borrower in enumerate(list_of_borrowers):
            user_id = borrower[0]
            update_user_info_from_ldap(user_id)
            if done % 10 == 0:
                task_update_progress("Borrower: updated %d out of %d." % (done, total_borrowers))
                task_sleep_now_if_required(can_stop_too=True)
        task_update_progress("Borrower: updated %d out of %d." % (done+1, total_borrowers))
        write_message("Updated %d out of %d total borrowers" % (done+1, total_borrowers))

    if task_get_option("update-requests"):
        write_message("Started update-requests")
        list_of_reqs = db.get_loan_request_by_status(CFG_BIBCIRCULATION_REQUEST_STATUS_WAITING)

        for (_request_id, recid, bc, _name, borrower_id, _library, _call_no, _location,
             _date_from, _date_to, _request_date) in list_of_reqs:
            description = db.get_item_description(bc)
            list_of_barcodes = db.get_barcodes(recid, description)
            for barcode in list_of_barcodes:
                update_requests_statuses(barcode)
                task_sleep_now_if_required(can_stop_too=True)
        task_update_progress("Requests due updated from 'waiting' to 'pending'.")
        write_message("Requests due updated from 'waiting' to 'pending'.")

    if task_get_option("overdue-letters"):
        write_message("Started overdue-letters")
        expired_loans = db.get_all_expired_loans()
        total_expired_loans = len(expired_loans)

        for done, (borrower_id, _bor_name, recid, _barcode, _loaned_on,
             _due_date, _number_of_renewals, number_of_letters,
             date_letters, _notes, loan_id) in enumerate(expired_loans):

            number_of_letters=int(number_of_letters)

            content = ''
            if number_of_letters == 0:
                content = generate_email_body(CFG_BIBCIRCULATION_TEMPLATES['RECALL1'], loan_id)
            elif number_of_letters == 1 and must_send_second_recall(date_letters):
                content = generate_email_body(CFG_BIBCIRCULATION_TEMPLATES['RECALL2'], loan_id)
            elif number_of_letters == 2 and must_send_third_recall(date_letters):
                content = generate_email_body(CFG_BIBCIRCULATION_TEMPLATES['RECALL3'], loan_id)
            elif number_of_letters >= 3 and must_send_third_recall(date_letters):
                content = generate_email_body(CFG_BIBCIRCULATION_TEMPLATES['RECALL3'], loan_id)

            if content != '':
                title = book_title_from_MARC(recid)
                subject = "LOAN RECALL: " + title

                update_expired_loan(loan_id)
                send_overdue_letter(borrower_id, CFG_BIBCIRCULATION_LOANS_EMAIL, subject, content)

            if done % 10 == 0:
                task_update_progress("Loan recall: sent %d out of %d." % (done, total_expired_loans))
                task_sleep_now_if_required(can_stop_too=True)
        task_update_progress("Loan recall: processed %d out of %d expires loans." % (done+1, total_expired_loans))
        write_message("Processed %d out of %d expired loans." % (done+1, total_expired_loans))

        # Recalls for expired ILLs
        write_message("Started overdue-letters for Inter Library Loans")
        expired_ills = db.get_all_expired_ills()
        total_expired_ills = len(expired_ills)

        for done, (ill_id, borrower_id, item_info, number_of_letters,
             date_letters) in enumerate(expired_ills):

            number_of_letters=int(number_of_letters)

            content = ''
            if number_of_letters == 0:
                content = generate_email_body(CFG_BIBCIRCULATION_TEMPLATES['ILL_RECALL1'], ill_id, ill=1)
            elif number_of_letters == 1 and must_send_second_recall(date_letters):
                content = generate_email_body(CFG_BIBCIRCULATION_TEMPLATES['ILL_RECALL2'], ill_id, ill=1)
            elif number_of_letters == 2 and must_send_third_recall(date_letters):
                content = generate_email_body(CFG_BIBCIRCULATION_TEMPLATES['ILL_RECALL3'], ill_id, ill=1)
            elif number_of_letters >= 3 and must_send_third_recall(date_letters):
                content = generate_email_body(CFG_BIBCIRCULATION_TEMPLATES['ILL_RECALL3'], ill_id, ill=1)

            if content != '' and looks_like_dictionary(item_info):
                item_info = eval(item_info)
                if item_info.has_key('title'):
                    book_title = item_info['title']
                    subject = "ILL RECALL: " + str(book_title)
                    update_expired_loan(loan_id=ill_id, ill=1)
                    send_overdue_letter(borrower_id, CFG_BIBCIRCULATION_ILLS_EMAIL, subject, content)
            if done % 10 == 0:
                task_update_progress("ILL recall: sent %d out of %d." % (done, total_expired_ills))
                task_sleep_now_if_required(can_stop_too=True)
        task_update_progress("ILL recall: processed %d out of %d expired ills." % (done+1, total_expired_ills))
        write_message("Processed %d out of %d expired ills." % (done+1, total_expired_ills))

    return 1
Exemple #7
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)
Exemple #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 = 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
def tag_all_requests_as_done(barcode, user_id):
    recid = db.get_recid(barcode)
    list_of_barcodes = db.get_barcodes(recid)
    for bc in list_of_barcodes:
        db.tag_requests_as_done(bc, user_id)