updating from browser works now
authorJohn Ladan <jladan@uwaterloo.ca>
Tue, 20 Mar 2012 19:27:34 +0000 (15:27 -0400)
committerJohn Ladan <jladan@uwaterloo.ca>
Tue, 20 Mar 2012 19:27:34 +0000 (15:27 -0400)
bookData.py
bookForm.py
browser.py
dbLayer.py

index 8e10054..8fbe953 100644 (file)
@@ -17,7 +17,7 @@ Keys:
     publish date - string of date (to make things easier to code/catalogue (won't be stored)
     publish year - int (this kind of thing will have to be confirmed by cataloguer)
     publish month - int
-    publish locations - like publishers
+    publish location - like publisher
     
     pages - integer - just the number of pages
     pagination - string eg. "xviii, 1327-1850"
@@ -48,10 +48,10 @@ def openLibrary(ISBN):
             book["publisher"] += "; " + v['name']
         book['publisher'] = book['publisher'][2:]
     if "publish_places" in openBook:
-        book["publish locations"]=""
+        book["publish location"]=""
         for v in openBook["publish_places"]:
-            book["publish locations"] += "; " + v['name']
-        book['publish locations'] = book['publish locations'][2:]
+            book["publish location"] += "; " + v['name']
+        book['publish location'] = book['publish location'][2:]
 
     # for lccn, there maybe be multiple values in the query. I'm just taking the first, but the full list may be useful
     if "lccn" in openBook['identifiers']:
index 78f3800..8ca5c81 100644 (file)
@@ -67,7 +67,7 @@ class bookForm:
     def highlight(self):
         if self.bt == -1:
             self.w.chgat(self.row, self.left, self.width, curses.A_UNDERLINE)
-            self.w.move(self.row, self.left+self.cursor)
+            self.mvCursor(0)
             curses.curs_set(1)
         else:
             self.w.chgat(self.row, self.bcol[self.bt], self.bwidth[self.bt], curses.A_REVERSE)
@@ -105,15 +105,15 @@ class bookForm:
         c = self.cursor
         self.entries[self.hl]=self.entries[self.hl][:c] +ch+  self.entries[self.hl][c:]
         self.drawRow(self.hl)
-        self.highlight()
         self.mvCursor(+1)
+        self.highlight()
 
     def backspace(self):
         if self.cursor>0:
             self.entries[self.hl]=self.entries[self.hl][:self.cursor-1] + self.entries[self.hl][self.cursor:]
             self.drawRow(self.hl)
-            self.highlight()
             self.mvCursor(-1)
+            self.highlight()
 
     def delete(self):
         c = self.cursor
index c2ded7e..e76c129 100644 (file)
@@ -1,5 +1,6 @@
 import curses
 import dbLayer as db
+from bookForm import bookForm
 
 class browserWindow:
     hl=0
@@ -11,6 +12,20 @@ class browserWindow:
                ('ISBN',13)]
     mx = my = 0
 
+    # redefinable functions
+    def updateSelection(self,book):
+        bookid = book['id']
+        
+        w=curses.newwin(1,1,20,20)
+        bf=bookForm(w)
+        bf.caption='Update Book '+str(bookid)
+        bf.blabel='update'
+        bf.updateEntries(book)
+        newbook = bf.eventLoop()
+        if len(newbook)!=0:
+            db.updateBook(newbook,bookid)
+
+
     def __init__(self,window):
         self.w = window
         self.updateGeometry()
@@ -97,6 +112,12 @@ class browserWindow:
             elif ch == curses.KEY_NPAGE:
                 self.scroll(+self.pageSize)
                 self.mvHighlight(+self.pageSize)
+            
+            elif ch == 117:
+                book = self.books[self.hl]
+                self.updateSelection(book)
+                self.books[self.hl]=db.getBookByID(book['id'])
+                self.refresh()
 
             self.w.refresh()
             ch = self.w.getch()
index bc633a3..7b523ae 100644 (file)
@@ -73,14 +73,10 @@ def addBook(book):
 def updateBook(book, bookID):
     conn = sqlite3.connect(dbFile)
     c = conn.cursor()
-    cols = []
-    vals = []
+    updates=[]
     for k,v in book.items():
-        if v!="":
-            cols.append(colify(k))
-            vals.append(stringify(v))
-    
-    query = "UPDATE "+bookTable+" ("+", ".join(cols)+") VALUES ("+", ".join(vals)+") WHERE id = " +bookID+";"
+        updates.append(colify(k)+"="+stringify(v))
+    query = "UPDATE "+bookTable+" SET " +  ", ".join(updates)+" WHERE id = " +str(bookID)+";"
     c.execute(query)
     conn.commit()
     c.close()
@@ -102,10 +98,26 @@ def getBooks():
     c.close()
     return books
 
-def removeBook():
+def getBookByID(bookid):
+    conn = sqlite3.connect(dbFile)
+    c = conn.cursor()
+    query = "SELECT * FROM "+bookTable+" WHERE id = "+str(bookid)+";"
+    c.execute(query)
+    b = c.fetchone()
+    book = {}
+    i=0
+    for k in columns:
+        if b[i]!=None:
+            book[k]=b[i]
+        i+=1
+    c.close()
+    return book
+
+
+def removeBook(bookid):
     conn = sqlite3.connect(dbFile)
     c = conn.cursor()
-    query = "DELETE FROM " +bookTable+ " WHERE id = "+str(id)+";"
+    query = "DELETE FROM " +bookTable+ " WHERE id = "+str(bookid)+";"
     c.execute(query)
     conn.commit()
     c.close()