can now browse books by category
authorJohn Ladan <jladan@uwaterloo.ca>
Sun, 1 Apr 2012 17:45:51 +0000 (13:45 -0400)
committerJohn Ladan <jladan@uwaterloo.ca>
Sun, 1 Apr 2012 17:45:51 +0000 (13:45 -0400)
browser.py
dbLayer.py

index ab6d6fa..fec2a62 100644 (file)
@@ -347,6 +347,10 @@ class bookBrowser(browserWindow):
         self.entries = db.getBooks()
         self.selected = map(lambda x:False, self.entries)
 
+    def refreshBooksInCategory(self,cat):
+        self.entries = db.getBooksByCategory(cat)
+        self.selected = map(lambda x:False, self.entries)
+
     def handleInput(self,ch):
         browserWindow.handleInput(self,ch)
         if ch == 117: #update on 'u'
@@ -393,6 +397,14 @@ class categoryBrowser(browserWindow):
             db.addCategory(c)
         cf.clear()
 
+    def viewCategory(self):
+        w = curses.newwin(20,80,20,20)
+        b = bookBrowser(w,self.hb)
+        self.centreChild(w)
+        b.refreshBooksInCategory(self.entries[self.hl])
+        b.eventLoop()
+        b.clear()
+
     def delSelected(self):
         categories = []
         for sel,cat in zip(self.selected, self.entries):
@@ -406,6 +418,9 @@ class categoryBrowser(browserWindow):
             self.addCategory()
             self.refreshCategories()
             self.refresh()
+        if ch ==10:
+            self.viewCategory()
+            self.refresh()
         if ch==100:
             count=0
             for s in self.selected[0:self.hl-1]:
index 250b3bd..3f7f252 100644 (file)
@@ -145,7 +145,7 @@ def getBooks():
 def getBooksByCategory(cat):
     conn = sqlite3.connect(dbFile)
     c = conn.cursor()
-    query = "SELECT "+",".join(mapt(colify,columns))+" FROM "+bookTable+" JOIN "+bookCategoryTable+" USING (id) WHERE cat_id = :id;"
+    query = "SELECT "+",".join(map(colify,columns))+" FROM "+bookTable+" JOIN "+bookCategoryTable+" USING (id) WHERE cat_id = :id;"
     c.execute(query,cat)
     books = []
     for b in c: