Made it possible to view uncategorized books
authorFelix Bauckholt <felixbauckholt@gmail.com>
Sun, 31 Jan 2016 02:03:45 +0000 (21:03 -0500)
committerFelix Bauckholt <felixbauckholt@gmail.com>
Sat, 6 Feb 2016 21:13:27 +0000 (16:13 -0500)
Also "specialized" lists of books (categorized, on
shelf, checked out, uncategorized) don't revert to
the main book list when refreshing.

librarian
library/database.py
library/interface/browser.py

index 7758d45..5335954 100755 (executable)
--- a/librarian
+++ b/librarian
@@ -119,13 +119,23 @@ def trashMenu():
     b.eventLoop()
     b.clear()
 
+def uncategorizedMenu():
+    w=curses.newwin(3,5)
+    b = browser.bookBrowser(w,hb)
+    (r,c) = w.getmaxyx()
+    (my,mx)=stdscr.getmaxyx()
+    w.mvwin((my-r)//2 -2, (mx-c)//2)
+    b.refreshBooksUncategorized()
+    b.eventLoop()
+    b.clear()
+
 def checkedout_menu():
     w=curses.newwin(3,5)
     b = browser.bookBrowser(w,hb)
     (r,c) = w.getmaxyx()
     (my,mx)=stdscr.getmaxyx()
     w.mvwin((my-r)//2 -2, (mx-c)//2)
-    b.load_data(db.get_checkedout_books())
+    b.refreshBooksCheckedout()
     b.columnDefs = [("id",0,3),
                     ("uwid",0,8),
                     ("date",0,10),
@@ -140,19 +150,19 @@ def onshelf_menu():
     (r,c) = w.getmaxyx()
     (my,mx)=stdscr.getmaxyx()
     w.mvwin((my-r)//2 -2, (mx-c)//2)
-    b.load_data(db.get_onshelf_books())
+    b.refreshBooksOnshelf()
     b.eventLoop()
     b.clear()
 
 def co_menu():
     w=curses.newwin(1,1)
     (my,mx)=stdscr.getmaxyx()
-    co.checkout_procedure(w,hb,my//2,mx//2,mx) 
+    co.checkout_procedure(w,hb,my//2,mx//2,mx)
 
 def return_menu():
     w=curses.newwin(1,1)
     (my,mx)=stdscr.getmaxyx()
-    co.return_procedure(w,hb,my//2,mx//2,mx) 
+    co.return_procedure(w,hb,my//2,mx//2,mx)
 
 def catMenu():
     (my,mx)=stdscr.getmaxyx()
@@ -172,6 +182,7 @@ if __name__ == "__main__":
          ("Add Book", addForm),
          ("Categories", catMenu),
          ("View Trash", trashMenu),
+         ("View Uncategorized Books", uncategorizedMenu),
          ("",exit),
          ("Check Out a Book", co_menu),
          ("Return a Book", return_menu),
index b2e1d9b..a188390 100644 (file)
@@ -91,7 +91,7 @@ def addBook(book):
         if v!="":
             cols.append(_colify(k))
             vals.append(_stringify(v))
-    
+
     query = ("INSERT INTO "+_book_table+" ("+", ".join(cols)+") VALUES ("+
              ", ".join(vals)+");")
     c.execute(query)
@@ -148,6 +148,18 @@ def getRemovedBooks():
     c.close()
     return books
 
+def getUncategorizedBooks():
+    conn = sqlite3.connect(_catalogue_db_file)
+    c = conn.cursor()
+    query = ("SELECT "+",".join(map(_colify,columns))+" FROM "+_book_table+
+             " WHERE id NOT IN (SELECT id FROM "+_book_category_table+")"+
+             " AND deleted=0;")
+    c.execute(query)
+    books = [_query_to_book(b) for b in c]
+    c.close()
+    return books
+
+
 def get_book(bookid):
     conn = sqlite3.connect(_catalogue_db_file)
     c = conn.cursor()
index 2e521b4..7a610a8 100644 (file)
@@ -375,7 +375,20 @@ class bookBrowser(browserWindow):
         self.load_data(db.get_books())
 
     def refreshBooksInCategory(self,cat):
-        self.load_data(db.getBooksByCategory(cat))
+        self.refreshBooks = lambda : self.load_data(db.getBooksByCategory(cat))
+        self.refreshBooks()
+
+    def refreshBooksUncategorized(self):
+        self.refreshBooks = lambda : self.load_data(db.getUncategorizedBooks())
+        self.refreshBooks()
+
+    def refreshBooksCheckedout(self):
+        self.refreshBooks = lambda : self.load_data(db.get_checkedout_books())
+        self.refreshBooks()
+
+    def refreshBooksOnshelf(self):
+        self.refreshBooks = lambda : self.load_data(db.get_onshelf_books())
+        self.refreshBooks()
 
     def handleInput(self,ch):
         browserWindow.handleInput(self,ch)