Ejemplo n.º 1
0
 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))
Ejemplo n.º 2
0
 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))
Ejemplo n.º 3
0
 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))
Ejemplo n.º 4
0
 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))
Ejemplo n.º 5
0
 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))
Ejemplo n.º 6
0
 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))
Ejemplo n.º 7
0
 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))