Added error messages for the checkout process
Now, it's impossible to sign out stickered books
This commit is contained in:
parent
9b9e95be69
commit
da52809b4d
|
@ -1,6 +1,7 @@
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
from library import permissions
|
from library import permissions
|
||||||
|
from library.exceptions import *
|
||||||
|
|
||||||
# because of the way that SQLite works we need to have these two
|
# because of the way that SQLite works we need to have these two
|
||||||
# files be different, because the Office staff needs read/write
|
# files be different, because the Office staff needs read/write
|
||||||
|
@ -248,6 +249,13 @@ def getBookCategories(book):
|
||||||
c.close()
|
c.close()
|
||||||
return cats
|
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)
|
@permissions.check_permissions(permissions.PERMISSION_LIBCOM)
|
||||||
def categorizeBook(book, cats):
|
def categorizeBook(book, cats):
|
||||||
conn = sqlite3.connect(_catalogue_db_file)
|
conn = sqlite3.connect(_catalogue_db_file)
|
||||||
|
@ -307,6 +315,9 @@ def deleteCategories(cats):
|
||||||
#########################################
|
#########################################
|
||||||
@permissions.check_permissions(permissions.PERMISSION_OFFICE)
|
@permissions.check_permissions(permissions.PERMISSION_OFFICE)
|
||||||
def checkout_book(book_id, uwid):
|
def checkout_book(book_id, uwid):
|
||||||
|
book = get_book(book_id)
|
||||||
|
if isStickered(book):
|
||||||
|
raise StickeredError()
|
||||||
conn = sqlite3.connect(_checkout_db_file)
|
conn = sqlite3.connect(_checkout_db_file)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
|
|
||||||
|
@ -314,12 +325,11 @@ def checkout_book(book_id, uwid):
|
||||||
query = "INSERT INTO " + _checkout_table + " (id, uwid) VALUES (?, ?);"
|
query = "INSERT INTO " + _checkout_table + " (id, uwid) VALUES (?, ?);"
|
||||||
c.execute(query, (book_id, uwid))
|
c.execute(query, (book_id, uwid))
|
||||||
except sqlite3.IntegrityError:
|
except sqlite3.IntegrityError:
|
||||||
return False # didn't work
|
raise CheckoutError()
|
||||||
finally:
|
finally:
|
||||||
conn.commit()
|
conn.commit()
|
||||||
c.close()
|
c.close()
|
||||||
|
|
||||||
return True # worked
|
|
||||||
|
|
||||||
@permissions.check_permissions(permissions.PERMISSION_OFFICE)
|
@permissions.check_permissions(permissions.PERMISSION_OFFICE)
|
||||||
def return_book(book_id):
|
def return_book(book_id):
|
||||||
|
|
|
@ -18,3 +18,9 @@ class PermissionsError(LibrarianException):
|
||||||
|
|
||||||
class NoHighlightedEntry(LibrarianException):
|
class NoHighlightedEntry(LibrarianException):
|
||||||
error_msg = "No highlighted entry"
|
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!"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import curses
|
import curses
|
||||||
from library.interface.form import FormWindow,BookForm
|
from library.interface.form import FormWindow,BookForm,catch_error_with
|
||||||
import library.database as db
|
import library.database as db
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,6 +46,7 @@ class FinalCheck(FormWindow):
|
||||||
def _return_values(self):
|
def _return_values(self):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@catch_error_with(lambda w, hb, *args : (w, hb, None))
|
||||||
def checkout_procedure(w, hb, cy, cx, mx):
|
def checkout_procedure(w, hb, cy, cx, mx):
|
||||||
"""Procedure to check out a book
|
"""Procedure to check out a book
|
||||||
|
|
||||||
|
|
|
@ -358,11 +358,16 @@ def error_form(text, w, hb):
|
||||||
f.event_loop()
|
f.event_loop()
|
||||||
f.clear()
|
f.clear()
|
||||||
|
|
||||||
def catch_error(fn):
|
def catch_error_with(getwhb):
|
||||||
def wrapper_fun(self, *args, **kwd):
|
def decorator(fn):
|
||||||
|
def wrapper_fun(*args, **kwd):
|
||||||
try:
|
try:
|
||||||
return fn(self, *args, **kwd)
|
return fn(*args, **kwd)
|
||||||
except LibrarianException as e:
|
except LibrarianException as e:
|
||||||
error_form(str(e), self.w, self.hb)
|
w, hb, cleanup = getwhb(*args, **kwd)
|
||||||
self.refresh()
|
error_form(str(e), w, hb)
|
||||||
|
if cleanup: cleanup()
|
||||||
return wrapper_fun
|
return wrapper_fun
|
||||||
|
return decorator
|
||||||
|
|
||||||
|
catch_error = catch_error_with(lambda self, *args, **kwd : (self.w, self.hb, self.refresh))
|
||||||
|
|
Loading…
Reference in New Issue