can now add categories from the category viewer

This commit is contained in:
John Ladan 2012-03-24 21:30:41 -04:00
parent a3018cb7a6
commit 24511bb11c
4 changed files with 45 additions and 3 deletions

View File

@ -1,6 +1,7 @@
import sys
import curses
import dbLayer as db
from form import bookForm
from form import bookForm,categoryForm
class browserWindow:
hl=0
@ -175,7 +176,22 @@ class categoryBrowser(browserWindow):
cats = db.getCategories()
for c in cats:
self.entries.append({'category':c})
self.sortByColumn('category')
def addCategory(self):
w = curses.newwin(1,1,10,10)
cf = categoryForm(w)
cats = cf.eventLoop()
print >> sys.stderr, cats
for c in cats:
print >> sys.stderr, "adding "+str(c)
db.addCategory(c)
cf.clear()
def handleInput(self,ch):
browserWindow.handleInput(self,ch)
if ch==97:
self.addCategory()
self.refreshCategories()
self.refresh()

View File

@ -1,3 +1,4 @@
import sys
import sqlite3
dbFile = 'sqLibrary.db'
@ -181,6 +182,21 @@ def deleteBook(bookid):
#########################################
# Category related functions
########################################
def categorizeBook(bookid, category):
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)+");"
conn.commit()
c.close()
def getCategories():
conn = sqlite3.connect(dbFile)
c = conn.cursor()
@ -196,7 +212,9 @@ def addCategory(cat):
conn = sqlite3.connect(dbFile)
c = conn.cursor()
query = "INSERT OR IGNORE INTO "+categoryTable+" (category) VALUES ("+stringify(cat)+");"
c.execte(query)
print >>sys.stderr, query
c.execute(query)
conn.commit()
c.close()
#########################################

View File

@ -209,3 +209,11 @@ class bookForm(formWindow):
self.updateEntries(book)
self.refresh()
formWindow.handleInput(self,ch)
class categoryForm(formWindow):
caption = "Add a Category"
blabel = "Add"
labels = ["Category"]
def returnValues(self):
return self.entries

View File

@ -83,9 +83,9 @@ def redrawMenu(w,items,highlight):
def addForm():
w=curses.newwin(1,1)
(my,mx)=stdscr.getmaxyx()
bf = form.bookForm(w)
(r,c)=w.getmaxyx()
w.mvwin((my-r)/2,(mx-c)/2)
bf = form.bookForm(w)
bf.lookup=bookData.openLibrary
bf.caption='Add a Book'
bf.blabel = 'Add'