def init(status): if not status: session = SqlHandler.newSession() SqlHandler.addItems(session,[SqlHandler.ALV(alv=24,alv_class=1), #Normal items SqlHandler.ALV(alv=10,alv_class=2), #Medicines SqlHandler.ALV(alv=14,alv_class=3)]) #Feed SqlHandler.addItems(session, [SqlHandler.GlobalVar(key="clinicpayment", value="20.00"), SqlHandler.GlobalVar(key="km_price", value="0.48")]) #create species koira = SqlHandler.Specie('Koira') kissa = SqlHandler.Specie('Kissa') hevonen = SqlHandler.Specie('Hevonen') #add species SqlHandler.addItems(session, [koira, kissa, hevonen]) item_list = [] dogs_file_name = "koirarodut.txt" cats_file_name = "kissarodut.txt" horse_file_name = "hevosrodut.txt" try: f = open(dogs_file_name, "r", encoding="utf-8") for race_name in f.readlines(): item_list.append(SqlHandler.Race(race_name.strip(),koira.id)) f.close() except IOError: print("Can not find file named: " + dogs_file_name) pass try: f = open(cats_file_name, "r", encoding="utf-8") for race_name in f.readlines(): item_list.append(SqlHandler.Race(race_name.strip(),kissa.id)) f.close() except IOError: print("Can not find file named: "+ cats_file_name) pass try: f = open(horse_file_name, "r", encoding="utf-8") for race_name in f.readlines(): item_list.append(SqlHandler.Race(race_name.strip(),hevonen.id)) f.close() except IOError: print("Can not find file named: "+ cats_file_name) pass SqlHandler.addItems(session,item_list) try: f = open('postinumerot.txt', "r", encoding="utf-8") raw_p_data = f.readlines() offices = [] offices_dict = {} for line in raw_p_data: if len(line) > 1: office = SqlHandler.PostOffice(line.split(' ')[0]) offices.append(office) offices_dict[line.split(' ')[0]] = office; SqlHandler.addItems(session,offices) numbers = [] for line in raw_p_data: if len(line) > 1: for item in line.split(' ')[1].strip().split(','): numbers.append(SqlHandler.PostNumber(offices_dict[line.split(' ')[0]].id, int(item))) SqlHandler.addItems(session,numbers) f.close() except IOError: print("Can not find file named: "+ cats_file_name) pass
def saveNewItem(self): SqlHandler.addItem(self.session, SqlHandler.PostOffice(self.ui.lineEdit.text())) #Will always be updated self.parent().setPostOffice(self.ui.lineEdit.text()) self.closeDialog()