books restored from trash, but there's an error when everything is restored
authorJohn Ladan <jladan@uwaterloo.ca>
Sat, 31 Mar 2012 00:41:00 +0000 (20:41 -0400)
committerJohn Ladan <jladan@uwaterloo.ca>
Sat, 31 Mar 2012 00:41:00 +0000 (20:41 -0400)
browser.py
dbLayer.py

index 5f01240..5ee26e0 100644 (file)
@@ -248,6 +248,13 @@ class trashBrowser(browserWindow):
         bf.eventLoop()
         bf.clear()
 
+    def restoreSelected(self):
+        books = []
+        for sel,book in zip(self.selected, self.entries):
+            if sel:
+                books.append(book)
+        db.restoreBooks(books)
+
     def delSelected(self):
         books = []
         for sel,book in zip(self.selected, self.entries):
@@ -265,7 +272,17 @@ class trashBrowser(browserWindow):
             book = self.entries[self.hl]
             self.viewSelection(book)
             self.refresh()
-        if ch==100:
+        if ch==114: #restore books
+            count=0
+            for s in self.selected[0:self.hl-1]:
+                if s:
+                    count+=1
+            self.restoreSelected()
+            self.refreshBooks()
+            self.refresh()
+            self.scroll(-count)
+            self.mvHighlight(-count)
+        if ch==100: # delete books
             count=0
             for s in self.selected[0:self.hl-1]:
                 if s:
index e0e1040..5587984 100644 (file)
@@ -126,7 +126,7 @@ def getBooks():
 def getBooksByCategory(cat):
     conn = sqlite3.connect(dbFile)
     c = conn.cursor()
-    query = "SELECT "+",".join(columns)+" FROM "+bookTable+" JOIN "+bookCategoryTable+" USING (id) WHERE cat_id = :id;"
+    query = "SELECT "+",".join(mapt(colify,columns))+" FROM "+bookTable+" JOIN "+bookCategoryTable+" USING (id) WHERE cat_id = :id;"
     c.execute(query,cat)
     books = []
     for b in c:
@@ -195,6 +195,18 @@ def removeBooks(books):
     conn.commit()
     c.close()
 
+# restores trashed books
+def restoreBooks(books):
+    conn = sqlite3.connect(dbFile)
+    c = conn.cursor()
+    query1 =  "INSERT INTO "+bookTable+" ("+",".join(map(colify,columns[1:]))+") SELECT "+",".join(map(colify,columns[1:]))+" FROM "+bookRemovedTable+" WHERE id = :id;"
+    query2 = "DELETE FROM " +bookRemovedTable+ " WHERE id = :id;"
+    for book in books:
+        c.execute(query1,book)
+        c.execute(query2,book)
+    conn.commit()
+    c.close()
+
 # fully deletes book from removedBooks table
 def deleteBook(bookid):
     conn = sqlite3.connect(dbFile)