updating from browser works now

This commit is contained in:
John Ladan 2012-03-20 15:27:34 -04:00
parent 770b4f553b
commit 263be64c75
4 changed files with 49 additions and 16 deletions

View 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']:

View 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

View 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()

View 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 = "DELETE FROM " +bookTable+ " WHERE id = "+str(id)+";"
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(bookid)+";"
c.execute(query)
conn.commit()
c.close()