def update_item(self, target, person_id, name, address, contact_email, contact_tel_num): i = [] tar = person_id if (target == 'person_id') \ else name if (target == 'name') \ else address if (target == 'address') \ else contact_email if (target == 'contact_email') \ else contact_tel_num if (target == 'contact_tel_num') \ else None if tar is not None: j = 0 for row in self.items: if len(row) != 0: if row[target] == tar: i.append(j) j += 1 if i: for idx in i: self.items[idx] = Person().\ generator(list([person_id, name, address, contact_email, contact_tel_num])) self.db.update_table( self.table_name, f"person_id={self.items[idx]['person_id']}, " f"name='{self.items[idx]['name']}', " f"address='{self.items[idx]['address']}', " f"contact_email='{self.items[idx]['contact_email']}', " f"contact_tel_num='{self.items[idx]['contact_tel_num']}', ", target + "=" + str(tar)) # print(self.items) else: raise mvc_exc.ItemNotStored( 'Can\'t update "{}" because it\'s not stored'.format(tar))
def update_item(self, target, departament_id, name, country): i = [] tar = departament_id if (target == 'departament_id') \ else name if (target == 'name') \ else country if (target == 'country') \ else None if tar is not None: j = 0 for row in self.items: if len(row) != 0: if row[target] == tar: i.append(j) j += 1 if i: for idx in i: self.items[idx] = Departament().generator( list([departament_id, name, country])) self.db.update_table( self.table_name, f"departament_id={self.items[idx]['departament_id']}, " f"name='{self.items[idx]['name']}', " f"country='{self.items[idx]['country']}' ", target + "=" + str(tar)) # print(self.items) else: raise mvc_exc.ItemNotStored( 'Can\'t update "{}" because it\'s not stored'.format(tar))
def update_item(self, target, order_id, quantity, date, person_id): i = [] tar = order_id if (target == 'order_id') \ else quantity if (target == 'quantity') \ else date if (target == 'date') \ else person_id if (target == 'person_id') \ else None if tar is not None: j = 0 for row in self.items: if len(row) != 0: if row[target] == tar: i.append(j) j += 1 if i: for idx in i: self.items[idx] = Order().\ generator(list([order_id, quantity, date, person_id])) self.db.update_table( self.table_name, f"order_id={self.items[idx]['order_id']}, " f"quantity={self.items[idx]['quantity']}, " f"date='{self.items[idx]['date']}', " f"person_id={self.items[idx]['person_id']} ", target + "=" + str(tar)) # print(self.items) else: raise mvc_exc.ItemNotStored( 'Can\'t update "{}" because it\'s not stored'.format(tar))
def update_item(self, target, type_id, spoil_quick, type_name): i = [] tar = type_id if (target == 'type_id') \ else spoil_quick if (target == 'spoil_quick') \ else type_name if (target == 'type_name') \ else None if tar is not None: j = 0 for row in self.items: if len(row) != 0: if row[target] == tar: i.append(j) j += 1 if i: for idx in i: self.items[idx] = Type().\ generator(list([type_id, spoil_quick, type_name])) self.db.update_table( self.table_name, f"type_id={self.items[idx]['type_id']}, " f"spoil_quick={self.items[idx]['spoil_quick']}, " f"type_name='{self.items[idx]['type_name']}', ", target + "=" + str(tar)) # print(self.items) else: raise mvc_exc.ItemNotStored( 'Can\'t update "{}" because it\'s not stored'.format(tar))
def del_row_in_table(self, table_name, cond): # self.print_table_db(table_name) # print(self.print_atr_type_and_return(table_name)) try: self.__cur.execute(f"DELETE FROM {table_name} " f"WHERE {cond}") self.__connection.commit() except psycopg2.errors.lookup("23503"): raise ex_mvc.ItemHaveForeign()
def read_item(self, column, data): myitems = [] for row in self.items: if len(row) != 0: if row[column] == data: myitems.append(row[column]) if myitems: return myitems[0] else: raise mvc_exc.ItemNotStored( 'Can\'t read "{}" because it\'s not stored'.format(data))
def create_item(self, type_id, spoil_quick, type_name): results = [] for row in self.items: if len(row) != 0: if row['type_id'] == type_id: results.append(row['type_id']) if results: raise mvc_exc.ItemAlreadyStored( '"{}" already stored!'.format(type_id)) else: results = Type().generator(list([type_id, spoil_quick, type_name])) self.items.append(results) self.db.execute_query( f"INSERT INTO {self.table_name} " f" (type_id, spoil_quick, type_name) " f"VALUES ({results['type_id']}, {results['spoil_quick']}, " f"'{(results['type_name'])}');")
def create_item(self, departament_id, name, country): results = [] for row in self.items: if len(row) != 0: if row['departament_id'] == departament_id: results.append(row['departament_id']) if results: raise mvc_exc.ItemAlreadyStored( '"{}" already stored!'.format(name)) else: results = Departament().generator( list([departament_id, name, country])) self.items.append(results) self.db.execute_query( f"INSERT INTO {self.table_name} " f" (departament_id, name, country) " f"VALUES ({results['departament_id']}, '{results['name']}', " f"'{(results['country'])}');")
def create_item(self, order_id, quantity, date, person_id): results = [] for row in self.items: if len(row) != 0: if row['order_id'] == order_id: results.append(row['order_id']) if results: raise mvc_exc.ItemAlreadyStored( '"{}" already stored!'.format(order_id)) else: results = Order().generator( list([order_id, quantity, date, person_id])) self.items.append(results) self.db.execute_query( f"INSERT INTO {self.table_name} " f" (order_id, quantity, date, person_id) " f"VALUES ({results['order_id']}, {results['quantity']}, " f"'{(results['date'])}', {results['person_id']});")
def delete_item(self, column, val): idxs_items = [] for row in self.items: if len(row) != 0: if row[column] == val: idxs_items.append(row[column]) break if idxs_items: idxs_items = [] for row in self.items: if len(row) != 0: if row[column] != val: idxs_items.append(row) del self.items self.items = idxs_items self.db.del_row_in_table(self.table_name, str(column) + "=" + str(val)) else: raise mvc_exc.ItemNotStored( 'Can\'t delete "{}" because it\'s not stored'.format(val))
def update_item(self, target, thing_id, quantity, expiration_date, breakable, type_id, order_id, name): i = [] tar = thing_id if (target == 'thing_id') \ else quantity if (target == 'quantity') \ else expiration_date if (target == 'expiration_date') \ else breakable if (target == 'breakable') \ else type_id if (target == 'type_id') \ else order_id if (target == 'order_id') \ else name if (target == 'name')\ else None if tar is not None: j = 0 for row in self.items: if len(row) != 0: if row[target] == tar: i.append(j) j += 1 if i: for idx in i: self.items[idx] = Thing().generator( list([ thing_id, quantity, expiration_date, breakable, type_id, order_id, name ])) self.db.update_table( self.table_name, f"thing_id={self.items[idx]['thing_id']}, " f"quantity={self.items[idx]['quantity']}, " f"expiration_date='{self.items[idx]['expiration_date']}', " f"breakable={self.items[idx]['breakable']}, " f"type_id={self.items[idx]['type_id']}, " f"order_id={self.items[idx]['order_id']}, " f"name='{self.items[idx]['name']}'", target + "=" + str(tar)) # print(self.items) else: raise mvc_exc.ItemNotStored( 'Can\'t update "{}" because it\'s not stored'.format(tar))
def create_item(self, person_id, name, address, contact_email, contact_tel_num): results = [] for row in self.items: if len(row) != 0: if row['person_id'] == person_id: results.append(row['person_id']) if results: raise mvc_exc.ItemAlreadyStored( '"{}" already stored!'.format(person_id)) else: results = Person().generator( list( [person_id, name, address, contact_email, contact_tel_num])) self.items.append(results) self.db.execute_query( f"INSERT INTO {self.table_name} " f" (person_id, name, address, contact_email, contact_tel_num) " f"VALUES ({results['person_id']}, '{results['name']}', " f"'{(results['address'])}', '{results['contact_email']}'," f"'{results['contact_tel_num']}');")
def create_item(self, thing_id, quantity, expiration_date, breakable, type_id, order_id, name): results = [] for row in self.items: if len(row) != 0: if row['thing_id'] == thing_id: results.append(row['thing_id']) if results: raise mvc_exc.ItemAlreadyStored( '"{}" already stored!'.format(name)) else: results = Thing().generator( list([ thing_id, quantity, expiration_date, breakable, type_id, order_id, name ])) self.items.append(results) self.db.execute_query( f"INSERT INTO {self.table_name} " f" (thing_id, quantity, expiration_date, breakable, type_id, order_id, name) " f"VALUES ({results['thing_id']}, {results['quantity']}, " f"'{(results['expiration_date'])}', {results['breakable']}, " f"{results['type_id']}, {results['order_id']}, " f"'{results['name']}');")