diff --git a/modules/bibcirculation/lib/bibcirculation.py b/modules/bibcirculation/lib/bibcirculation.py
index dfaf97f25..ea72d4d03 100644
--- a/modules/bibcirculation/lib/bibcirculation.py
+++ b/modules/bibcirculation/lib/bibcirculation.py
@@ -1,695 +1,698 @@
# -*- coding: utf-8 -*-
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""BibCirculation .........."""
__revision__ = "$Id$"
# bibcirculation imports
import invenio.bibcirculation_dblayer as db
import invenio.template
bibcirculation_templates = invenio.template.load('bibcirculation')
# others invenio imports
from invenio.config import \
CFG_SITE_LANG, \
CFG_CERN_SITE, \
CFG_SITE_SUPPORT_EMAIL
from invenio.dateutils import get_datetext
import datetime
from invenio.webuser import collect_user_info
from invenio.mailutils import send_email
from invenio.bibcirculation_utils import hold_request_mail, \
book_title_from_MARC, \
- make_copy_available
+ make_copy_available, \
+ create_ill_record
from invenio.bibcirculation_cern_ldap import get_user_info_from_ldap
from invenio.bibcirculation_config import CFG_BIBCIRCULATION_LIBRARIAN_EMAIL
def perform_loanshistoricaloverview(uid, ln=CFG_SITE_LANG):
"""
Display Loans historical overview for user uid.
@param uid: user id
@param ln: language of the page
@return body(html)
"""
invenio_user_email = db.get_invenio_user_email(uid)
is_borrower = db.is_borrower(invenio_user_email)
result = db.get_historical_overview(is_borrower)
body = bibcirculation_templates.tmpl_loanshistoricaloverview(result=result,
ln=ln)
return body
def perform_borrower_loans(uid, barcode, borrower_id,
request_id, ln=CFG_SITE_LANG):
"""
Display all the loans and the requests of a given borrower.
@param barcode: identify the item. Primary key of crcITEM.
@type barcode: string
@param borrower_id: identify the borrower. Primary key of crcBORROWER.
@type borrower_id: int
@param request_id: identify the request: Primary key of crcLOANREQUEST
@type request_id: int
@return body(html)
"""
infos = []
is_borrower = db.is_borrower(db.get_invenio_user_email(uid))
loans = db.get_borrower_loans(is_borrower)
requests = db.get_borrower_requests(is_borrower)
tmp_date = datetime.date.today() + datetime.timedelta(days=30)
new_due_date = get_datetext(tmp_date.year, tmp_date.month, tmp_date.day)
#renew loan
if barcode:
recid = db.get_id_bibrec(barcode)
queue = db.get_queue_request(recid)
if len(queue) != 0:
infos.append("It is not possible to renew your loan for " \
"" + book_title_from_MARC(recid) + ". Another user " \
"is waiting for this book.")
else:
db.update_due_date(barcode, new_due_date)
infos.append("Your loan has been renewed with sucess.")
#cancel request
if request_id:
db.cancel_request(request_id, 'cancelled')
make_copy_available(request_id)
#renew all loans
elif borrower_id:
list_of_recids = db.get_borrower_recids(borrower_id)
for (recid) in list_of_recids:
queue = db.get_queue_request(recid[0])
#check if there are requests
if len(queue) != 0:
infos.append("It is not possible to renew your loan for " \
"" + book_title_from_MARC(recid) + ". Another user" \
" is waiting for this book.")
else:
db.update_due_date_borrower(borrower_id,
new_due_date)
infos.append("All loans have been renewed with success.")
body = bibcirculation_templates.tmpl_yourloans(loans=loans,
requests=requests,
borrower_id=is_borrower,
infos=infos,
ln=ln)
return body
def perform_get_holdings_information(recid, req, ln=CFG_SITE_LANG):
"""
Display all the copies of an item.
@param recid: identify the record. Primary key of bibrec.
@type recid: int
@return body(html)
"""
holdings_information = db.get_holdings_information(recid)
body = bibcirculation_templates.tmpl_holdings_information2(recid=recid,
req=req,
holdings_info=holdings_information,
ln=ln)
return body
def perform_get_pending_request(ln=CFG_SITE_LANG):
"""
@param ln: language of the page
"""
status = db.get_loan_request_by_status("pending")
body = bibcirculation_templates.tmpl_get_pending_request(status=status,
ln=ln)
return body
-def perform_new_request(uid, recid, barcode, ln=CFG_SITE_LANG):
+def perform_new_request(recid, barcode, ln=CFG_SITE_LANG):
"""
Display form to be filled by the user.
@param uid: user id
@type: int
@param recid: identify the record. Primary key of bibrec.
@type recid: int
@param barcode: identify the item. Primary key of crcITEM.
@type barcode: string
@return request form
"""
- body = bibcirculation_templates.tmpl_new_request2(uid=uid,
- recid=recid,
+ body = bibcirculation_templates.tmpl_new_request2(recid=recid,
barcode=barcode,
ln=ln)
return body
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:
- result = get_user_info_from_ldap(email=user['email'])
+ 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
-def ill_request_with_recid(recid, uid, ln=CFG_SITE_LANG):
+def ill_request_with_recid(recid, ln=CFG_SITE_LANG):
"""
Display ILL form.
@param recid: identify the record. Primary key of bibrec.
@type recid: int
@param uid: user id
@type: int
"""
body = bibcirculation_templates.tmpl_ill_request_with_recid(recid=recid, infos=[], ln=ln)
return body
def ill_register_request_with_recid(recid, uid, period_of_interest_from,
period_of_interest_to, additional_comments,
conditions, only_edition, ln=CFG_SITE_LANG):
"""
Register a new ILL request.
@param recid: identify the record. Primary key of bibrec.
@type recid: int
@param uid: user id
@type: int
@param period_of_interest_from: period of interest - from(date)
@type period_of_interest_from: string
@param period_of_interest_to: period of interest - to(date)
@type period_of_interest_to: string
"""
# create a dictionnary
book_info = {'recid': recid}
user = collect_user_info(uid)
is_borrower = db.is_borrower(user['email'])
#Check if borrower is on DB.
if is_borrower != 0:
address = db.get_borrower_address(user['email'])
#Check if borrower has an address.
if address != 0:
#Check if borrower has accepted ILL conditions.
if conditions:
#Register ILL request on crcILLREQUEST.
db.ill_register_request(book_info, is_borrower, period_of_interest_from,
period_of_interest_to, 'pending', additional_comments,
only_edition or 'False')
#Display confirmation message.
message = "Your ILL request has been registered and the " \
"document will be sent to you via internal mail."
#Notify librarian about new ILL request.
send_email(fromaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
toaddr=CFG_SITE_SUPPORT_EMAIL,
subject='ILL request for books confirmation',
content=hold_request_mail(recid, is_borrower),
attempt_times=1,
attempt_sleeptime=10
)
#Borrower did not accept ILL conditions.
else:
infos = []
infos.append("You didn't accept the ILL conditions.")
body = bibcirculation_templates.tmpl_ill_request_with_recid(recid, infos=infos, ln=ln)
#Borrower doesn't have an address.
else:
#If BibCirculation at CERN, use LDAP.
if CFG_CERN_SITE == 1:
- result = get_user_info_from_ldap(email=user['email'])
+ email=user['email']
+ result = get_user_info_from_ldap(email)
try:
ldap_address = result['physicalDeliveryOfficeName'][0]
except KeyError:
ldap_address = None
# verify address
if ldap_address is not None:
db.add_borrower_address(ldap_address, email)
db.ill_register_request(book_info, is_borrower, period_of_interest_from,
period_of_interest_to, additional_comments,
conditions, only_edition or 'False')
message = "Your ILL request has been registered and the document"\
" will be sent to you via internal mail."
send_email(fromaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
toaddr=CFG_SITE_SUPPORT_EMAIL,
subject='ILL request for books confirmation',
content=hold_request_mail(recid, is_borrower),
attempt_times=1,
attempt_sleeptime=10
)
else:
message = "It is not possible to validate your request. "\
"Your office address is not available. "\
"Please contact ... "
else:
# Get information from CERN LDAP
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
# verify address
if address is not None:
db.new_borrower(name, email, phone, address, mailbox, '')
is_borrower = db.is_borrower(email)
db.ill_register_request(book_info, is_borrower, period_of_interest_from,
period_of_interest_to, additional_comments,
conditions, only_edition or 'False')
message = "Your ILL request has been registered and the document"\
" will be sent to you via internal mail."
send_email(fromaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
toaddr=CFG_SITE_SUPPORT_EMAIL,
subject='ILL request for books confirmation',
content=hold_request_mail(recid, is_borrower),
attempt_times=1,
attempt_sleeptime=10
)
else:
message = "It is not possible to validate your request. "\
"Your office address is not available."\
" Please contact ... "
body = bibcirculation_templates.tmpl_ill_register_request_with_recid(message=message, ln=ln)
return body
-def display_ill_form(uid, ln=CFG_SITE_LANG):
+def display_ill_form(ln=CFG_SITE_LANG):
"""
Display ILL form
@param uid: user id
@type: int
"""
body = bibcirculation_templates.tmpl_display_ill_form(infos=[], ln=ln)
return body
def ill_register_request(uid, title, authors, place, publisher, year, edition,
isbn, period_of_interest_from, period_of_interest_to,
additional_comments, conditions, only_edition, ln=CFG_SITE_LANG):
"""
Register new ILL request. Create new record (collection: ILL Books)
@param uid: user id
@type: int
@param authors: book's authors
@type authors: string
@param place: place of publication
@type place: string
@param publisher: book's publisher
@type publisher: string
@param year: year of publication
@type year: string
@param edition: book's edition
@type edition: string
@param isbn: book's isbn
@type isbn: string
@param period_of_interest_from: period of interest - from(date)
@type period_of_interest_from: string
@param period_of_interest_to: period of interest - to(date)
@type period_of_interest_to: string
@param additional_comments: comments given by the user
@type additional_comments: string
@param conditions: ILL conditions
@type conditions: boolean
@param only_edition: borrower wants only the given edition
@type only_edition: boolean
"""
item_info = (title, authors, place, publisher, year, edition, isbn)
create_ill_record(item_info)
book_info = {'title': title, 'authors': authors, 'place': place, 'publisher': publisher,
'year': year, 'edition': edition, 'isbn': isbn}
user = collect_user_info(uid)
is_borrower = db.is_borrower(user['email'])
#Check if borrower is on DB.
if is_borrower != 0:
address = db.get_borrower_address(user['email'])
#Check if borrower has an address.
if address != 0:
#Check if borrower has accepted ILL conditions.
if conditions:
#Register ILL request on crcILLREQUEST.
db.ill_register_request(book_info, is_borrower, period_of_interest_from,
period_of_interest_to, 'pending', additional_comments,
only_edition or 'False')
#Display confirmation message.
message = "Your ILL request has been registered and the " \
"document will be sent to you via internal mail."
#Notify librarian about new ILL request.
send_email(fromaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
toaddr=CFG_SITE_SUPPORT_EMAIL,
subject='ILL request for books confirmation',
content="",
attempt_times=1,
attempt_sleeptime=10
)
#Borrower did not accept ILL conditions.
else:
infos = []
infos.append("You didn't accept the ILL conditions.")
body = bibcirculation_templates.tmpl_display_ill_form(infos=infos, ln=ln)
#Borrower doesn't have an address.
else:
#If BibCirculation at CERN, use LDAP.
if CFG_CERN_SITE == 1:
- result = get_user_info_from_ldap(email=user['email'])
+ email=user['email']
+ result = get_user_info_from_ldap(email)
try:
ldap_address = result['physicalDeliveryOfficeName'][0]
except KeyError:
ldap_address = None
# verify address
if ldap_address is not None:
db.add_borrower_address(ldap_address, email)
db.ill_register_request(book_info, is_borrower, period_of_interest_from,
period_of_interest_to, 'pending', additional_comments,
only_edition or 'False')
message = "Your ILL request has been registered and the document"\
" will be sent to you via internal mail."
send_email(fromaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
toaddr=CFG_SITE_SUPPORT_EMAIL,
subject='ILL request for books confirmation',
content="",
attempt_times=1,
attempt_sleeptime=10
)
else:
message = "It is not possible to validate your request. "\
"Your office address is not available. "\
"Please contact ... "
else:
# Get information from CERN LDAP
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
# verify address
if address is not None:
db.new_borrower(name, email, phone, address, mailbox, '')
is_borrower = db.is_borrower(email)
db.ill_register_request(book_info, is_borrower, period_of_interest_from,
period_of_interest_to, 'pending', additional_comments,
only_edition or 'False')
message = "Your ILL request has been registered and the document"\
" will be sent to you via internal mail."
send_email(fromaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
toaddr=CFG_SITE_SUPPORT_EMAIL,
subject='ILL request for books confirmation',
content="",
attempt_times=1,
attempt_sleeptime=10
)
else:
message = "It is not possible to validate your request. "\
"Your office address is not available."\
" Please contact ... "
body = bibcirculation_templates.tmpl_ill_register_request_with_recid(message=message, ln=ln)
return body
diff --git a/modules/bibcirculation/lib/bibcirculation_daemon.py b/modules/bibcirculation/lib/bibcirculation_daemon.py
index 1b07f9d51..b3b6ad161 100644
--- a/modules/bibcirculation/lib/bibcirculation_daemon.py
+++ b/modules/bibcirculation/lib/bibcirculation_daemon.py
@@ -1,192 +1,190 @@
# -*- coding: utf-8 -*-
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""
BibCirculation daemon.
"""
__revision__ = "$Id$"
import sys
import datetime
import time
from invenio.dbquery import run_sql
-from invenio.bibtask import task_init, write_message
+from invenio.bibtask import task_init
from invenio.mailutils import send_email
import invenio.bibcirculation_dblayer as db
from invenio.bibcirculation_config import CFG_BIBCIRCULATION_TEMPLATES, \
CFG_BIBCIRCULATION_LIBRARIAN_EMAIL
from invenio.search_engine import get_fieldvalues
from invenio.bibcirculation_utils import generate_email_body
def get_expired_loan():
"""
@return all expired loans
"""
res = run_sql("""select id_crcBORROWER, id, id_bibrec
from crcLOAN
where status = 'on loan' and due_date < NOW()
""")
return res
def update_expired_loan(loan_id):
"""
Update status, number of overdue letter and date of overdue letter
@param loan_id: identify the loan. Primary key of crcLOAN.
@type loan_id: int
"""
run_sql("""update crcLOAN
set overdue_letter_number = overdue_letter_number + 1,
status = 'expired',
overdue_letter_date = NOW()
where id = %s
""", (loan_id, ))
def get_overdue_letters_info(loan_id):
"""
Get the number of letters and the date of the last letter
sent for a given loan_id.
@param loan_id: identify the loan. Primary of crcLOAN.
@type loan_id: int
@return number_of_letters and date of the last letter
"""
res = run_sql("""select overdue_letter_number,
DATE_FORMAT(overdue_letter_date,'%%Y-%%m-%%d')
from crcLOAN
where id=%s""",
(loan_id, ))
return res[0]
def send_overdue_letter(borrower_id, subject, content):
"""
Send an overdue letter
@param borrower_id: identify the borrower. Primary key of crcBORROWER.
@type borrower_id: int
@param subject: subject of the overdue letter
@type subject: string
"""
to_borrower = db.get_borrower_email(borrower_id)
send_email(fromaddr=CFG_BIBCIRCULATION_LIBRARIAN_EMAIL,
toaddr=to_borrower,
subject=subject,
content=content,
header='',
footer='',
attempt_times=1,
attempt_sleeptime=10
)
return 1
def send_second_recall(date_letters):
"""
@param date_letters: date of the last letter.
@type date_letters: string
@return boolean
"""
today = datetime.date.today()
time_tuple = time.strptime(date_letters, "%Y-%m-%d")
#datetime.strptime(date_letters, "%Y-%m-%d") doesn't work (only on 2.5).
tmp_date = datetime.datetime(*time_tuple[0:3]) + datetime.timedelta(weeks=1)
if tmp_date.strftime("%Y-%m-%d") == today.strftime("%Y-%m-%d"):
return True
else:
return False
def send_third_recall(date_letters):
"""
@param date_letters: date of the last letter.
@type date_letters: string
@return boolean
"""
today = datetime.date.today()
time_tuple = time.strptime(date_letters, "%Y-%m-%d")
#datetime.strptime(date_letters, "%Y-%m-%d") doesn't work (only on 2.5).
tmp_date = datetime.datetime(*time_tuple[0:3]) + datetime.timedelta(days=3)
if tmp_date.strftime("%Y-%m-%d") == today.strftime("%Y-%m-%d"):
return True
else:
return False
def task_run_core():
"""
run daemon
"""
#write_message("Getting expired loans ...", verbose=9)
expired_loans = get_expired_loan()
for (borrower_id, loan_id, recid) in expired_loans:
(number_of_letters, date_letters) = get_overdue_letters_info(loan_id)
if number_of_letters == 0:
content = generate_email_body(CFG_BIBCIRCULATION_TEMPLATES['RECALL1'], loan_id)
elif number_of_letters == 1 and send_second_recall(date_letters):
content = generate_email_body(CFG_BIBCIRCULATION_TEMPLATES['RECALL2'], loan_id)
elif number_of_letters == 2 and send_third_recall(date_letters):
content = generate_email_body(CFG_BIBCIRCULATION_TEMPLATES['RECALL3'], loan_id)
else:
content = generate_email_body(CFG_BIBCIRCULATION_TEMPLATES['RECALL3'], loan_id)
title = ''.join(get_fieldvalues(recid, "245__a"))
subject = "LOAN RECALL: " + title
- update_expired_loan(id_loan)
+ update_expired_loan(loan_id)
#write_message("Updating information about expired loans")
send_overdue_letter(borrower_id, subject, content)
#write_message("Sending overdue letter")
#write_message("Done!!")
return 1
def main():
"""
main()
"""
task_init(authorization_action='runbibcirculation',
authorization_msg="BibCirculation Task Submission",
description="""Examples:
%s -u admin
""" % (sys.argv[0],),
version=__revision__,
task_run_fnc = task_run_core)
if __name__ == '__main__':
main()
-
-
diff --git a/modules/bibcirculation/lib/bibcirculation_dblayer.py b/modules/bibcirculation/lib/bibcirculation_dblayer.py
index 5eede9b82..48c4bfd60 100644
--- a/modules/bibcirculation/lib/bibcirculation_dblayer.py
+++ b/modules/bibcirculation/lib/bibcirculation_dblayer.py
@@ -1,2829 +1,2829 @@
# -*- coding: utf-8 -*-
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""Every db-related function of module bibcirculation"""
__revision__ = "$Id$"
from invenio.dbquery import run_sql
def verify_office_reference(uid):
"""
Verify is there a reference for user's office
@param uid: user ID
"""
query = """SELECT office
FROM crcborrower
WHERE id=%(user_id)i
"""
uid = int(uid)
res = run_sql(query%uid)
return res
def get_holdings_info(recid):
"""
Get information about holding, using recid.
@param recid: identify the record. Primary key of bibrec.
@type recid: int
@return holdings information
"""
res = run_sql("""
select count(lr.id_bibrec),
it.loan_period,
DATE_FORMAT(max(lr.period_of_interest_to),'%%Y-%%m-%%d'),
lib.name
from crcLOANREQUEST lr, crcITEM it, crcLIBRARY lib
where lib.id = it.id_crcLIBRARY and
lr.id_bibrec=it.id_bibrec and
it.id_bibrec=%s and
lr.status = 'waiting' GROUP BY (lr.id_bibrec)
""", (recid, ))
return res
def get_holdings_information(recid):
"""
Get information about holding, using recid.
@param recid: identify the record. Primary key of bibrec.
@type recid: int
@return holdings information
"""
res = run_sql("""select it.barcode,
lib.name,
it.collection,
it.location,
it.description,
it.loan_period,
it.status,
DATE_FORMAT(ln.due_date, '%%Y-%%m-%%d')
from crcITEM it
left join crcLOAN ln
on it.barcode = ln.barcode and ln.status != 'returned'
left join crcLIBRARY lib
on lib.id = it.id_crcLIBRARY
where it.id_bibrec=%s""",
(recid, ))
return res
def get_holdings_details(recid):
"""
Get details about holdings (loan period, location and library).
@param recid: identify the record. Primary key of bibrec.
@type recid: int
@return list with loan period, location and library.
"""
res = run_sql(""" select it.loan_period, lib.name, it.location
from crcITEM it, crcLIBRARY lib
where id_bibrec=%s limit 1""",
(recid, ))
return res
def get_loan_details(recid):
"""
Get details about a loan (barcode and status).
@param recid: identify the record. Primary key of bibrec.
@type recid: int
@return loan details
"""
res = run_sql("""select barcode, status
from crcITEM
where id_bibrec=%s and status = "available" limit 1;
""", (recid, ))
return res
def get_due_date_loan(recid):
"""
Get the due date of a loan.
@param recid: identify the record. Primary key of bibrec.
@type recid: int
@return due date
"""
res = run_sql("""select DATE_FORMAT(max(due_date),'%%Y-%%m-%%d')
from crcLOAN
where id_bibrec=%s and status != 'returned'
""", (recid, ))
if res:
return res[0][0]
else:
return None
def get_holdings_info_no_requests(recid):
"""
@param recid: identify the record. Primary key bibrec.
@type recid: int
"""
res = run_sql(""" select it.loan_period, lib.name
from crcITEM it, crcLIBRARY lib
where it.id_crcLIBRARY=lib.id and it.id_bibrec=%s
""", (recid, ))
return res
def get_request_recid(request_id):
"""
Get recid of a given request_id
@param request_id: identify the (hold) request. Primary key of crcLOANREQUEST.
@type request_id: int
@return recid
"""
res = run_sql(""" select id_bibrec
from crcLOANREQUEST
where id=%s
""", (request_id, ))
if res:
return res[0][0]
else:
return None
def get_request_borrower_id(request_id):
"""
Get borrower_id of a given request_id
@param request_id: identify the (hold) request. Primary key of crcLOANREQUEST.
@type request_id: int
@return borrower_id
"""
res = run_sql(""" select id_crcBORROWER
from crcLOANREQUEST
where id=%s
""", (request_id, ))
if res:
return res[0][0]
else:
return None
def get_request_barcode(request_id):
"""
Get the barcode associate to a request_id.
@param request_id: identify the (hold) request. Primary key of crcLOANREQUEST.
@type request_id: int
@return barcode
"""
res = run_sql(""" select barcode
from crcLOANREQUEST
where id=%s
""", (request_id, ))
if res:
return res[0][0]
else:
return None
def get_id_bibrec(barcode):
"""
Get the id bibrec (or recid).
@param barcode: identify the item. Primary key of crcITEM.
@type barcode: string
@return recid or None
"""
res = run_sql("""select id_bibrec
from crcITEM
where barcode=%s
""", (barcode, ))
if res:
return res[0][0]
else:
return None
def update_item_status(status, barcode):
"""
Update the status of an item (using the barcode).
@param status: status of the item.
@type status: string
@param barcode: identify the item. Primary key of crcITEM.
@type barcode: string
@return
"""
if status == 'on loan':
return int(run_sql("""UPDATE crcITEM
SET status=%s,
number_of_requests = number_of_requests + 1
WHERE barcode=%s""",
(status, barcode)))
else:
return int(run_sql("""UPDATE crcITEM
SET status=%s
WHERE barcode=%s""",
(status, barcode)))
def new_hold_request(borrower_id, recid, barcode, date_from, date_to, status):
"""
Create a new hold request.
@param borrower_id: identify the borrower. Primary key of crcBORROWER.
@type borrower_id: int
@param recid: identify the record. Primary key of bibrec.
@type recid: int
@param barcode: identify the item. Primary key of crcITEM.
@type barcode: string
@param date_from: begining of the period of interest.
@type date_from: string
@param date_to: end of the period of interest.
@type date_to: string
@param status: hold request status.
@type status: string
@return
"""
res = run_sql("""INSERT INTO crcLOANREQUEST(id_crcBORROWER,
id_bibrec,
barcode,
period_of_interest_from,
period_of_interest_to,
status,
request_date)
VALUES (%s, %s, %s, %s, %s, %s, NOW())
""", (borrower_id, recid, barcode,
date_from, date_to,
status))
return res
def get_barcode(recid):
"""
Get all the barcodes(copies) of a record(item).
@param recid: identify the record. Primary key of bibrec.
@type recid: int
@return list with barcode(s).
"""
res = run_sql("""select barcode
from crcITEM
where id_bibrec=%s
""", (recid, ))
if res:
return res[0][0]
else:
return None
def get_due_date(barcode):
"""
Get the due date of a given barcode.
@param barcode: identify the item. Primary key of crcITEM.
@type barcode: string
@return due_date
"""
res = run_sql("""select period_of_interest_to
from crcLOANREQUEST
where barcode=%s
""", (barcode, ))
if res:
return res[0][0]
else:
return None
def get_number_requests(recid):
"""
Get the number of requests of a record.
@param recid: identify the record. Primary key of bibrec.
@type recid: int
@return number of request (int)
"""
res = run_sql("""
select id_bibrec
from crcLOANREQUEST
where id_bibrec=%s and status != 'done' and status != 'cancelled';
""", (recid, ))
return res
def get_number_requests2(barcode, request_id):
"""
@param barcode: identify the item. Primary key of crcITEM.
@type barcode: string
@param request_id: identify the (hold) request. Primary key of crcLOANREQUEST.
@type request_id: int
"""
res = run_sql("""select id_bibrec
from crcLOANREQUEST
where id < %s and barcode=%s and status != 'done'
""", (request_id, barcode))
return res
def loan_return_confirm(borrower_id, recid):
"""
@param borrower_id: identify the borrower. Primary key of crcBORROWER.
@type borrower_id: int
@param recid: identify the record. Primary key of bibrec.
@type recid: int
"""
res = run_sql("""select bor.name, it.id_bibrec
from crcBORROWER bor, crcITEM it
where bor.id=%s and it.id_bibrec=%s
""", (borrower_id, recid))
return res
def get_borrower_id(barcode):
"""
Get the borrower id who is associate to a loan.
@param barcode: identify the item. Primary key of crcITEM.
@type barcode: string
@return borrower_id or None
"""
res = run_sql(""" select id_crcBORROWER
from crcLOAN
where barcode=%s and
(status='on loan' or status='expired')""",
(barcode, ))
try:
return res[0][0]
except IndexError:
return None
def get_borrower_email(borrower_id):
"""
Get the email of a borrower.
@param borrower_id: identify the borrower. Primary key of crcBORROWER.
@type borrower_id: int
@return borrower's email (string).
"""
res = run_sql("""select email
from crcBORROWER
where id=%s""", (borrower_id, ))
if res:
return res[0][0]
else:
return None
def get_next_waiting_loan_request(recid):
"""
Get the next waiting (loan) request for a given recid.
@param recid: identify the record. Primary key of bibrec.
@type recid: int
@return list with request_id, borrower_name, recid, status,
period_of_interest (from and to) and request_date.
"""
res = run_sql("""SELECT lr.id,
bor.name,
lr.id_bibrec,
lr.status,
DATE_FORMAT(lr.period_of_interest_from,'%%Y-%%m-%%d'),
DATE_FORMAT(lr.period_of_interest_to,'%%Y-%%m-%%d'),
lr.request_date
FROM crcLOANREQUEST lr,
crcBORROWER bor
WHERE lr.id_crcBORROWER=bor.id AND
(lr.status='waiting' OR lr.status='pending') AND lr.id_bibrec=%s
ORDER BY lr.request_date""",
(recid, ))
return res
def update_loan_info(returned_on, status, barcode):
"""
Update loan information when copy is returned.
@param returned_on: return date.
@type returned_on: string
@param status: new loan status.
@type status: string
@param barcode: identify the item. Primary key of crcITEM.
@type barcode: string
@return
"""
return int(run_sql("""update crcLOAN
set returned_on=%s, status=%s
where barcode=%s
""", (returned_on, status, barcode)))
def get_item_copies_details(recid):
"""
Get copies details of a given recid.
@param recid: identify the record. Primary key of bibrec.
@type recid: int
@return list with barcode, loan_period, library_name, library_id,
location, number_of_requests, status, collection,
description and due_date.
"""
res = run_sql("""select it.barcode, it.loan_period, lib.name,
lib.id, it.location, it.number_of_requests,
it.status, it.collection, it.description,
DATE_FORMAT(ln.due_date,'%%Y-%%m-%%d')
from crcITEM it
left join crcLOAN ln
on it.barcode = ln.barcode and ln.status != 'returned'
left join crcLIBRARY lib
on lib.id = it.id_crcLIBRARY
where it.id_bibrec=%s
order by it.creation_date
""", (recid, ))
return res
def get_number_copies(recid):
"""
Get the number of copies of a given recid.
@param recid: identify the record. Primary key of bibrec.
@type recid: int
@return number_of_copies
"""
res = run_sql("""select count(barcode)
from crcITEM
where id_bibrec=%s
""", (recid, ))
return res[0][0]
def bor_loans_historical_overview(borrower_id):
"""
Get loans historical overview of a given borrower_id.
@param borrower_id: identify the borrower. Primary key of crcBORROWER.
@type borrower_id: int
@return list with loans historical overview.
"""
res = run_sql("""
select l.id_bibrec,
l.barcode,
lib.name,
it.location,
DATE_FORMAT(l.loaned_on,'%%Y-%%m-%%d'),
DATE_FORMAT(l.due_date,'%%Y-%%m-%%d'),
l.returned_on,
l.number_of_renewals,
l.overdue_letter_number
from crcLOAN l, crcITEM it, crcLIBRARY lib
where l.id_crcBORROWER=%s and
lib.id = it.id_crcLIBRARY and
it.barcode = l.barcode and
l.status = 'returned' """,
(borrower_id, ))
return res
def bor_requests_historical_overview(borrower_id):
"""
Get requests historical overview of a given borrower_id.
@param borrower_id: identify the borrower. Primary key of crcBORROWER.
@type borrower_id: int
@return list with requests historical overview.
"""
res = run_sql("""select lr.id_bibrec,
lr.barcode,
lib.name,
it.location,
DATE_FORMAT(lr.period_of_interest_from,'%%Y-%%m-%%d'),
DATE_FORMAT(lr.period_of_interest_to,'%%Y-%%m-%%d'),
lr.request_date
from crcLOANREQUEST lr, crcITEM it, crcLIBRARY lib
where lr.id_crcBORROWER=%s and
lib.id = it.id_crcLIBRARY and
it.barcode = lr.barcode and
lr.status ='done' """
, (borrower_id, ))
return res
def get_item_loans_historical_overview(recid):
"""
@param recid: identify the record. Primary key of bibrec.
@type recid: int
"""
res = run_sql("""select bor.name,
bor.id,
l.barcode,
lib.name,
it.location,
DATE_FORMAT(l.loaned_on,'%%Y-%%m-%%d'),
DATE_FORMAT(l.due_date,'%%Y-%%m-%%d'),
l.returned_on,
l.number_of_renewals,
l.overdue_letter_number
from crcLOAN l, crcBORROWER bor, crcITEM it, crcLIBRARY lib
where l.id_crcBORROWER=bor.id and
lib.id = it.id_crcLIBRARY and
it.barcode = l.barcode and
l.id_bibrec = %s and
l.status = 'returned' """
, (recid, ))
return res
def get_item_requests_historical_overview(recid):
"""
recid: identify the record. It is also the primary key of
the table bibrec.
"""
res = run_sql("""
select bor.name,
bor.id,
lr.barcode,
lib.name,
it.location,
DATE_FORMAT(lr.period_of_interest_from,'%%Y-%%m-%%d'),
DATE_FORMAT(lr.period_of_interest_to,'%%Y-%%m-%%d'),
lr.request_date
from crcLOANREQUEST lr, crcBORROWER bor, crcITEM it, crcLIBRARY lib
where lr.id_crcBORROWER=bor.id and
lib.id = it.id_crcLIBRARY and
it.barcode = lr.barcode and
lr.id_bibrec = %s and
lr.status = 'done'
""", (recid, ))
return res
def get_library_details(library_id):
"""
library_id: identify the library. It is also the primary key of
the table crcLIBRARY.
"""
res = run_sql("""select id, name, address, email, phone, notes
from crcLIBRARY
where id=%s;
""", (library_id, ))
if res:
return res[0]
else:
return None
def get_loan_request_by_status(status):
"""
status: request status.
"""
res = run_sql("""SELECT DISTINCT
lr.id,
lr.id_bibrec,
bor.name,
bor.id,
lib.name,
it.location,
DATE_FORMAT(lr.period_of_interest_from,'%%Y-%%m-%%d'),
DATE_FORMAT(lr.period_of_interest_to,'%%Y-%%m-%%d'),
lr.request_date
FROM crcLOANREQUEST lr,
crcBORROWER bor,
crcITEM it,
crcLIBRARY lib
WHERE lr.id_crcBORROWER=bor.id AND it.barcode=lr.barcode AND
lib.id = it.id_crcLIBRARY AND lr.status=%s
ORDER BY lr.request_date;
""" ,
(status, ))
return res
def update_loan_request_status(request_id, status):
"""
request_id: identify the hold request. It is also the primary key
of the table crcLOANREQUEST.
status: new request status.
"""
return int(run_sql("""UPDATE crcLOANREQUEST
SET status=%s
WHERE id=%s""",
(status, request_id)))
def get_all_requests():
"""
Retrieve all requests.
"""
res = run_sql("""SELECT lr.id,
bor.id,
bor.name,
lr.id_bibrec,
lr.status,
DATE_FORMAT(lr.period_of_interest_from,'%Y-%m-%d'),
DATE_FORMAT(lr.period_of_interest_to,'%Y-%m-%d'),
lr.request_date
FROM crcLOANREQUEST lr,
crcBORROWER bor
WHERE bor.id = lr.id_crcBORROWER and (lr.status='waiting' or lr.status='pending')
ORDER BY lr.request_date
""")
return res
def get_item_requests(recid):
"""
recid: identify the record. It is also the primary key of
the table bibrec.
"""
res = run_sql("""SELECT bor.id,
bor.name,
lr.id_bibrec,
lr.status,
lib.name,
it.location,
DATE_FORMAT(lr.period_of_interest_from,'%%Y-%%m-%%d'),
DATE_FORMAT(lr.period_of_interest_to,'%%Y-%%m-%%d'),
lr.id,
lr.request_date
FROM crcLOANREQUEST lr,
crcBORROWER bor,
crcITEM it,
crcLIBRARY lib
WHERE bor.id = lr.id_crcBORROWER and lr.id_bibrec=%s
and lr.status!='done' and lr.status!='cancelled'
and lr.barcode = it.barcode and lib.id = it.id_crcLIBRARY
""", (recid, ))
return res
def get_all_requests_for_item_order_by_status(recid):
"""
recid: identify the record. It is also the primary key of
the table bibrec.
"""
res = run_sql("""SELECT bor.id,
bor.name,
lr.id_bibrec,
lr.status,
DATE_FORMAT(lr.period_of_interest_from,'%%Y-%%m-%%d'),
DATE_FORMAT(lr.period_of_interest_to,'%%Y-%%m-%%d')
FROM crcLOANREQUEST lr,
crcBORROWER bor
WHERE bor.id = lr.id_crcBORROWER and lr.id_bibrec=%s and lr.status!='done' ORDER BY status
""", (recid, ))
return res
def get_all_requests_for_item_order_by_name(recid):
"""
recid: identify the record. It is also the primary key of
the table bibrec.
"""
res = run_sql("""SELECT bor.id,
bor.name,
lr.id_bibrec,
lr.status,
DATE_FORMAT(lr.period_of_interest_from,'%%Y-%%m-%%d'),
DATE_FORMAT(lr.period_of_interest_to,'%%Y-%%m-%%d')
FROM crcLOANREQUEST lr,
crcBORROWER bor
WHERE bor.id = lr.id_crcBORROWER and lr.id_bibrec=%s and lr.status!='done' ORDER BY name
""", (recid, ))
return res
def get_all_requests_order_by_status():
"""
Get all requests order by status.
"""
res = run_sql("""SELECT bor.id,
bor.name,
lr.id_bibrec,
lr.status,
DATE_FORMAT(lr.period_of_interest_from,'%Y-%m-%d'),
DATE_FORMAT(lr.period_of_interest_to,'%Y-%m-%d')
FROM crcLOANREQUEST lr,
crcBORROWER bor
WHERE bor.id = lr.id_crcBORROWER and lr.status!='done' ORDER BY status
""")
return res
def get_all_requests_order_by_name():
"""
Get all requests order by name.
"""
res = run_sql("""SELECT bor.id,
bor.name,
lr.id_bibrec,
lr.status,
DATE_FORMAT(lr.period_of_interest_from,'%Y-%m-%d'),
DATE_FORMAT(lr.period_of_interest_to,'%Y-%m-%d')
FROM crcLOANREQUEST lr,
crcBORROWER bor
WHERE bor.id = lr.id_crcBORROWER and lr.status!='done' ORDER BY name
""")
return res
def get_all_requests_order_by_item():
"""
Get all requests order by item.
"""
res = run_sql("""SELECT bor.id,
bor.name,
lr.id_bibrec,
lr.status,
DATE_FORMAT(lr.period_of_interest_from,'%Y-%m-%d'),
DATE_FORMAT(lr.period_of_interest_to,'%Y-%m-%d')
FROM crcLOANREQUEST lr,
crcBORROWER bor
WHERE bor.id = lr.id_crcBORROWER and lr.status!='done' ORDER BY id_bibrec
""")
return res
def get_borrower_details(borrower_id):
"""
borrower_id: identify the borrower. It is also the primary key of
the table crcBORROWER.
"""
res = run_sql("""select id, name, email, phone, address, mailbox
from crcBORROWER
where id=%s""", (borrower_id, ))
if res:
return res[0]
else:
return None
def get_borrower_name(borrower_id):
"""
borrower_id: identify the borrower. It is also the primary key of
the table crcBORROWER.
"""
res = run_sql("""select name
from crcBORROWER
where id=%s""", (borrower_id, ))
if res:
return res[0][0]
else:
return None
def loan_on_desk_confirm(barcode, borrower_id):
"""
barcode: identify the item. It is the primary key of the table
crcITEM.
borrower_id: identify the borrower. It is also the primary key of
the table crcBORROWER.
"""
res = run_sql("""select it.id_bibrec, bor.name
from crcITEM it, crcBORROWER bor
where it.barcode=%s and bor.id=%s
""", (barcode, borrower_id))
return res
def search_borrower_by_name(string):
"""
string: search pattern.
"""
res = run_sql("""select id, name
from crcBORROWER
where name regexp %s order by name
""", (string, ))
return res
def search_borrower_by_email(string):
"""
string: search pattern.
"""
res = run_sql("""select id, name
from crcBORROWER
where email regexp %s
""", (string, ))
return res
def search_borrower_by_phone(string):
"""
string: search pattern.
"""
res = run_sql("""select id, name
from crcBORROWER
where phone regexp %s
""", (string, ))
return res
def search_borrower_by_id(string):
"""
string: search pattern.
"""
res = run_sql("""select id, name
from crcBORROWER
where id=%s
""", (string, ))
return res
def search_user_by_email(string):
"""
string: search pattern.
"""
res = run_sql("""
select id, email
from user
where email regexp %s
""", (string, ))
return res
def get_borrower_loan_details(borrower_id):
"""
borrower_id: identify the borrower. It is also the primary key of
the table crcBORROWER.
"""
res = run_sql("""
select it.id_bibrec,
l.barcode,
DATE_FORMAT(l.loaned_on,'%%Y-%%m-%%d'),
DATE_FORMAT(l.due_date,'%%Y-%%m-%%d'),
l.number_of_renewals,
l.overdue_letter_number,
DATE_FORMAT(l.overdue_letter_date,'%%Y-%%m-%%d'),
l.type,
l.notes,
l.id,
l.status
from crcLOAN l, crcITEM it
where l.barcode=it.barcode and id_crcBORROWER=%s and l.status!='returned'
""", (borrower_id, ))
return res
def get_borrower_request_details(borrower_id):
"""
borrower_id: identify the borrower. It is also the primary key of
the table crcBORROWER.
"""
res = run_sql("""SELECT lr.id_bibrec,
lr.status,
lib.name,
it.location,
DATE_FORMAT(lr.period_of_interest_from,'%%Y-%%m-%%d'),
DATE_FORMAT(lr.period_of_interest_to,'%%Y-%%m-%%d'),
lr.request_date,
lr.id
FROM crcLOANREQUEST lr,
crcITEM it,
crcLIBRARY lib
WHERE lr.id_crcBORROWER =%s and (lr.status='waiting' or lr.status='pending')
and lib.id = it.id_crcLIBRARY and lr.barcode = it.barcode
""", (borrower_id, ))
return res
def get_borrower_request_details_order_by_item(borrower_id):
"""
borrower_id: identify the borrower. It is also the primary key of
the table crcBORROWER.
"""
res = run_sql("""SELECT lr.id_crcBORROWER,
lr.id_bibrec,
lr.status,
DATE_FORMAT(lr.period_of_interest_from,'%%Y-%%m-%%d'),
DATE_FORMAT(lr.period_of_interest_to,'%%Y-%%m-%%d')
FROM crcLOANREQUEST lr
WHERE lr.id_crcBORROWER =%s and lr.status!='done' ORDER BY id_bibrec
""", (borrower_id, ))
return res
def get_borrower_request_details_order_by_status(borrower_id):
"""
borrower_id: identify the borrower. It is also the primary key of
the table crcBORROWER.
"""
res = run_sql("""SELECT lr.id_crcBORROWER,
lr.id_bibrec,
lr.status,
DATE_FORMAT(lr.period_of_interest_from,'%%Y-%%m-%%d'),
DATE_FORMAT(lr.period_of_interest_to,'%%Y-%%m-%%d')
FROM crcLOANREQUEST lr
WHERE lr.id_crcBORROWER =%s and lr.status!='done' ORDER BY status
""", (borrower_id, ))
return res
def get_borrower_request_details_order_by_from(borrower_id):
"""
borrower_id: identify the borrower. It is also the primary key of
the table crcBORROWER.
"""
res = run_sql("""SELECT lr.id_crcBORROWER,
lr.id_bibrec,
lr.status,
DATE_FORMAT(lr.period_of_interest_from,'%%Y-%%m-%%d'),
DATE_FORMAT(lr.period_of_interest_to,'%%Y-%%m-%%d')
FROM crcLOANREQUEST lr
WHERE lr.id_crcBORROWER =%s and lr.status!='done' ORDER BY period_of_interest_from
""", (borrower_id, ))
return res
def get_borrower_request_details_order_by_to(borrower_id):
"""
borrower_id: identify the borrower. It is also the primary key of
the table crcBORROWER.
"""
res = run_sql("""SELECT lr.id_crcBORROWER,
lr.id_bibrec,
lr.status,
DATE_FORMAT(lr.period_of_interest_from,'%%Y-%%m-%%d'),
DATE_FORMAT(lr.period_of_interest_to,'%%Y-%%m-%%d')
FROM crcLOANREQUEST lr
WHERE lr.id_crcBORROWER =%s and lr.status!='done' ORDER BY period_of_interest_to
""", (borrower_id, ))
return res
def new_loan(borrower_id, recid, barcode,
loaned_on, due_date, status, loan_type, notes):
"""
Create a new loan.
borrower_id: identify the borrower. It is also the primary key of
the table crcBORROWER.
recid: identify the record. It is also the primary key of
the table bibrec.
barcode: identify the item. It is the primary key of the table
crcITEM.
loaned_on: loan date.
due_date: due date.
status: loan status.
loan_type: loan type(normal, ILL, etc...)
notes: loan notes.
"""
res = run_sql(""" insert into crcLOAN (id_crcBORROWER, id_bibrec,
barcode, loaned_on, due_date,
status, type, notes)
values(%s, %s, %s, %s, %s, %s ,%s, %s)
""", (borrower_id, recid, barcode, loaned_on,
due_date, status, loan_type, str(notes)))
return res
def get_item_loans(recid):
"""
recid: identify the record. It is also the primary key of
the table bibrec.
"""
res = run_sql(
"""
select bor.id,
bor.name,
l.barcode,
DATE_FORMAT(l.loaned_on,'%%Y-%%m-%%d'),
DATE_FORMAT(l.due_date,'%%Y-%%m-%%d'),
l.number_of_renewals,
l.overdue_letter_number,
DATE_FORMAT(l.overdue_letter_date,'%%Y-%%m-%%d'),
l.status,
l.notes,
l.id
from crcLOAN l, crcBORROWER bor, crcITEM it
where l.id_crcBORROWER = bor.id
and l.barcode=it.barcode
and l.id_bibrec=%s
and l.status!='returned'
""", (recid, ))
return res
def get_all_loans(limit):
"""
Get all loans.
"""
res = run_sql(
"""
SELECT bor.id,
bor.name,
it.id_bibrec,
l.barcode,
DATE_FORMAT(l.loaned_on,'%%Y-%%m-%%d'),
DATE_FORMAT(l.due_date,'%%Y-%%m-%%d'),
l.number_of_renewals,
l.overdue_letter_number,
DATE_FORMAT(l.overdue_letter_date,'%%Y-%%m-%%d'),
l.notes,
l.id
FROM crcLOAN l, crcBORROWER bor, crcITEM it
WHERE l.id_crcBORROWER = bor.id
and l.barcode = it.barcode
and l.status = 'on loan'
ORDER BY 5 DESC
LIMIT 0,%s
""", (limit,))
return res
def get_all_expired_loans():
"""
Get all expired(overdue) loans.
"""
res = run_sql(
"""
select bor.id,
bor.name,
it.id_bibrec,
l.barcode,
DATE_FORMAT(l.loaned_on,'%Y-%m-%d'),
DATE_FORMAT(l.due_date,'%Y-%m-%d'),
l.number_of_renewals,
l.overdue_letter_number,
DATE_FORMAT(l.overdue_letter_date,'%Y-%m-%d'),
l.notes,
l.id
from crcLOAN l, crcBORROWER bor, crcITEM it
where l.id_crcBORROWER = bor.id
and l.barcode = it.barcode
and l.status = 'on loan'
and l.due_date < CURDATE()
""")
# l.status='expired'
return res
def get_borrower_loans(borrower_id):
"""
borrower_id: identify the borrower. It is also the primary key of
the table crcBORROWER.
"""
res = run_sql(""" select id_bibrec,
barcode,
DATE_FORMAT(loaned_on,'%%Y-%%m-%%d'),
DATE_FORMAT(due_date,'%%Y-%%m-%%d'),
type
from crcLOAN
where id_crcBORROWER=%s and status != 'returned'
""", (borrower_id, ))
return res
def update_due_date(loan_id, new_due_date):
"""
loan_id: identify a loan. It is the primery key of the table
crcLOAN.
new_due_date: new due date.
"""
return int(run_sql("""UPDATE crcLOAN
SET due_date=%s,
number_of_renewals = number_of_renewals + 1
WHERE id=%s""",
(new_due_date, loan_id)))
def update_due_date_borrower(borrower_id, new_due_date):
"""
borrower_id: identify the borrower. It is also the primary key of
the table crcBORROWER.
new_due_date: new due date.
"""
return int(run_sql("""UPDATE crcLOAN
SET due_date=%s
WHERE id_crcBORROWER=%s and status='on loan'
""", (new_due_date, borrower_id)))
def get_queue_request(recid):
"""
recid: identify the record. It is also the primary key of
the table bibrec.
"""
res = run_sql(""" select id
from crcLOANREQUEST
where id_bibrec=%s and (status='pending' or status='waiting')
""", (recid, ))
return res
def get_recid_borrower_loans(borrower_id):
"""
borrower_id: identify the borrower. It is also the primary key of
the table crcBORROWER.
"""
res = run_sql(""" select id, id_bibrec, barcode
from crcLOAN
where id_crcBORROWER=%s and
status != 'returned'and
type != 'ill'
""", (borrower_id, ))
return res
def update_request_barcode(barcode, request_id):
"""
Update the barcode of an hold request.
barcode: new barcode (after update). It is also the
primary key of the crcITEM table.
request_id: identify the hold request who will be
cancelled. It is also the primary key of
the crcLOANREQUEST table.
"""
run_sql("""update crcLOANREQUEST
set barcode = %s
where id = %s
""", (barcode, request_id))
def get_historical_overview(borrower_id):
"""
Get historical information overview (recid, loan date, return date
and number of renewals).
borrower_id: identify the borrower. All the old (returned) loans
associate to this borrower will be retrieved.
It is also the primary key of the crcBORROWER table.
"""
res = run_sql("""select id_bibrec,
DATE_FORMAT(loaned_on,'%%Y-%%m-%%d'),
returned_on,
number_of_renewals
from crcLOAN
where id_crcBORROWER = %s and status = "returned";
""", (borrower_id, ))
return res
def get_borrower_requests(borrower_id):
"""
Get the hold requests of a borrower.
borrower_id: identify the borrower. All the hold requests
associate to this borrower will be retrieved.
It is also the primary key of the crcBORROWER table.
"""
res = run_sql("""
select id,
id_bibrec,
DATE_FORMAT(request_date,'%%Y-%%m-%%d'),
status
from crcLOANREQUEST
where id_crcBORROWER=%s and
(status='pending' or status='waiting')""",
(borrower_id, ))
return res
def cancel_request(request_id, status):
"""
Cancel an hold request.
request_id: identify the hold request who will be
cancelled. It is also the primary key of
the crcLOANREQUEST table.
status: The new status of the hold request. In this case
it will be 'cancelled'.
"""
run_sql("""update crcLOANREQUEST set status=%s
where id=%s
""", (status, request_id))
def get_nb_copies_on_loan(recid):
"""
Get the number of copies on loan for a recid.
recid: CDS Invenio record identifier. The number of copies
of this record will be retrieved.
"""
res = run_sql("""select id_bibrec
from crcLOAN
where id_bibrec=%s and status='on loan';
""", (recid, ))
return res
def get_loans_notes(loan_id):
"""
Get loan's notes.
loan_id: identify the loan. The notes of
this loan will be retrieved. It is
also the primary key of the table
crcLOAN.
"""
res = run_sql("""select notes
from crcLOAN
where id=%s
""", (loan_id, ))
if res:
return res[0][0]
else:
return None
def add_new_note(new_note, borrower_id):
"""
Add a new borrower's note.
new_note: note who will be added.
borrower_id: identify the borrower. A new note will be
associate to this borrower. It is also
the primary key of the crcBORROWER table.
"""
run_sql("""update crcBORROWER
set notes=concat(notes,%s)
where id=%s;
""", (new_note, borrower_id))
def add_new_loan_note(new_note, loan_id):
"""
Add a new loan's note.
new_note: note who will be added.
loan_id: identify the loan. A new note will
added to this loan. It is also the
primary key of the table crcLOAN.
"""
run_sql("""update crcLOAN
set notes=concat(notes,%s)
where id=%s;
""", (new_note, loan_id))
def is_borrower(email):
"""
Verify if someone is a borrower, using the email.
email: borrower's email.
"""
res = run_sql("""select id
from crcBORROWER
where email=%s""",
(email, ))
if res:
return res[0][0]
else:
return 0
def new_borrower(name, email, phone, address, mailbox, notes):
"""
Add/Register a new borrower on the crcBORROWER table.
name: borrower's name.
email: borrower's email.
phone: borrower's phone.
address: borrower's address.
"""
run_sql("""insert into crcBORROWER (name,
email,
phone,
address,
mailbox,
borrower_since,
borrower_until,
notes)
values(%s, %s, %s, %s, %s, NOW(), '0000-00-00 00:00:00', %s)""",
(name, email, phone, address, mailbox, notes))
def get_borrower_address(email):
"""
Get the address of a borrower using the email.
email: borrower's email.
"""
res = run_sql("""select address
from crcBORROWER
where email=%s""", (email, ))
if len(res[0][0]) > 0:
return res[0][0]
else:
return 0
def add_borrower_address(address, email):
"""
Add the email and the address of a borrower.
address: borrower's address.
email: borrower's email.
"""
run_sql("""update crcBORROWER
set address=%s
where email=%s""", (address, email))
def get_invenio_user_email(uid):
"""
Get the email of an invenio's user.
uid: identify an invenio's user.
"""
res = run_sql("""select email
from user
where id=%s""",
(uid, ))
if res:
return res[0][0]
else:
return None
def get_borrower_notes(borrower_id):
"""
Get the notes of a borrower.
borrower_id: identify the borrower. The data associate
to this borrower will be retrieved. It is also
the primary key of the crcBORROWER table.
"""
res = run_sql("""select notes
from crcBORROWER
where id=%s""",
(borrower_id, ))
if res:
return res[0][0]
else:
return None
def update_loan_status(status, loan_id):
"""
Update the status of a loan.
status: new status (after update)
loan_id: identify the loan who will be updated.
It is also the primary key of the table
crcLOAN.
"""
run_sql("""update crcLOAN
set status = %s
where id = %s""",
(status, loan_id))
def get_loan_due_date(loan_id):
"""
Get the due date of a loan.
loan_id: identify the loan. The due date of
this loan will be retrieved. It is
also the primary key of the table
crcLOAN.
"""
res = run_sql("""select DATE_FORMAT(due_date, '%%Y-%%m-%%d')
from crcLOAN
where id = %s""",
(loan_id, ))
if res:
return res[0][0]
else:
return None
def get_pdf_request_data(status):
"""
status: request status.
"""
res = run_sql("""SELECT DISTINCT
lr.id_bibrec,
bor.name,
lib.name,
it.location,
DATE_FORMAT(lr.period_of_interest_from,'%%Y-%%m-%%d'),
DATE_FORMAT(lr.period_of_interest_to,'%%Y-%%m-%%d'),
lr.request_date
FROM crcLOANREQUEST lr,
crcBORROWER bor,
crcITEM it,
crcLIBRARY lib
WHERE lr.id_crcBORROWER=bor.id AND
it.id_bibrec=lr.id_bibrec AND
lib.id = it.id_crcLIBRARY AND
lr.status=%s;
""" ,
(status, ))
return res
def get_last_loan():
"""
Get the recid, the borrower_id and the due date of
the last loan who was registered on the crcLOAN table.
"""
res = run_sql("""select id_bibrec,
id_crcBORROWER,
DATE_FORMAT(due_date, '%Y-%m-%d')
from crcLOAN ORDER BY id DESC LIMIT 1""")
if res:
return res[0]
else:
return None
def get_borrower_data(borrower_id):
"""
Get the borrower's information (name, address and email).
borrower_id: identify the borrower. The data associate
to this borrower will be retrieved. It is also
the primary key of the crcBORROWER table.
"""
res = run_sql("""select name,
address,
mailbox,
email
from crcBORROWER
where id=%s""",
(borrower_id, ))
if res:
return res[0]
else:
return None
def update_borrower_info(borrower_id, name, email, phone, address, mailbox):
"""
Update borrower info.
borrower_id: identify the borrower. It is also the primary key of
the table crcBORROWER.
"""
return int(run_sql("""update crcBORROWER
set name=%s,
email=%s,
phone=%s,
address=%s,
mailbox=%s
where id=%s""",
(name, email, phone, address, mailbox, borrower_id)))
-def add_new_library(name, email, phone, address, type, notes):
+def add_new_library(name, email, phone, address, lib_type, notes):
"""
Add a new Library.
"""
run_sql("""insert into crcLIBRARY (name, email, phone,
address, type, notes)
values (%s, %s, %s, %s, %s, %s)""",
- (name, email, phone, address, type, notes))
+ (name, email, phone, address, lib_type, notes))
def search_library_by_name(string):
"""
string: search pattern.
"""
res = run_sql("""select id, name
from crcLIBRARY
where name regexp %s
""", (string, ))
return res
def search_library_by_email(string):
"""
string: search pattern.
"""
res = run_sql("""select id, name
from crcLIBRARY
where email regexp %s
""", (string, ))
return res
def get_all_libraries():
"""
"""
res = run_sql("""select id, name
from crcLIBRARY""")
return res
def update_library_info(library_id, name, email, phone, address):
"""
Update library information.
library_id: identify the library. It is also the primary key of
the table crcLIBRARY.
"""
return int(run_sql("""update crcLIBRARY
set name=%s,
email=%s,
phone=%s,
address=%s
where id=%s""",
(name, email, phone, address, library_id)))
def get_libraries():
"""
Get Libraries
"""
res = run_sql("""select id, name
from crcLIBRARY""")
#where type<>'external' """)
return res
def get_library_name(library_id):
"""
Get Library's name.
library_id: identify the library. It is also the primary key of
the table crcLIBRARY.
"""
res = run_sql("""select name
from crcLIBRARY
where id=%s""",
(library_id, ))
if res:
return res[0][0]
else:
return None
def add_new_copy(barcode, recid, library_id, collection, location, description,
loan_period, status):
"""
Add a new copy
barcode: identify the item. It is the primary key of the table
crcITEM.
recid: identify the record. It is also the primary key of
the table bibrec.
library_id: identify the library. It is also the primary key of
the table crcLIBRARY.
"""
run_sql("""insert into crcITEM (barcode, id_bibrec, id_crcLIBRARY,
collection, location, description, loan_period,
status, creation_date, modification_date)
values (%s, %s, %s, %s, %s, %s, %s, %s, NOW(), NOW())""",
(barcode, recid, library_id, collection, location, description,
loan_period, status))
def get_item_info(barcode):
"""
Get item's information.
barcode: identify the item. It is the primary key of the table
crcITEM.
"""
res = run_sql("""select it.barcode,
it.id_crcLIBRARY,
lib.name,
it.collection,
it.location,
it.description,
it.loan_period,
it.status
from crcITEM it,
crcLIBRARY lib
where it.barcode=%s and it.id_crcLIBRARY = lib.id""",
(barcode, ))
if res:
return res[0]
else:
return None
def update_item_info(barcode, library_id, collection, location, description,
loan_period, status):
"""
Update item's information.
barcode: identify the item. It is the primary key of the table
crcITEM.
library_id: identify the library. It is also the primary key of
the table crcLIBRARY.
"""
int(run_sql("""update crcITEM
set barcode=%s,
id_crcLIBRARY=%s,
collection=%s,
location=%s,
description=%s,
loan_period=%s,
status=%s,
modification_date=NOW()
where barcode=%s""",
(barcode, library_id, collection, location, description,
loan_period, status, barcode)))
def get_library_items(library_id):
"""
Get all items who belong to a library.
library_id: identify the library. It is also the primary key of
the table crcLIBRARY.
"""
res = run_sql("""select barcode, id_bibrec, collection,
location, description, loan_period, status, number_of_requests
from crcITEM
where id_crcLIBRARY=%s""",
(library_id, ))
return res
def get_library_notes(library_id):
"""
Get the notes of a library.
library_id: identify the library. The data associate
to this library will be retrieved. It is also
the primary key of the crcLIBRARY table.
"""
res = run_sql("""select notes
from crcLIBRARY
where id=%s""",
(library_id, ))
if res:
return res[0][0]
else:
return None
def add_new_library_note(new_note, library_id):
"""
Add a new borrower's note.
new_note: note who will be added.
library_id: identify the borrower. A new note will be
associate to this borrower. It is also
the primary key of the crcBORROWER table.
"""
run_sql("""update crcLIBRARY
set notes=concat(notes,%s)
where id=%s;
""", (new_note, library_id))
def get_borrower_data_by_name(name):
"""
Retrieve borrower's data by name.
"""
res = run_sql("""select id, name, email, phone,
address, mailbox
from crcBORROWER
where name regexp %s order by name""",
(name, ))
return res
def get_borrower_data_by_email(email):
"""
Retrieve borrower's data by email.
"""
res = run_sql("""select id, name, email, phone,
address, mailbox
from crcBORROWER
where email regexp %s""",
(email, ))
return res
def get_borrower_data_by_id(borrower_id):
"""
Retrieve borrower's data by borrower_id.
"""
res = run_sql("""select id, name, email, phone,
address, mailbox
from crcBORROWER
where id regexp %s""",
(borrower_id, ))
return res
def get_number_requests_per_copy(barcode):
"""
barcode: identify the item. It is the primary key of the table
crcITEM.
"""
res = run_sql("""select count(barcode)
from crcLOANREQUEST
where barcode=%s and
(status != 'done' and status != 'cancelled')""",
(barcode, ))
return res[0][0]
def get_requested_barcode(request_id):
"""
request_id: identify the hold request. It is also the primary key
of the table crcLOANREQUEST.
"""
res = run_sql("""select barcode
from crcLOANREQUEST
where id=%s""",
(request_id, ))
if res:
return res[0][0]
else:
return None
def get_borrower_recids(borrower_id):
"""
borrower_id: identify the borrower. It is also the primary key of
the table crcBORROWER.
"""
res = run_sql("""select id_bibrec
from crcLOAN
where id_crcBORROWER=%s""",
(borrower_id,))
return res
def get_loan_status(loan_id):
"""
Get loan's status
loan_id: identify a loan. It is the primery key of the table
crcLOAN.
"""
res = run_sql("""select status
from crcLOAN
where id=%s""",
(loan_id, ))
if res:
return res[0][0]
else:
return None
def get_loan_period(barcode):
"""
Retrieve the loan period of a book.
barcode: identify the item. It is the primary key of the table
crcITEM.
"""
res = run_sql("""select loan_period
from crcITEM
where barcode=%s""",
(barcode, ))
if res:
return res[0][0]
else:
return None
def get_loan_infos(loan_id):
"""
loan_id: identify a loan. It is the primery key of the table
crcLOAN.
"""
res = run_sql("""select l.id_bibrec,
l.barcode,
DATE_FORMAT(l.loaned_on, '%%Y-%%m-%%d'),
DATE_FORMAT(l.due_date, '%%Y-%%m-%%d'),
l.status,
it.loan_period,
it.status
from crcLOAN l, crcITEM it, crcLOANREQUEST lr
where l.barcode=it.barcode and
l.id=%s""",
(loan_id, ))
if res:
return res[0]
else:
return None
def is_item_on_loan(barcode):
"""
Check if an item is on loan.
barcode: identify the item. It is the primary key of the table
crcITEM.
"""
res = run_sql("""select id
from crcLOAN
where (status='on loan' or status='expired')
and barcode=%s""",
(barcode, ))
try:
return res[0][0]
except IndexError:
return None
def order_new_copy(recid, vendor_id, order_date, cost,
status, notes, expected_date):
"""
Register a new copy who has been ordered.
"""
run_sql("""insert into crcPURCHASE(id_bibrec, id_crcVENDOR, ordered_date, price,
status, notes, expected_date)
values (%s, %s, %s, %s, %s, %s, %s)""",
(recid, vendor_id, order_date, cost,
status, notes, expected_date))
def get_ordered_books():
"""
Get the list with all the ordered books.
"""
res = run_sql("""select id, id_bibrec, id_crcVENDOR,
DATE_FORMAT(ordered_date,'%Y-%m-%d'),
DATE_FORMAT(expected_date, '%Y-%m-%d'),
price, status, notes
from crcPURCHASE""")
return res
def get_purchase_notes(purchase_id):
"""
Get the notes of a purchase.
library_id: identify the purchase. The data associate
to this library will be retrieved. It is also
the primary key of the crcPURCHASE table.
"""
res = run_sql("""select notes
from crcPURCHASE
where id=%s""",
(purchase_id, ))
if res:
return res[0][0]
else:
return None
def update_purchase_notes(purchase_id, purchase_notes):
"""
"""
run_sql("""update crcPURCHASE
set notes=%s
where id=%s """, (str(purchase_notes), purchase_id))
def add_new_purchase_note(new_note, purchase_id):
"""
Add a new purchase's note.
new_note: note who will be added.
library_id: identify the purchase. A new note will be
associate to this purchase. It is also
the primary key of the crcPURCHASE table.
"""
run_sql("""update crcPURCHASE
set notes=concat(notes,%s)
where id=%s;
""", (new_note, purchase_id))
def ill_register_request(book_info, borrower_id, period_of_interest_from,
period_of_interest_to, status, additional_comments,
only_edition):
"""
"""
run_sql("""insert into crcILLREQUEST(id_crcBORROWER, period_of_interest_from,
period_of_interest_to, status, book_info,
borrower_comments, only_this_edition)
values (%s, %s, %s, %s, %s, %s, %s)""",
(borrower_id, period_of_interest_from, period_of_interest_to,
status, str(book_info), additional_comments, only_edition))
def ill_register_request_on_desk(borrower_id, book_info, period_of_interest_from,
period_of_interest_to, status, notes,
only_edition):
"""
"""
run_sql("""insert into crcILLREQUEST(id_crcBORROWER, period_of_interest_from,
period_of_interest_to, status, book_info,
only_this_edition, library_notes)
values (%s, %s, %s, %s, %s, %s, %s)""",
(borrower_id, period_of_interest_from, period_of_interest_to, status,
str(book_info), only_edition, notes))
def get_ill_requests():
"""
"""
query = """select ill.id, ill.id_crcBORROWER, bor.name,
ill.id_crcLIBRARY, ill.status,
DATE_FORMAT(ill.period_of_interest_from,'%Y-%m-%d'),
DATE_FORMAT(ill.period_of_interest_to,'%Y-%m-%d'),
ill.book_info
from crcILLREQUEST ill, crcBORROWER bor
where ill.id_crcBORROWER=bor.id order by ill.id desc"""
res = run_sql(query)
return res
def get_ill_request_pending(ill_request_id):
"""
"""
res = run_sql("""select library_notes
from crcILLREQUEST
where id=%s""", (ill_request_id, ))
if res:
return res[0][0]
else:
return None
def get_ill_request_sent(ill_request_id):
"""
"""
res = run_sql("""select id_crcLIBRARY,
DATE_FORMAT(request_date,'%%Y-%%m-%%d'),
DATE_FORMAT(expected_date,'%%Y-%%m-%%d'),
cost,
barcode,
library_notes
from crcILLREQUEST
where id=%s""", (ill_request_id, ))
if res:
return res[0]
else:
return None
def get_ill_request_cancelled(ill_request_id):
"""
"""
res = run_sql("""select id_crcLIBRARY,
DATE_FORMAT(request_date,'%%Y-%%m-%%d'),
DATE_FORMAT(expected_date,'%%Y-%%m-%%d'),
library_notes
from crcILLREQUEST
where id=%s""", (ill_request_id, ))
if res:
return res[0]
else:
return None
def get_ill_request_received(ill_request_id):
"""
"""
res = run_sql("""select id_crcLIBRARY,
DATE_FORMAT(request_date,'%%Y-%%m-%%d'),
DATE_FORMAT(expected_date,'%%Y-%%m-%%d'),
DATE_FORMAT(arrival_date,'%%Y-%%m-%%d'),
DATE_FORMAT(due_date,'%%Y-%%m-%%d'),
cost,
barcode,
library_notes
from crcILLREQUEST
where id=%s""", (ill_request_id, ))
if res:
return res[0]
else:
return None
def get_ill_request_returned(ill_request_id):
"""
"""
res = run_sql("""select id_crcLIBRARY,
DATE_FORMAT(request_date,'%%Y-%%m-%%d'),
DATE_FORMAT(expected_date,'%%Y-%%m-%%d'),
DATE_FORMAT(arrival_date,'%%Y-%%m-%%d'),
DATE_FORMAT(due_date,'%%Y-%%m-%%d'),
DATE_FORMAT(return_date,'%%Y-%%m-%%d'),
cost,
barcode,
library_notes
from crcILLREQUEST
where id=%s""", (ill_request_id, ))
if res:
return res[0]
else:
return None
def get_ill_item_received(ill_request_id):
"""
"""
res = run_sql("""select id_crcLIBRARY,
DATE_FORMAT(request_date,'%%Y-%%m-%%d'),
DATE_FORMAT(expected_date,'%%Y-%%m-%%d'),
library_notes
from crcILLREQUEST
where id=%s""", (ill_request_id, ))
if res:
return res[0]
else:
return None
def get_ill_item_returned(ill_request_id):
"""
"""
res = run_sql("""select id_crcLIBRARY,
DATE_FORMAT(request_date,'%%Y-%%m-%%d'),
DATE_FORMAT(expected_date,'%%Y-%%m-%%d'),
DATE_FORMAT(arrival_date,'%%Y-%%m-%%d'),
DATE_FORMAT(due_date,'%%Y-%%m-%%d'),
barcode,
library_notes
from crcILLREQUEST
where id=%s""", (ill_request_id, ))
if res:
return res[0]
else:
return None
def get_ill_request_closed(ill_request_id):
"""
"""
res = run_sql("""select id_crcLIBRARY,
DATE_FORMAT(request_date,'%%Y-%%m-%%d'),
DATE_FORMAT(expected_date,'%%Y-%%m-%%d'),
DATE_FORMAT(arrival_date,'%%Y-%%m-%%d'),
DATE_FORMAT(due_date,'%%Y-%%m-%%d'),
DATE_FORMAT(return_date,'%%Y-%%m-%%d'),
cost,
barcode,
library_notes
from crcILLREQUEST
where id=%s""", (ill_request_id, ))
if res:
return res[0]
else:
return None
def get_ill_borrower_request(ill_request_id):
"""
"""
res = run_sql("""select ill.id_crcBORROWER, bor.name, bor.email, bor.mailbox,
DATE_FORMAT(ill.period_of_interest_from,'%%Y-%%m-%%d'),
DATE_FORMAT(ill.period_of_interest_to,'%%Y-%%m-%%d'),
ill.book_info, ill.borrower_comments,
ill.only_this_edition
from crcILLREQUEST ill, crcBORROWER bor
where ill.id_crcBORROWER=bor.id and ill.id=%s""", (ill_request_id, ))
if res:
return res[0]
else:
return None
def get_external_libraries():
"""
Get Libraries
"""
res = run_sql("""select id, name
from crcLIBRARY
where type='external'
""")
return res
def update_ill_request(ill_request_id, library_id, request_date, expected_date,
arrival_date, return_date, status, cost, currency, barcode,
library_notes):
"""
Update an ILL request.
"""
cost_format = cost + ' ' + currency
run_sql("""update crcILLREQUEST
set id_crcLIBRARY=%s,
request_date=%s,
expected_date=%s,
arrival_date=%s,
return_date=%s,
status=%s,
cost=%s,
barcode=%s,
library_notes=%s
where id=%s""",
(library_id, request_date, expected_date,
arrival_date, return_date, status, cost_format,
barcode, library_notes, ill_request_id))
def update_ill_request_pending(ill_request_id, ill_status, library_notes):
"""
"""
run_sql("""update crcILLREQUEST
set status=%s,
library_notes=%s
where id=%s""", (ill_status, library_notes, ill_request_id))
def update_ill_request_sent(ill_request_id, ill_status, library_id,
request_date, expected_date,
cost_format, barcode, library_notes):
"""
"""
run_sql("""update crcILLREQUEST
set status=%s,
id_crcLIBRARY=%s,
request_date=%s,
expected_date=%s,
cost=%s,
barcode=%s,
library_notes=%s
where id=%s""", (ill_status, library_id,
request_date, expected_date,
cost_format, barcode, library_notes,
ill_request_id))
def update_ill_request_cancelled(ill_request_id, ill_status,
cost_format, barcode, library_notes):
"""
"""
run_sql("""update crcILLREQUEST
set status=%s,
cost=%s,
barcode=%s,
library_notes=%s
where id=%s""", (ill_status, cost_format,
barcode, library_notes,
ill_request_id))
def update_ill_item_received(ill_request_id, ill_status,
arrival_date, due_date,
cost_format, barcode, library_notes):
"""
"""
run_sql("""update crcILLREQUEST
set status=%s,
arrival_date=%s,
due_date=%s,
cost=%s,
barcode=%s,
library_notes=%s
where id=%s""", (ill_status,
arrival_date, due_date,
cost_format, barcode, library_notes,
ill_request_id))
def update_ill_item_returned(ill_request_id, ill_status,
return_date, cost_format,
library_notes):
"""
"""
run_sql("""update crcILLREQUEST
set status=%s,
return_date=%s,
cost=%s,
library_notes=%s
where id=%s""", (ill_status, return_date,
cost_format, library_notes,
ill_request_id))
def update_ill_request_closed(ill_request_id, ill_status, library_notes):
"""
"""
run_sql("""update crcILLREQUEST
set status=%s,
library_notes=%s
where id=%s""", (ill_status,
library_notes,
ill_request_id))
def get_order_details(purchase_id):
"""
"""
res = run_sql("""select id, id_bibrec, id_crcVENDOR,
DATE_FORMAT(ordered_date,'%%Y-%%m-%%d'),
DATE_FORMAT(expected_date,'%%Y-%%m-%%d'),
price, status, notes
from crcPURCHASE
where id=%s""", (purchase_id, ))
if res:
return res[0]
else:
return None
def uptade_purchase(purchase_id, recid, vendor_id, price,
status, order_date, expected_date, notes):
"""
"""
run_sql("""update crcPURCHASE
set id_bibrec=%s,
id_crcVENDOR=%s,
ordered_date=%s,
expected_date=%s,
price=%s,
status=%s,
notes=%s
where id=%s""",
(recid, vendor_id, order_date, expected_date, price, status,
notes, purchase_id))
def add_new_vendor(name, email, phone, address, notes):
"""
Add a new vendor.
"""
run_sql("""insert into crcVENDOR (name, email, phone,
address, notes)
values (%s, %s, %s, %s, %s)""",
(name, email, phone, address, notes))
def search_vendor_by_name(string):
"""
string: search pattern.
"""
res = run_sql("""select id, name
from crcVENDOR
where name regexp %s
""", (string, ))
return res
def search_vendor_by_email(string):
"""
string: search pattern.
"""
res = run_sql("""select id, name
from crcVENDOR
where email regexp %s
""", (string, ))
return res
def get_all_vendors():
"""
"""
res = run_sql("""select id, name
from crcVENDOR""")
return res
def update_vendor_info(vendor_id, name, email, phone, address):
"""
Update vendor information.
vendor_id: identify the vendor. It is also the primary key of
the table crcVENDOR.
"""
return int(run_sql("""update crcVENDOR
set name=%s,
email=%s,
phone=%s,
address=%s
where id=%s""",
(name, email, phone, address, vendor_id)))
def get_vendors():
"""
Get vendors
"""
res = run_sql("""select id, name
from crcVENDOR""")
return res
def get_vendor_details(vendor_id):
"""
vendor_id: identify the vendor. It is also the primary key of
the table crcVENDOR.
"""
res = run_sql("""select id, name, address, email, phone, notes
from crcVENDOR
where id=%s;
""", (vendor_id, ))
if res:
return res[0]
else:
return None
def get_vendor_notes(vendor_id):
"""
Get the notes of a vendor.
vendor_id: identify the vendor. The data associate
to this vendor will be retrieved. It is also
the primary key of the crcVENDOR table.
"""
res = run_sql("""select notes
from crcVENDOR
where id=%s""",
(vendor_id, ))
if res:
return res[0][0]
else:
return None
def add_new_vendor_note(new_note, vendor_id):
"""
Add a new vendor's note.
new_note: note who will be added.
vendor_id: identify the vendor. A new note will be
associate to this vendor. It is also
the primary key of the crcVENDOR table.
"""
run_sql("""update crcVENDOR
set notes=concat(notes,%s)
where id=%s;
""", (new_note, vendor_id))
def get_list_of_vendors():
"""
Get vendors
"""
res = run_sql("""select id, name
from crcVENDOR""")
return res
def get_vendor_name(vendor_id):
"""
Get Vendor's name.
vendor_id: identify the vendor. It is also the primary key of
the table crcVENDOR.
"""
res = run_sql("""select name
from crcVENDOR
where id=%s""",
(vendor_id, ))
if res:
return res[0][0]
else:
return None
def get_ill_request_notes(ill_request_id):
"""
"""
res = run_sql("""select library_notes
from crcILLREQUEST
where id=%s""",
(ill_request_id, ))
if res:
return res[0][0]
else:
return None
def update_ill_request_notes(ill_request_id, library_notes):
"""
"""
run_sql("""update crcILLREQUEST
set library_notes=%s
where id=%s""", (str(library_notes), ill_request_id))
def get_ill_borrower(ill_request_id):
"""
"""
res = run_sql("""select id_crcBORROWER
from crcILLREQUEST
where id=%s""", (ill_request_id, ))
if res:
return res[0][0]
else:
return None
def get_ill_barcode(ill_request_id):
"""
"""
res = run_sql("""select barcode
from crcILLREQUEST
where id=%s""", (ill_request_id, ))
if res:
return res[0][0]
else:
return None
-def update_ill_loan_status(borrower_id, barcode, return_date, type):
+def update_ill_loan_status(borrower_id, barcode, return_date, loan_type):
"""
"""
run_sql("""update crcLOAN
set status = 'returned',
returned_on = %s
where id_crcBORROWER = %s
and barcode = %s
and type = %s""",
- (return_date, borrower_id, barcode, type))
+ (return_date, borrower_id, barcode, loan_type))
def get_recid(barcode):
"""
Get the id bibrec.
barcode: identify the item. It is the primary key of the table
crcITEM.
"""
res = run_sql("""select id_bibrec
from crcITEM
where barcode=%s""",
(barcode, ))
try:
return res[0]
except IndexError:
return None
def get_ill_requests_details(borrower_id):
"""
"""
res = run_sql("""select id, book_info, id_crcLIBRARY,
DATE_FORMAT(request_date,'%%Y-%%m-%%d'),
DATE_FORMAT(expected_date,'%%Y-%%m-%%d'),
DATE_FORMAT(arrival_date,'%%Y-%%m-%%d'),
DATE_FORMAT(due_date,'%%Y-%%m-%%d'),
status, library_notes
from crcILLREQUEST
where id_crcBORROWER=%s and status!='document received, request closed' """, (borrower_id, ))
return res
def bor_ill_historical_overview(borrower_id):
"""
"""
res = run_sql("""select id, book_info, id_crcLIBRARY,
DATE_FORMAT(request_date,'%Y-%m-%d'),
DATE_FORMAT(expected_date,'%Y-%m-%d'),
DATE_FORMAT(arrival_date,'%Y-%m-%d'),
DATE_FORMAT(due_date,'%Y-%m-%d'),
status, library_notes
from crcILLREQUEST
where id_crcBORROWER=%s and status='document received, request closed'"""
, (borrower_id, ))
return res
def get_ill_notes(ill_id):
"""
"""
res = run_sql("""select library_notes
from crcILLREQUEST
where id=%s""",
(ill_id, ))
if res:
return res[0][0]
else:
return None
def update_ill_notes(ill_id, ill_notes):
"""
"""
run_sql("""update crcILLREQUEST
set library_notes=%s
where id=%s """, (str(ill_notes), ill_id))
def is_on_loan(barcode):
"""
"""
res = run_sql("""select id
from crcLOAN
where barcode=%s and status='on loan'
""", (barcode, ))
if res:
return True
else:
return False
def is_requested(barcode):
"""
"""
res = run_sql("""select id
from crcLOANREQUEST
where barcode=%s and
(status = 'pending' or status = 'waiting')
""", (barcode, ))
try:
return res
except IndexError:
return None
def get_lib_location(barcode):
"""
"""
res = run_sql("""select id_crcLIBRARY, location
from crcITEM
where barcode=%s""",
(barcode, ))
if res:
return res[0]
else:
return None
def get_barcodes(recid):
"""
"""
res = run_sql("""select barcode
from crcITEM
where id_bibrec=%s""",
(recid, ))
barcodes = []
for i in range(len(res)):
barcodes.append(res[i][0])
return barcodes
def barcode_in_use(barcode):
"""
"""
res = run_sql("""select id_bibrec
from crcITEM
where barcode=%s""",
(barcode, ))
if res:
return True
else:
return False
def get_expired_loans_with_requests():
"""
"""
res = run_sql("""SELECT DISTINCT
lr.id,
lr.id_bibrec,
lr.id_crcBORROWER,
it.id_crcLIBRARY,
it.location,
DATE_FORMAT(lr.period_of_interest_from,'%Y-%m-%d'),
DATE_FORMAT(lr.period_of_interest_to,'%Y-%m-%d'),
lr.request_date
FROM crcLOANREQUEST lr,
crcITEM it,
crcLOAN l
WHERE it.barcode=lr.barcode AND
lr.barcode=l.barcode AND
(lr.status='pending' or lr.status='waiting') AND
l.status='on loan'
and l.due_date < CURDATE()
ORDER BY lr.request_date;
""")
return res
def get_total_of_loans():
"""
"""
res = run_sql("""select count(id)
from crcLOAN
where status='on loan';""")
return res[0][0]
def update_borrower_notes(borrower_id, borrower_notes):
"""
"""
run_sql("""update crcBORROWER
set notes=%s
where id=%s """, (str(borrower_notes), borrower_id))
def get_loan_notes(loan_id):
"""
"""
res = run_sql("""select notes
from crcLOAN
where id=%s""",
(loan_id, ))
if res:
return res[0][0]
else:
return None
def update_loan_notes(loan_id, loan_notes):
"""
"""
run_sql("""update crcLOAN
set notes=%s
where id=%s """, (str(loan_notes), loan_id))
def update_library_notes(library_id, library_notes):
"""
"""
run_sql("""update crcLIBRARY
set notes=%s
where id=%s """, (str(library_notes), library_id))
def get_ill_book_info(ill_request_id):
"""
"""
res = run_sql("""select book_info
from crcILLREQUEST
where id=%s""",
(ill_request_id, ))
if res:
return res[0][0]
else:
return None
def get_ill_ids():
"""
"""
res = run_sql("""select id
from crcILLREQUEST
where status!='document received, request closed'""")
return res
def get_copies_status(recid):
"""
"""
res = run_sql("""select status
from crcITEM
where id_bibrec=%s""",
(recid, ))
if res:
return res[0]
else:
return None
def get_loan_recid(loan_id):
"""
"""
res = run_sql("""select id_bibrec
from crcLOAN
where id=%s""",
(loan_id, ))
if res:
return res[0][0]
else:
return None
diff --git a/modules/bibcirculation/lib/bibcirculation_regression_tests.py b/modules/bibcirculation/lib/bibcirculation_regression_tests.py
index 039e4e442..5e10bec8a 100644
--- a/modules/bibcirculation/lib/bibcirculation_regression_tests.py
+++ b/modules/bibcirculation/lib/bibcirculation_regression_tests.py
@@ -1,76 +1,75 @@
# -*- coding: utf-8 -*-
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
"""BibCirculation Regression Test Suite."""
__revision__ = "$Id$"
import unittest
from invenio.config import CFG_SITE_URL
from invenio.testutils import make_test_suite, run_test_suite, \
- test_web_page_content, merge_error_messages, \
- test_web_page_existence
+ test_web_page_content, merge_error_messages
class BibCirculationUsersWebPagesAvailabilityTest(unittest.TestCase):
"""Check BibCirculation web pages whether they are up or not."""
def test_your_loans_page_availability(self):
"""bibcirculation - availability of your loans page"""
baseurl = CFG_SITE_URL + '/yourloans/'
_exports = ['', 'display', 'loanshistoricaloverview']
error_messages = []
for url in [baseurl + page for page in _exports]:
error_messages.extend(test_web_page_content(url))
if error_messages:
self.fail(merge_error_messages(error_messages))
return
class BibCirculationAdminsWebPagesAvailabilityTest(unittest.TestCase):
"""Check BibCirculation web pages whether they are up or not for Admins."""
def test_admin_pages_availability(self):
"""bibcirculation - availability of main admin page"""
baseurl = CFG_SITE_URL + '/admin/bibcirculation/bibcirculationadmin.py'
self.assertEqual([], test_web_page_content(baseurl,
expected_text="BibCirculation Admin"))
return
def test_borrower_search_availability(self):
"""bibcirculation - availability of borrower search"""
baseurl = CFG_SITE_URL + '/admin/bibcirculation/bibcirculationadmin.py/' \
+ 'borrower_search_result?column=name&string=john'
self.assertEqual([], test_web_page_content(baseurl, username='admin',
expected_text='Borrower search result'))
return
TEST_SUITE = make_test_suite(BibCirculationUsersWebPagesAvailabilityTest,
BibCirculationAdminsWebPagesAvailabilityTest)
if __name__ == "__main__":
run_test_suite(TEST_SUITE, warn_user=True)
diff --git a/modules/bibcirculation/lib/bibcirculation_templates.py b/modules/bibcirculation/lib/bibcirculation_templates.py
index c022e82ae..bbb04f2dd 100644
--- a/modules/bibcirculation/lib/bibcirculation_templates.py
+++ b/modules/bibcirculation/lib/bibcirculation_templates.py
@@ -1,16607 +1,16605 @@
# -*- coding: utf-8 -*-
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
""" Templates for bibcirculation module """
__revision__ = "$Id$"
import datetime
import time
import cgi
from invenio.urlutils import create_html_link
from invenio.config import CFG_SITE_URL, CFG_SITE_LANG, \
CFG_CERN_SITE, CFG_SITE_SECURE_URL
+from invenio.bibcirculation_config import CFG_BIBCIRCULATION_LIBRARIAN_EMAIL
from invenio.messages import gettext_set_language
-
-
import invenio.bibcirculation_dblayer as db
from invenio.bibcirculation_utils import get_book_cover, \
book_information_from_MARC, \
book_title_from_MARC, \
renew_loan_for_X_days, \
get_item_info_for_search_result, \
all_copies_are_missing, \
has_copies
_MENU_ = """
-
-
""" % {'url': CFG_SITE_URL}
class Template:
"""Templates for BibCirculation module"""
def tmpl_infobox(self, infos, ln=CFG_SITE_LANG):
"""
Display len(infos) information fields
@param infos: list of strings
@param ln: language
@return html output
"""
_ = gettext_set_language(ln)
if not((type(infos) is list) or (type(infos) is tuple)):
infos = [infos]
infobox = ""
for info in infos:
infobox += "
"
lines = info.split("\n")
for line in lines[0:-1]:
infobox += line + " \n"
infobox += lines[-1] + "
\n"
return infobox
def tmpl_holdings_information2(self, recid, req, holdings_info,
ln=CFG_SITE_LANG):
"""
This template is used in the user interface. In this template
it is possible to see all details (loan period, number of copies, location, etc)
about a book.
@param recid: identify the record. Primary key of bibrec.
@type recid: int
@param holdings_info: book's information (all copies)
@type holdings_info: list
"""
_ = gettext_set_language(ln)
if not book_title_from_MARC(recid):
out = """
This record does not exist.
"""
return out
elif not has_copies(recid):
out = """
This record has no copies.
"""
return out
# verify if all copies are missing
elif all_copies_are_missing(recid):
ill_link = """ILL services""" % (CFG_SITE_URL, recid)
out = """
All the copies of %s are missing.You can request a copy using %s.
""" % (book_title_from_MARC(recid), ill_link)
return out
# verify if there are no copies
elif not holdings_info:
out = """
This item has no holdings.
"""
return out
out = """
"""
out += """
%s
%s
%s
%s
%s
%s
%s
%s
%s
""" % (_("Barcode"), _("Library"), _("Collection"),
_("Location"), _("Description"), _("Loan period"),
_("Status"), _("Due date"), _("Option(s)"))
for (barcode, library, collection, location, description,
loan_period, status, due_date) in holdings_info:
if status == 'Not for loan':
request_button = '-'
else:
request_button = """""" % (CFG_SITE_URL, recid, barcode,
_("Request"))
if status == 'missing':
out += """ """
else:
out += """
%s
%s
%s
%s
%s
%s
%s
%s
%s
""" % (barcode, library, collection or '-', location,
description or '-', loan_period, status,
due_date or '-', request_button)
from invenio.bibcirculationadminlib import is_adminuser
(auth_code, _auth_message) = is_adminuser(req)
if auth_code != 0:
- bibcirc_link = ''
+ bibcirc_link = ''
else:
bibcirc_link = create_html_link(CFG_SITE_URL +
'/admin/bibcirculation/bibcirculationadmin.py/get_item_details',
{'recid': recid, 'ln': ln},
_("See this book on BibCirculation"))
out += """
"""
return message
- def tmpl_message_request_send_ok_cern(self, ln=CFG_SITE_LANG):
+ def tmpl_message_request_send_ok_cern(self):
message = "Your request has been registered and the document"\
" will be sent to you via internal mail."
return message
- def tmpl_message_request_send_ok_other(self, ln=CFG_SITE_LANG):
+ def tmpl_message_request_send_ok_other(self):
message = "Your request has been registered."
return message
def tmpl_message_request_send_fail_cern(self):
message = "It is not possible to validate your request. "\
"Your office address is not available. "\
"Please contact " + CFG_BIBCIRCULATION_LIBRARIAN_EMAIL
return message
- def tmpl_message_request_send_fail_other(self, ln=CFG_SITE_LANG):
+ def tmpl_message_request_send_fail_other(self):
message = "It is not possible to validate your request. "\
"Your office address is not available. "\
"Please contact " + CFG_BIBCIRCULATION_LIBRARIAN_EMAIL
return message
def tmpl_borrower_search_result(self, result, redirect='no', ln=CFG_SITE_LANG):
"""
When the admin features 'borrower_seach' is used, this template
show the result.
@param result: search result
@type result:list
@param ln: language
"""
_ = gettext_set_language(ln)
out = """ """
out += _MENU_
if len(result) == 0:
out += """
%s
""" % (_("0 borrower(s) found."))
else:
out += """
%s borrower(s) found
%s
""" % (len(result), _("Borrower(s)"))
for (borrower_id, name) in result:
if redirect == 'no':
borrower_link = create_html_link(CFG_SITE_URL +
'/admin/bibcirculation/bibcirculationadmin.py/get_borrower_details',
{'borrower_id': borrower_id, 'ln': ln},
(name))
else:
borrower_link = create_html_link(CFG_SITE_URL +
'/admin/bibcirculation/bibcirculationadmin.py/create_new_request_step1',
{'borrower_id': borrower_id, 'ln': ln},
(name))
out += """
%s
""" % (borrower_link, borrower_id)
out += """
""" % (_("Back"))
return out
def tmpl_yourloans(self, loans, requests, borrower_id,
infos, ln=CFG_SITE_LANG):
"""
When an user is logged in, it is possible to check his loans.
In the section 'yourloans', it is also possible to renew a single
loan or all loans.
@param result: show all loans of an user who is logged in
@param uid: user ID
@param infos: display information about holdings
@param ln: language
"""
_ = gettext_set_language(ln)
renew_all_link = create_html_link(CFG_SITE_SECURE_URL +
'/yourloans/display',
{'borrower_id': borrower_id},
(_("Renew all loans")))
loanshistoricaloverview_link = create_html_link(CFG_SITE_SECURE_URL +
'/yourloans/loanshistoricaloverview',
{'ln': ln},
(_("Loans - historical overview")))
out = self.tmpl_infobox(infos, ln)
if len(loans) == 0:
out += """
%s
""" % (_("You don't have any book on loan."))
else:
out += """
""" % (record_link,
loaned_on,
due_date,
renew_link)
out += """
%s
""" % (renew_all_link)
if len(requests) == 0:
out += """
%s
%s
%s
""" % (_("Your Requests"),
_("You don't have any request (waiting or pending)."),
loanshistoricaloverview_link,
CFG_SITE_URL,
_("Back to home"))
else:
out +="""
""" % (record_link, request_date,
status, cancel_request_link)
out +="""
%s
""" % (loanshistoricaloverview_link,
CFG_SITE_URL,
_("Back to home"))
return out
def tmpl_loanshistoricaloverview(self, result, ln):
"""
In the section 'yourloans' it is possible to see the loans historical overview
of the user who is logged in. Bibcirculation display all loans where the status is
'returned'.
@param result: show all loans where status = 'returned'
@param ln: language
"""
_ = gettext_set_language(ln)
out = """
""" % (record_link, loaned_on,
returned_on, nb_renewalls)
out += """
""" % (_("Back"))
return out
def tmpl_new_request(self, uid, recid, barcode, ln=CFG_SITE_LANG):
"""
This template is used when an user want to request a book. Here it is
possible to define the 'period of interest'
@param uid: user ID
@param recid: recID - CDS Invenio record identifier
@param barcode: book's barcode
@param ln: language
"""
_ = gettext_set_language(ln)
today = datetime.date.today()
out = """
"""
out = out % {'url': CFG_SITE_URL,
'from_year' : today.year,
'from_month' : today.month,
'from_day': today.day,
'to_year': today.year + 1,
'to_month': today.month,
'to_day': today.day,
'submit_button': ('Confirm'),
'recid': recid,
'uid': uid,
'barcode': barcode
}
return out
- def tmpl_new_request2(self, uid, recid, barcode, ln=CFG_SITE_LANG):
+ def tmpl_new_request2(self, recid, barcode, ln=CFG_SITE_LANG):
"""
This template is used when an user want to request a book. Here it is
possible to define the 'period of interest'
@param uid: user ID
@param recid: recID - CDS Invenio record identifier
@param barcode: book's barcode
@param ln: language
"""
_ = gettext_set_language(ln)
today = datetime.date.today()
gap = datetime.timedelta(days=180)
more_6_months = (today + gap).strftime('%Y-%m-%d')
out = """
""" % (CFG_SITE_URL, CFG_SITE_URL,
CFG_SITE_URL, recid,
_("Enter your period of interest"),
_("From"),CFG_SITE_URL, today, _("To"), CFG_SITE_URL, more_6_months,
barcode, _("Back"), _("Confirm"))
return out
def tmpl_new_request_send(self, message, ln=CFG_SITE_LANG):
"""
This template is used in the user interface.
@param ln: language of the page
"""
_ = gettext_set_language(ln)
out = """
""" % (message,
_("You can see your loans "),
CFG_SITE_URL + '/yourloans/display',
_("here"),
_("."),
CFG_SITE_URL,
_("Back to home"))
return out
def tmpl_next_loan_request_done(self, ln=CFG_SITE_LANG):
"""
This template is used in the admin interface, when a request is
'waiting' in the queue.
@param ln: language of the page
"""
_ = gettext_set_language(ln)
out = """
"""
out += _MENU_
out += """
%s
""" % (_("A new loan has been registered."),
CFG_SITE_URL,
_("Back to home"))
return out
def tmpl_get_pending_requests(self, result, ln=CFG_SITE_LANG):
"""
@param ln: language of the page
"""
_ = gettext_set_language(ln)
out = _MENU_
out += """
"""
if len(result) == 0:
out += """
%s
""" % (_("No more requests are pending."),
_("Back"))
else:
out += """
"""
out += """
""" % (_("Back"))
return out
def tmpl_get_waiting_requests(self, result, ln=CFG_SITE_LANG):
"""
Template for the admin interface. Show pending requests(all, on loan, available)
@param result: items with status = 'pending'
@param ln: language
"""
_ = gettext_set_language(ln)
out = _MENU_
out += """
"""
if len(result) == 0:
out += """
%s
""" % (_("No more requests are pending."),
_("Back"))
else:
out += """
"""
out += """
""" % (_("Back"))
return out
def tmpl_get_next_waiting_loan_request(self, result, recid, barcode, ln=CFG_SITE_LANG):
"""
Template for the admin interface. Show the next request in the queue.
@param result: next request with status = 'waiting'
@param barcode: book's barcode
@param ln: language
"""
_ = gettext_set_language(ln)
out = """
"""
out += _MENU_
if len(result) == 0:
out += """
%s
""" % (_("No hold requests waiting."), CFG_SITE_URL)
else:
out += """