made getCategories more like getBooks (need id as well)
authorJohn Ladan <jladan@uwaterloo.ca>
Tue, 27 Mar 2012 02:03:13 +0000 (22:03 -0400)
committerJohn Ladan <jladan@uwaterloo.ca>
Tue, 27 Mar 2012 02:03:13 +0000 (22:03 -0400)
browser.py
dbLayer.py

index 6076052..ae14b25 100644 (file)
@@ -183,10 +183,7 @@ class categoryBrowser(browserWindow):
 
 
     def refreshCategories(self):
-        self.entries = []
-        cats = db.getCategories()
-        for c in cats:
-            self.entries.append({'category':c})
+        self.entries = db.getCategories()
         self.sortByColumn('category')
         self.selected = map(lambda x:False, self.entries)
 
index 4be0f29..db1ca8e 100644 (file)
@@ -182,17 +182,10 @@ def deleteBook(bookid):
 #########################################
 # Category related functions
 ########################################
-def categorizeBook(bookid, category):
+def categorizeBook(bookid, cat_id):
     conn = sqlite3.connect(dbFile)
     c = conn.cursor()
-    if isinstance(category,str):
-        query = "INSERT OR IGNORE INTO "+categoryTable+" (category) VALUES ("+stringify(cat)+");"
-        conn.commit()
-        c.execute(query)
-        query = "SELECT cat_id FROM "+categoryTable+" WHERE category = "+stringify(category)+";"
-        c.execute(query)
-        category = c.fetchone()
-    query = "INSERT OR IGNORE INTO "+bookCategoryTable+" (id,cat_id) VALUES ("+str(bookid)+", "+str(category)+");"
+    query = "INSERT OR IGNORE INTO "+bookCategoryTable+" (id,cat_id) VALUES ("+str(bookid)+", "+str(cat_id)+");"
     conn.commit()
     c.close()
         
@@ -200,11 +193,11 @@ def categorizeBook(bookid, category):
 def getCategories():
     conn = sqlite3.connect(dbFile)
     c = conn.cursor()
-    query = "SELECT category FROM "+categoryTable+";"
+    query = "SELECT cat_id, category FROM "+categoryTable+";"
     c.execute(query)
     cats = []
-    for category in c:
-        cats.append(category[0])
+    for cat_id,cat in c:
+        cats.append({'id':cat_id, 'category':cat})
     c.close()
     return cats