Enhance luggage management: update new_part to accept pieces, add delete functionality, and log actions
This commit is contained in:
@@ -40,7 +40,7 @@ def new_part(cloth_type, weigth, pieces):
|
|||||||
logging.error("only ints allowed")
|
logging.error("only ints allowed")
|
||||||
else:
|
else:
|
||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
executed = "INSERT INTO luggage (clothes, weigth, pieces) VALUES (?, ?)"
|
executed = "INSERT INTO luggage (clothes, weigth, pieces) VALUES (?, ?, ?)"
|
||||||
executed_data = (cloth_type, weigth, pieces)
|
executed_data = (cloth_type, weigth, pieces)
|
||||||
cursor.execute(executed, executed_data)
|
cursor.execute(executed, executed_data)
|
||||||
connection.commit()
|
connection.commit()
|
||||||
@@ -97,3 +97,11 @@ def fetch_all_pieces():
|
|||||||
cursor = connection.cursor()
|
cursor = connection.cursor()
|
||||||
cursor.execute("SELECT sum(pieces) FROM luggage")
|
cursor.execute("SELECT sum(pieces) FROM luggage")
|
||||||
pieces = cursor.fetchone()[0]
|
pieces = cursor.fetchone()[0]
|
||||||
|
logging.info("fetched all luggage pieces")
|
||||||
|
return pieces
|
||||||
|
|
||||||
|
def delete(cloth_type):
|
||||||
|
cursor = connection.cursor()
|
||||||
|
cursor.execute("DELETE FROM luggage WHERE clothes = ?;", (cloth_type,))
|
||||||
|
logging.critical(f"{cloth_type} was deleted")
|
||||||
|
connection.commit()
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ except Exception as e:
|
|||||||
|
|
||||||
def insert():
|
def insert():
|
||||||
clothe = input("How is the clothe called? ").upper()
|
clothe = input("How is the clothe called? ").upper()
|
||||||
weigth = input("The weigth please? ")
|
weigth = float(input("The weigth please? "))
|
||||||
pieces = input("How many pieces? ints only ")
|
pieces = int(input("How many pieces? ints only "))
|
||||||
db.new_part(clothe, weigth, pieces)
|
db.new_part(clothe, weigth, pieces)
|
||||||
print("it is inserted")
|
print("it is inserted")
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
@@ -88,6 +88,19 @@ def get_weigth_pieces():
|
|||||||
os.system('cls' if os.name == 'nt' else 'clear')
|
os.system('cls' if os.name == 'nt' else 'clear')
|
||||||
menu()
|
menu()
|
||||||
|
|
||||||
|
def delete():
|
||||||
|
clothe = input("How is the clothe called? ").upper()
|
||||||
|
really = input("Do you really want to delete it? Y/N").upper()
|
||||||
|
if really == "Y":
|
||||||
|
db.delete(clothe)
|
||||||
|
print(f"{clothe} was deleted")
|
||||||
|
time.sleep(3)
|
||||||
|
else:
|
||||||
|
time.sleep(0.5)
|
||||||
|
logging.info("no item deleted")
|
||||||
|
os.system('cls' if os.name == 'nt' else 'clear')
|
||||||
|
menu()
|
||||||
|
|
||||||
def exit_programm():
|
def exit_programm():
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
print(r"""
|
print(r"""
|
||||||
@@ -118,6 +131,7 @@ def menu():
|
|||||||
print("6: Get pieces of luggage")
|
print("6: Get pieces of luggage")
|
||||||
print("7: Get clothes")
|
print("7: Get clothes")
|
||||||
print("8: Get weigth and pieces of clothes")
|
print("8: Get weigth and pieces of clothes")
|
||||||
|
print("9: Delete Item")
|
||||||
print("0: EXIT")
|
print("0: EXIT")
|
||||||
choice = input("Type number here ")
|
choice = input("Type number here ")
|
||||||
os.system('cls' if os.name == 'nt' else 'clear')
|
os.system('cls' if os.name == 'nt' else 'clear')
|
||||||
@@ -141,6 +155,8 @@ def menu():
|
|||||||
get_weigth_pieces()
|
get_weigth_pieces()
|
||||||
if choice == "0":
|
if choice == "0":
|
||||||
exit_programm()
|
exit_programm()
|
||||||
|
if choice == "9":
|
||||||
|
delete()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user