deletion of categories now supported
This commit is contained in:
parent
ee94be5589
commit
b079405d33
19
browser.py
19
browser.py
|
@ -197,16 +197,31 @@ class categoryBrowser(browserWindow):
|
||||||
w = curses.newwin(1,1,10,10)
|
w = curses.newwin(1,1,10,10)
|
||||||
cf = categoryForm(w,self.hb)
|
cf = categoryForm(w,self.hb)
|
||||||
cats = cf.eventLoop()
|
cats = cf.eventLoop()
|
||||||
print >> sys.stderr, cats
|
|
||||||
for c in cats:
|
for c in cats:
|
||||||
print >> sys.stderr, "adding "+str(c)
|
|
||||||
db.addCategory(c)
|
db.addCategory(c)
|
||||||
cf.clear()
|
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):
|
def handleInput(self,ch):
|
||||||
browserWindow.handleInput(self,ch)
|
browserWindow.handleInput(self,ch)
|
||||||
if ch==97:
|
if ch==97:
|
||||||
self.addCategory()
|
self.addCategory()
|
||||||
self.refreshCategories()
|
self.refreshCategories()
|
||||||
self.refresh()
|
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)
|
conn = sqlite3.connect(dbFile)
|
||||||
c = conn.cursor()
|
c = conn.cursor()
|
||||||
query = "INSERT OR IGNORE INTO "+categoryTable+" (category) VALUES ("+stringify(cat)+");"
|
query = "INSERT OR IGNORE INTO "+categoryTable+" (category) VALUES ("+stringify(cat)+");"
|
||||||
print >>sys.stderr, query
|
|
||||||
c.execute(query)
|
c.execute(query)
|
||||||
conn.commit()
|
conn.commit()
|
||||||
c.close()
|
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
|
# Database initialization
|
||||||
#########################################
|
#########################################
|
||||||
|
|
Loading…
Reference in New Issue