def populatenames(self): ''' Populates the attendance treeview. ''' datalist = DatabaseQueryClass.queryattendanceall( self.database, self.meetingid) # Inserts the attendance entry into the treeview. for i in datalist: senatorname = DatabaseQueryClass.querysenatorname( self.database, i[2]) id = self.treeview.insert('', 'end', values=tuple([senatorname[0]] + [i[1]])) self.data[id] = list(i) try: self.treeview.selection_set(id) self.treeview.focus(id) except: return
def __init__(self, connection, database, treeview, data={}): ''' Constructor ''' # Database connection. self.connection = connection # Database variable self.database = database # Dictionary that stores table data for operations on the treeview and the # database. Its keys are set to the same one generated by the treeview for # easy access. self.data = data # The treeview attached to the GUI. self.treeview = treeview datalist = DatabaseQueryClass.querysenatorall(self.database) # Initially fills dictionary and treeview upon creation. for i in datalist: id = self.treeview.insert('', 'end', values=i[1:5]) self.data[id] = list(i) try: self.treeview.selection_set(id) self.treeview.focus(id) except: return
def querysenator(self): ''' Queries selected senator entry. Queries senator table. ''' id = self.treeview.selection() id = id[0] itemlist = self.data[id] list = DatabaseQueryClass.querysenator(self.database, itemlist[0]) return list
def querymeeting(self): ''' Queries selected meeting entry. Queries meeting table. ''' id = self.treeview.selection() id = id[0] itemlist = self.data[id] list = DatabaseQueryClass.querymeeting(self.database, itemlist[0]) return list
def queryclub(self): ''' Queries selected budget entry. Queries club and club info table. ''' id = self.treeview.selection() id = id[0] itemlist = self.data[id] list = DatabaseQueryClass.queryclub(self.database, itemlist[0]) return list
def newbudget(self, itemlist): ''' Adds a new budget entry in the database, treeview and dictionary. Inserts into the budget table. ''' inputlist = DatabaseInsertClass().insertbudget(self.database, self.connection, itemlist) # Queries budgets the club name. list = DatabaseQueryClass.querybudget(self.database, inputlist[4]) id = self.treeview.insert('', 'end', values = tuple(list)) self.data[id] = inputlist
def querybudget(self): ''' Queries selected budget entry. Queries budget table. ''' id = self.treeview.selection() id = id[0] itemlist = self.data[id] list = DatabaseQueryClass.querybudget(self.database, itemlist[4]) return list
def editbudget(self, itemlist): ''' Edits selected budget entry in the database, treeview and dictionary. Edits the budget table. ''' id = self.treeview.selection() id = str(id[0]) templist = self.data[id] inputlist = DatabaseUpdateClass().updatebudget(self.database, self.connection, itemlist, templist[0]) # Queries updated budget to get the potential changed club. list = DatabaseQueryClass.querybudget(self.database, inputlist[4]) self.treeview.item(id, values = tuple([list[0]] + inputlist[1:4])) self.data[id] = inputlist
def editattendance(self, status): ''' Edits selected attendance entry in the database, treeview and dictionary. Edits the attendance table. ''' id = self.treeview.selection() id = str(id[0]) oldlist = self.data[id] oldlist[1] = status senatorname = DatabaseQueryClass.querysenatorname( self.database, oldlist[2]) newlist = DatabaseUpdateClass().updateattendance( self.database, self.connection, oldlist[1:4], oldlist[0]) self.treeview.item(id, values=tuple([senatorname[0]] + [newlist[1]])) self.data[id] = newlist
def newsenator(self, itemlist): ''' Adds a new senator entry in the database, treeview and dictionary. Inserts in the senator table. Creates attendance tables for all meetings in relation to this senator. ''' inputlist = DatabaseInsertClass().insertsenator( self.database, self.connection, itemlist) id = self.treeview.insert('', 'end', values=tuple(inputlist[1:5])) list = DatabaseQueryClass.querymeetingidall(self.database) # Creates attendance tables for all meetings in relation to this senator. for i in list: attendancelist = [inputlist[0]] + [i[0]] DatabaseInsertClass().insertattendance(self.database, self.connection, attendancelist) self.data[id] = inputlist