Button-only forms, including BookView

The checkout process should be way more convenient
now!

Also, when viewing books (by pressing Enter), you
can see their categories and see if they're
checked out.
This commit is contained in:
Felix Bauckholt 2016-02-06 16:44:34 -05:00
parent da52809b4d
commit 19b8869134
4 changed files with 44 additions and 22 deletions

View File

@ -330,6 +330,15 @@ def checkout_book(book_id, uwid):
conn.commit() conn.commit()
c.close() c.close()
def get_checkout_status(book_id):
conn = sqlite3.connect(_checkout_db_file)
c = conn.cursor()
query = "SELECT uwid,date_out FROM "+ _checkout_table + " WHERE id = :id ;"
c.execute(query, {"id": book_id})
data = c.fetchone()
c.close()
if data: return {"uwid":data[0], "date_out":data[1]}
return None
@permissions.check_permissions(permissions.PERMISSION_OFFICE) @permissions.check_permissions(permissions.PERMISSION_OFFICE)
def return_book(book_id): def return_book(book_id):

View File

@ -1,6 +1,6 @@
import curses import curses
import library.database as db import library.database as db
from library.interface.form import BookForm,CategoryForm,error_form,catch_error from library.interface.form import BookForm,BookView,CategoryForm,error_form,catch_error
from library.exceptions import NoHighlightedEntry from library.exceptions import NoHighlightedEntry
class browserWindow: class browserWindow:
@ -277,10 +277,8 @@ class trashBrowser(browserWindow):
def viewSelection(self,book): def viewSelection(self,book):
bookid = book['id'] bookid = book['id']
w=curses.newwin(1,1) w=curses.newwin(1,1)
bf = BookForm(w, self.hb, book, width=self.mx-10) bf = BookView(w, self.hb, book, width=self.mx-10)
self.centreChild(w) self.centreChild(w)
bf.caption='Viewing Book '+str(bookid)
bf.blabel='done'
bf.event_loop() bf.event_loop()
bf.clear() bf.clear()
@ -359,10 +357,8 @@ class bookBrowser(browserWindow):
def viewSelection(self,book): def viewSelection(self,book):
bookid = book['id'] bookid = book['id']
w=curses.newwin(1,1) w=curses.newwin(1,1)
bf = BookForm(w,self.hb,book, width=self.mx-20) bf = BookView(w,self.hb,book, width=self.mx-20)
self.centreChild(w) self.centreChild(w)
bf.caption='Viewing Book '+str(bookid)
bf.blabel='done'
bf.event_loop() bf.event_loop()
bf.clear() bf.clear()

View File

@ -1,5 +1,5 @@
import curses import curses
from library.interface.form import FormWindow,BookForm,catch_error_with from library.interface.form import FormWindow,BookForm,BookView,catch_error_with
import library.database as db import library.database as db
@ -18,7 +18,7 @@ class BookIDForm(FormWindow):
self.clear() self.clear()
bookid = self.entries[0].value bookid = self.entries[0].value
book = db.get_book(bookid) book = db.get_book(bookid)
bf = BookForm(self.w, self.hb, book, width=self.mx-10) bf = BookView(self.w, self.hb, book, width=self.mx-10)
(y,x) = self.w.getbegyx() (y,x) = self.w.getbegyx()
(r,c) = self.w.getmaxyx() (r,c) = self.w.getmaxyx()
self.w.mvwin( y+(self.my-r)//2,x+(self.mx-c)//2) self.w.mvwin( y+(self.my-r)//2,x+(self.mx-c)//2)
@ -42,6 +42,7 @@ class FinalCheck(FormWindow):
caption = "Is this information correct?" caption = "Is this information correct?"
blabel = "Check Out" blabel = "Check Out"
labels = ["Username", "Book ID"] labels = ["Username", "Book ID"]
buttononly = True
def _return_values(self): def _return_values(self):
return True return True

View File

@ -1,5 +1,7 @@
import curses import curses
from library.exceptions import LibrarianException from library.exceptions import LibrarianException
from copy import copy
import library.database as db
class TextEntry: class TextEntry:
@ -121,6 +123,7 @@ class FormWindow:
left = 0 left = 0
top = 2 top = 2
row = 2 row = 2
buttononly = False
caption = "Form" caption = "Form"
blabel = "Done" blabel = "Done"
labels = ["label1"] labels = ["label1"]
@ -144,7 +147,11 @@ class FormWindow:
def event_loop(self): def event_loop(self):
self.w.keypad(1) self.w.keypad(1)
self.refresh() self.refresh()
self.hl=0; self.hl=0
if self.buttononly:
self.bt = 1
self._highlight_button()
else:
self.entries[self.hl].gain_focus() self.entries[self.hl].gain_focus()
ch = self.w.getch() ch = self.w.getch()
@ -215,6 +222,7 @@ class FormWindow:
self.w.chgat(self.brow,1,self.mx-2,curses.A_NORMAL) self.w.chgat(self.brow,1,self.mx-2,curses.A_NORMAL)
def _mv_focus(self,delta): def _mv_focus(self,delta):
if self.buttononly: return
if self.bt==-1: if self.bt==-1:
self.entries[self.hl].lose_focus() self.entries[self.hl].lose_focus()
else: else:
@ -224,7 +232,6 @@ class FormWindow:
self.hl = new self.hl = new
if new == len(self.labels): if new == len(self.labels):
self.bt = 1 self.bt = 1
self.bt = min(self.bt,1)
self._highlight_button() self._highlight_button()
else: else:
self.bt=-1 self.bt=-1
@ -308,6 +315,24 @@ class BookForm(FormWindow):
else: else:
FormWindow.handle_input(self,ch) FormWindow.handle_input(self,ch)
class BookView(BookForm):
blabel = "Done"
buttononly = True
labels = ["ISBN", "LCCN", "Title", "Subtitle", "Authors", "Edition",
"Publisher", "Publish Date", "Publish Year", "Publish Month", "Publish location",
"Pages", "Pagination", "Weight", "Categories", "Status"]
def __init__(self, window, helpbar, book, width=50):
book = copy(book)
book["categories"] = " - ".join([cat["category"] for cat in db.getBookCategories(book)])
status = db.get_checkout_status(book["id"])
if status:
book["status"] = "Checked out by %s (%s)" % (status["uwid"], status["date_out"])
else:
book["status"] = "On shelf"
self.caption = "Viewing Book " + str(book["id"])
super().__init__(window, helpbar, book, width)
class CategoryForm(FormWindow): class CategoryForm(FormWindow):
caption = "Add a Category" caption = "Add a Category"
blabel = "Add" blabel = "Add"
@ -316,21 +341,13 @@ class CategoryForm(FormWindow):
def _return_values(self): def _return_values(self):
return self.entries[0].value return self.entries[0].value
class DummyTextEntry(TextEntry):
def redraw(self): pass
class ErrorForm(FormWindow): class ErrorForm(FormWindow):
caption = "Error" caption = "Error"
blabel = "OK" blabel = "OK"
buttononly = True
def __init__(self,window,helpbar,errortext,width=50): def __init__(self,window,helpbar,errortext,width=50):
self.labels = errortext.split("\n") self.labels = errortext.split("\n")
super().__init__(window, helpbar, width=width) super().__init__(window, helpbar, width=width)
self.bt = 1
def _make_entries(self):
self.entries = []
for e in range(len(self.labels)):
self.entries.append(DummyTextEntry(self.w))
def redraw(self): def redraw(self):
self.w.box() self.w.box()
@ -339,7 +356,6 @@ class ErrorForm(FormWindow):
for l in self.labels: for l in self.labels:
c = 2 c = 2
self.w.addstr(r+self.top,c,l) self.w.addstr(r+self.top,c,l)
self.entries[r].redraw()
r+=1 r+=1
self.w.addstr(self.brow,self.bcol[1], "<"+self.blabel+">") self.w.addstr(self.brow,self.bcol[1], "<"+self.blabel+">")
self.w.chgat(self.brow, self.bcol[1], len(self.blabel)+2, curses.A_REVERSE) self.w.chgat(self.brow, self.bcol[1], len(self.blabel)+2, curses.A_REVERSE)