Added error messages for the checkout process

Now, it's impossible to sign out stickered books
This commit is contained in:
Felix Bauckholt 2016-02-06 16:41:27 -05:00
parent 9b9e95be69
commit da52809b4d
4 changed files with 34 additions and 12 deletions

View File

@ -1,6 +1,7 @@
import sqlite3
from library import permissions
from library.exceptions import *
# because of the way that SQLite works we need to have these two
# files be different, because the Office staff needs read/write
@ -248,6 +249,13 @@ def getBookCategories(book):
c.close()
return cats
def isStickered(book):
cats = getBookCategories(book)
for c in cats:
if c['category'] == "Stickered":
return True
return False
@permissions.check_permissions(permissions.PERMISSION_LIBCOM)
def categorizeBook(book, cats):
conn = sqlite3.connect(_catalogue_db_file)
@ -307,6 +315,9 @@ def deleteCategories(cats):
#########################################
@permissions.check_permissions(permissions.PERMISSION_OFFICE)
def checkout_book(book_id, uwid):
book = get_book(book_id)
if isStickered(book):
raise StickeredError()
conn = sqlite3.connect(_checkout_db_file)
c = conn.cursor()
@ -314,12 +325,11 @@ def checkout_book(book_id, uwid):
query = "INSERT INTO " + _checkout_table + " (id, uwid) VALUES (?, ?);"
c.execute(query, (book_id, uwid))
except sqlite3.IntegrityError:
return False # didn't work
raise CheckoutError()
finally:
conn.commit()
c.close()
return True # worked
@permissions.check_permissions(permissions.PERMISSION_OFFICE)
def return_book(book_id):

View File

@ -18,3 +18,9 @@ class PermissionsError(LibrarianException):
class NoHighlightedEntry(LibrarianException):
error_msg = "No highlighted entry"
class CheckoutError(LibrarianException):
error_msg = "Checkout didn't work"
class StickeredError(CheckoutError):
error_msg = "You can't sign out stickered books!"

View File

@ -1,5 +1,5 @@
import curses
from library.interface.form import FormWindow,BookForm
from library.interface.form import FormWindow,BookForm,catch_error_with
import library.database as db
@ -46,6 +46,7 @@ class FinalCheck(FormWindow):
def _return_values(self):
return True
@catch_error_with(lambda w, hb, *args : (w, hb, None))
def checkout_procedure(w, hb, cy, cx, mx):
"""Procedure to check out a book

View File

@ -358,11 +358,16 @@ def error_form(text, w, hb):
f.event_loop()
f.clear()
def catch_error(fn):
def wrapper_fun(self, *args, **kwd):
def catch_error_with(getwhb):
def decorator(fn):
def wrapper_fun(*args, **kwd):
try:
return fn(self, *args, **kwd)
return fn(*args, **kwd)
except LibrarianException as e:
error_form(str(e), self.w, self.hb)
self.refresh()
w, hb, cleanup = getwhb(*args, **kwd)
error_form(str(e), w, hb)
if cleanup: cleanup()
return wrapper_fun
return decorator
catch_error = catch_error_with(lambda self, *args, **kwd : (self.w, self.hb, self.refresh))