deletion of categories now supported
parent
ee94be5589
commit
b079405d33
19
browser.py
19
browser.py
|
@ -197,16 +197,31 @@ class categoryBrowser(browserWindow):
|
|||
w = curses.newwin(1,1,10,10)
|
||||
cf = categoryForm(w,self.hb)
|
||||
cats = cf.eventLoop()
|
||||
print >> sys.stderr, cats
|
||||
for c in cats:
|
||||
print >> sys.stderr, "adding "+str(c)
|
||||
db.addCategory(c)
|
||||
cf.clear()
|
||||
|
||||
def delSelected(self):
|
||||
categories = []
|
||||
for sel,cat in zip(self.selected, self.entries):
|
||||
if sel:
|
||||
categories.append(cat)
|
||||
db.deleteCategories(categories)
|
||||
|
||||
def handleInput(self,ch):
|
||||
browserWindow.handleInput(self,ch)
|
||||
if ch==97:
|
||||
self.addCategory()
|
||||
self.refreshCategories()
|
||||
self.refresh()
|
||||
if ch==100:
|
||||
count=0
|
||||
for s in self.selected[0:self.hl-1]:
|
||||
if s:
|
||||
count+=1
|
||||
self.delSelected()
|
||||
self.refreshCategories()
|
||||
self.refresh()
|
||||
self.scroll(-count)
|
||||
self.mvHighlight(-count)
|
||||
|
||||
|
|
12
dbLayer.py
12
dbLayer.py
|
@ -224,11 +224,21 @@ def addCategory(cat):
|
|||
conn = sqlite3.connect(dbFile)
|
||||
c = conn.cursor()
|
||||
query = "INSERT OR IGNORE INTO "+categoryTable+" (category) VALUES ("+stringify(cat)+");"
|
||||
print >>sys.stderr, query
|
||||
c.execute(query)
|
||||
conn.commit()
|
||||
c.close()
|
||||
|
||||
def deleteCategories(cats):
|
||||
conn = sqlite3.connect(dbFile)
|
||||
c = conn.cursor()
|
||||
query1 = "DELETE FROM " +categoryTable+ " WHERE cat_id = :id;"
|
||||
query2 = "DELETE FROM " +bookCategoryTable+ " WHERE cat_id = :id;"
|
||||
for cat in cats:
|
||||
c.execute(query1, cat)
|
||||
c.execute(query2, cat)
|
||||
conn.commit()
|
||||
c.close()
|
||||
|
||||
#########################################
|
||||
# Database initialization
|
||||
#########################################
|
||||
|
|
Loading…
Reference in New Issue