2 # -*- coding: utf-8 -*-
10 class Liststorehandler():
12 def get_unitsstore(self):
13 if (self.unitsstore==None):
14 self.unitsstore=gtk.ListStore(str, str, str,str,str, str,str, str, str,str, str, str,str)
15 self.unitsstore.clear()
19 self.unitsstore.append(["-1","-1","","","","","","","","","","",""])
20 self.unitsstore.append(["-1","-1","","1","g","","0","","","","","",""])
21 self.unitsstore.append(["-1","-1","","2","kg","","1","","","","","",""])
22 self.unitsstore.append(["-1","-1","","3","liter","","2","","","","","",""])
23 self.unitsstore.append(["-1","-1","","4","packs","","3","","","","","",""])
24 self.unitsstore.append(["-1","-1","","5","","","4","","","","","",""])
25 self.unitsstore.append(["-1","-1","","6","","","5","","","","","",""])
26 self.unitsstore.append(["-1","-1","","7","","","6","","","","","",""])
27 self.unitsstore.append(["-1","-1","","8","","","7","","","","","",""])
28 self.unitsstore.append(["-1","-1","","9","","","8","","","","","",""])
29 self.unitsstore.append(["-1","-1","","","","","9","","","","","",""])
31 return self.unitsstore
36 def get_liststore(self,titlesearch=""):
37 if (self.liststore==None):
38 self.liststore=gtk.ListStore(str, str, str,str,str, str,str, str, str,str, str, str,str)
39 self.liststore.clear()
41 titlesearch=titlesearch+"%"
44 if (self.selection.get_status()=="0"): #only 0 and 1 (active items)
45 sql="SELECT uid,status,title,quantitiy,unit,price,priority,date,private,stores,note,custom1,custom2 FROM items WHERE list=? AND category LIKE ? AND status>=? AND title like ? ORDER BY category, status, title"
46 rows=self.db.ladeSQL(sql,(self.selection.get_list(),self.selection.get_category(True),self.selection.get_status(),titlesearch))
48 sql="SELECT uid,status,title,quantitiy,unit,price,priority,date,private,stores,note,custom1,custom2 FROM items WHERE list=? AND category LIKE ? AND title LIKE ? ORDER BY category, title ASC"
49 rows=self.db.ladeSQL(sql,(self.selection.get_list(),self.selection.get_category(True),titlesearch))
52 if ((rows!=None)and(len(rows)>0)):
54 uid,status,title,quantitiy,unit,price,priority,date,private,stores,note,custom1,custom2 = row
58 self.liststore.append([uid,status,title,quantitiy,unit,price,priority,date,private,stores,note,custom1,custom2])
60 #self.liststore.append(["-1","-1",""," ","","","","","","","","",""])
62 #self.liststore.append(["-1","-1","","","","","","","","","","",""])
67 def emptyValueExists(self):
68 for child in self.liststore:
75 def update_row(self,irow,icol,new_text):
77 #for x in self.liststore:
80 if (irow>-1)and(self.liststore[irow][0]!="-1")and(self.liststore[irow][0]!=None):
81 sql = "UPDATE items SET "+self.collist[icol]+"=? WHERE uid=?"
82 self.db.speichereSQL(sql,(new_text,self.liststore[irow][0]),rowid=self.liststore[irow][0])
84 logging.info("Updated row: "+self.collist[icol]+" new text "+new_text+" Titel: "+str(self.liststore[irow][2])+" with uid "+str(self.liststore[irow][0]))
86 self.liststore[irow][icol]=new_text
88 logging.warning("update_row: row does not exist")
90 #if (self.emptyValueExists()==True)and(icol<2):
91 # #print "letzter Eintrag ohne inhalt"
95 #for x in self.liststore:
99 def checkout_rows(self):
100 sql = "UPDATE items SET status=? WHERE list=? AND category=?"
101 self.db.speichereSQL(sql,("-1",self.selection.get_list(),self.selection.get_category()))
102 for i in range(len(self.liststore)):
103 self.liststore[i][1]="-1"
109 #self.update_row(-1,1,"-1")
110 #for x in self.liststore:
112 status=self.selection.get_status()
114 uid=str(uuid.uuid4())
115 sql = "INSERT INTO items (uid,list,category,status, title) VALUES (?,?,?,?,?)"
116 self.db.speichereSQL(sql,(uid,self.selection.get_list(),self.selection.get_category(),status,""),rowid=uid)
117 logging.info("Insertet row: status = "+status+" with uid "+str(uid))
118 #self.liststore[irow][0]=str(uuid.uuid4())
120 self.liststore.append([uid,status,""," ","","","","","","","","",""])
121 self.selection.comboLists_check_for_update()
123 # self.liststore[irow][icol]=new_text
124 # self.liststore[irow][0]=uid
126 # self.liststore.append([uid,"-1",""," ","","","","","","","","",""])
127 #print "xy",self.liststore[len(self.liststore)-1][0]
128 #Check if a new list/category is opened
129 # self.selection.comboLists_check_for_update()
131 def del_row(self,irow,row_iter):
132 uid=self.liststore[irow][0]
133 self.liststore.remove(row_iter)
134 sql = "DELETE FROM items WHERE uid=?"
135 self.db.speichereSQL(sql,(uid,))
139 def get_colname(self,i):
140 if i<len(self.collist):
141 return self.collist[i]
145 def get_colcount(self):
146 return len(self.collist)
149 def rename_category(self,new_name):
150 sql = "UPDATE items SET category=? WHERE list=? AND category=?"
151 self.db.speichereSQL(sql,(new_name,self.selection.get_list(),self.selection.get_category()))
152 self.selection.comboList_changed()
153 self.selection.set_category(new_name)
155 def rename_list(self,new_name):
156 sql = "UPDATE items SET list=? WHERE list=?"
157 self.db.speichereSQL(sql,(new_name,self.selection.get_list(),))
158 self.selection.load()
159 self.selection.set_list(new_name)
162 #def update_category(self,widget=None,data=None,data2=None,data3=None):
163 # self.get_liststore()
165 def update_list(self,widget=None,data=None,data2=None,data3=None):
168 def __init__(self,db,selection):
172 self.selection=selection
173 self.collist=("uid","status","title","quantitiy","unit","price","priority","date","private","stores","note","custom1","custom2")
175 #sql="DROP TABLE items"
176 #self.db.speichereSQL(sql)
178 sql = "CREATE TABLE items (uid TEXT, list TEXT, category TEXT, status TEXT, title TEXT, quantitiy TEXT, unit TEXT, price TEXT, priority TEXT, date TEXT, pcdate TEXT, private TEXT, stores TEXT, note TEXT, custom1 TEXT, custom2 TEXT)"
179 self.db.speichereSQL(sql)
182 self.selection.load()
183 self.selection.connect("changed",self.update_list)
184 #self.selection.connect("changedCategory",self.update_category)
188 sql = "INSERT INTO items (uid,list,category,title) VALUES (?,?,?,?)"
190 self.db.speichereSQL(sql,(str(uuid.uuid4()),"default","default","atitel1"))
191 self.db.speichereSQL(sql,(str(uuid.uuid4()),"default","default","btitel2"))
192 self.db.speichereSQL(sql,(str(uuid.uuid4()),"default","default","ctitel3"))