def generate_email_body(template, loan_id, ill=0): """ Generate the body of an email for loan recalls. @param template: email template @type template: string @param loan_id: identify the loan. Primary key of crcLOAN. @type loan_id: int @return email(body) """ if ill: # Inter library loan. out = template else: recid = db.get_loan_recid(loan_id) (book_title, book_year, book_author, book_isbn, book_editor) = book_information_from_MARC(int(recid)) due_date = db.get_due_date(loan_id) lib_id = db.get_library_for_loan(loan_id) library_details = db.get_library_details(lib_id) (library_id, name, address, email, phone, lib_type, notes) = library_details out = template % (book_title, book_year, book_author, book_isbn, book_editor, due_date, name, name, phone, email) return out
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) hodling_library = db.get_library_holding_barcode(barcode) (l_id, l_name, l_address, library_email, l_phone, l_type, l_notes) = db.get_library_details(hodling_library) 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, p_id) = 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[8] 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) if mail_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, l_name, l_phone, library_email) else: 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=library_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)) if mail_template == 'notification': message_for_librarian = message_template % ( name, ccid, email, address, mailbox, title, author, publisher, year, isbn, location, library, link_to_holdings_details, request_date, l_name, l_phone, library_email) else: message_for_librarian = message_template % ( name, ccid, email, address, mailbox, title, author, publisher, year, isbn, location, library, link_to_holdings_details, request_date) send_email(fromaddr=library_email, toaddr=library_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
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) hodling_library = db.get_library_holding_barcode(barcode) (l_id, l_name, l_address, library_email, l_phone, l_type, l_notes) = db.get_library_details(hodling_library) 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, p_id) = 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[8] 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) if mail_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, l_name, l_phone, library_email) else: 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 = library_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)) if mail_template == 'notification': message_for_librarian = message_template % (name, ccid, email, address, mailbox, title, author, publisher, year, isbn, location, library, link_to_holdings_details, request_date, l_name, l_phone, library_email) else: message_for_librarian = message_template % (name, ccid, email, address, mailbox, title, author, publisher, year, isbn, location, library, link_to_holdings_details, request_date) send_email(fromaddr = library_email, toaddr = library_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