diff --git a/0.7_indev/__pycache__/add_func.cpython-311.pyc b/0.7_stable/__pycache__/add_func.cpython-311.pyc similarity index 72% rename from 0.7_indev/__pycache__/add_func.cpython-311.pyc rename to 0.7_stable/__pycache__/add_func.cpython-311.pyc index 1b2fa6c..12426f4 100644 Binary files a/0.7_indev/__pycache__/add_func.cpython-311.pyc and b/0.7_stable/__pycache__/add_func.cpython-311.pyc differ diff --git a/0.7_indev/__pycache__/dbconnection.cpython-311.pyc b/0.7_stable/__pycache__/dbconnection.cpython-311.pyc similarity index 100% rename from 0.7_indev/__pycache__/dbconnection.cpython-311.pyc rename to 0.7_stable/__pycache__/dbconnection.cpython-311.pyc diff --git a/0.7_indev/__pycache__/dbtable.cpython-311.pyc b/0.7_stable/__pycache__/dbtable.cpython-311.pyc similarity index 99% rename from 0.7_indev/__pycache__/dbtable.cpython-311.pyc rename to 0.7_stable/__pycache__/dbtable.cpython-311.pyc index ee9d809..22fefc9 100644 Binary files a/0.7_indev/__pycache__/dbtable.cpython-311.pyc and b/0.7_stable/__pycache__/dbtable.cpython-311.pyc differ diff --git a/0.7_indev/__pycache__/project_config.cpython-311.pyc b/0.7_stable/__pycache__/project_config.cpython-311.pyc similarity index 100% rename from 0.7_indev/__pycache__/project_config.cpython-311.pyc rename to 0.7_stable/__pycache__/project_config.cpython-311.pyc diff --git a/0.7_indev/__pycache__/texts.cpython-311.pyc b/0.7_stable/__pycache__/texts.cpython-311.pyc similarity index 80% rename from 0.7_indev/__pycache__/texts.cpython-311.pyc rename to 0.7_stable/__pycache__/texts.cpython-311.pyc index a7e4b31..165ae1b 100644 Binary files a/0.7_indev/__pycache__/texts.cpython-311.pyc and b/0.7_stable/__pycache__/texts.cpython-311.pyc differ diff --git a/0.7_indev/add_func.py b/0.7_stable/add_func.py similarity index 91% rename from 0.7_indev/add_func.py rename to 0.7_stable/add_func.py index 3c7293a..0b41e89 100644 --- a/0.7_indev/add_func.py +++ b/0.7_stable/add_func.py @@ -44,3 +44,10 @@ def validate_input(prompt, min_value, max_value): print(f"Введенное значение должно быть в диапазоне от {min_value} до {max_value}") except ValueError: print("Введенное значение должно быть числом.") + + +test1 = 'erhwogngonwro' +test2 = '1 minute' +test3 = '2 hours 3 minutes' + +print(validate_time_format(test1), validate_time_format(test2), validate_time_format(test3)) \ No newline at end of file diff --git a/0.7_indev/config.yaml b/0.7_stable/config.yaml similarity index 100% rename from 0.7_indev/config.yaml rename to 0.7_stable/config.yaml diff --git a/0.7_indev/dbconnection.py b/0.7_stable/dbconnection.py similarity index 100% rename from 0.7_indev/dbconnection.py rename to 0.7_stable/dbconnection.py diff --git a/0.7_indev/dbtable.py b/0.7_stable/dbtable.py similarity index 100% rename from 0.7_indev/dbtable.py rename to 0.7_stable/dbtable.py diff --git a/0.7_indev/main.py b/0.7_stable/main.py similarity index 96% rename from 0.7_indev/main.py rename to 0.7_stable/main.py index 4ef2666..b76fa77 100644 --- a/0.7_indev/main.py +++ b/0.7_stable/main.py @@ -17,8 +17,8 @@ TODO: 4) UPDATE для категорий - done 5) Красивый вывод - done 6) Доделать ограничение на выбор категории - done -7) Постраничный вывод - indev -8) UPDATE для блюд - indev +7) UPDATE для блюд - done +8) Постраничный вывод - indev FIXME: ''' @@ -82,7 +82,7 @@ class Main: menu = texts.show_cath_1txt print(menu) lst = CathTable().all() - self.max_cath_index = (len(lst)+1) + self.max_cath_index = (len(lst)) for i in lst: self.cath_arr.append(str(i[0])) @@ -99,7 +99,7 @@ class Main: while True: if next_step == "4": # Удаление категории x = add_func.validate_input('Введите номер удаляемой категории (0 - для отмены): ', 0, self.max_cath_index) - if(x!=0): + if(x!=-1): CathTable().delete(self.cath_arr[int(x)-1]) return "1" @@ -109,7 +109,7 @@ class Main: elif next_step == "7":#Удаление блюда из категории x = add_func.validate_input('Введите номер удаляемого блюда (0 - для отмены): ', 0, self.max_index) - if(x!=0): + if(x!=-1): DishTable().delete(self.dish_arr[int(x)-1][0]) else: return "1" @@ -120,13 +120,12 @@ class Main: elif next_step == "8": # Обновление названия категории x = add_func.validate_input('Введите номер обновляемой категории (0 - для отмены): ', 0, self.max_cath_index) - if(x!=0): + if(x!=-1): CathTable().cath_update(self.cath_arr[int(x)-1]) return "1" - - elif next_step == "u": + elif next_step == "88": x = add_func.validate_input('Введите номер изменяемого блюда (0 - для отмены): ', 0, self.max_index) - if(x!=0): + if(x!=-1): DishTable().update_dish(self.dish_arr[int(x)-1][0]) else: return "1" @@ -165,7 +164,7 @@ class Main: if self.cath_id == -1: while True: x = add_func.validate_input('Выберите номер интересуемой категории (0 - отмена): ', 0, self.max_cath_index) - if(x!=0): + if(x!=-1): self.cath_id = CathTable().find_by_name(self.cath_arr[x-1]) self.cath_obj = self.cath_arr[x-1] else: diff --git a/0.7_indev/project_config.py b/0.7_stable/project_config.py similarity index 100% rename from 0.7_indev/project_config.py rename to 0.7_stable/project_config.py diff --git a/0.7_indev/tables/__pycache__/cath_table.cpython-311.pyc b/0.7_stable/tables/__pycache__/cath_table.cpython-311.pyc similarity index 100% rename from 0.7_indev/tables/__pycache__/cath_table.cpython-311.pyc rename to 0.7_stable/tables/__pycache__/cath_table.cpython-311.pyc diff --git a/0.7_indev/tables/__pycache__/dish_table.cpython-311.pyc b/0.7_stable/tables/__pycache__/dish_table.cpython-311.pyc similarity index 57% rename from 0.7_indev/tables/__pycache__/dish_table.cpython-311.pyc rename to 0.7_stable/tables/__pycache__/dish_table.cpython-311.pyc index e0f74eb..2e41776 100644 Binary files a/0.7_indev/tables/__pycache__/dish_table.cpython-311.pyc and b/0.7_stable/tables/__pycache__/dish_table.cpython-311.pyc differ diff --git a/0.7_indev/tables/cath_table.py b/0.7_stable/tables/cath_table.py similarity index 100% rename from 0.7_indev/tables/cath_table.py rename to 0.7_stable/tables/cath_table.py diff --git a/0.7_indev/tables/dish_table.py b/0.7_stable/tables/dish_table.py similarity index 89% rename from 0.7_indev/tables/dish_table.py rename to 0.7_stable/tables/dish_table.py index 540d020..23d9ba9 100644 --- a/0.7_indev/tables/dish_table.py +++ b/0.7_stable/tables/dish_table.py @@ -64,6 +64,14 @@ class DishTable(DbTable): cur.close() return str(result) + def id_by_name(self, name): + sql = f"""SELECT id FROM dish WHERE dish_name = '{name}'""" + cur = self.dbconn.conn.cursor() + cur.execute(sql) + result = cur.fetchone() + cur.close() + return str(result) + def insert_dishone(self, cath_id): ins_name = input('Введите название добавляемого блюда (1 - для отмены): ') @@ -89,11 +97,12 @@ class DishTable(DbTable): ins_time = input(f'Процесс добавления блюда: {ins_name}\ \nВведите время приготовления в формате 10 minutes/1 hour 5 minutes (1 - для отмены): ') - while(ins_time==0)or(add_func.validate_time_format(ins_time)): + while(ins_time==0)or(add_func.validate_time_format(ins_time)==False): if ins_time == "0": return "1" else: - ins_time = input('Введите время приготовления в формате 10 minutes/1 hour 5 minutes (1 - для отмены): ') + ins_time = input('Время введено в неверном формате. Повторите попытку.\n\ +Введите время приготовления в формате 10 minutes/1 hour 5 minutes (1 - для отмены): ') ins_manual = input(f'Процесс добавления блюда: {ins_name}\ \nВведите краткую инструкцию приготовления блюда (1 - для отмены): ') @@ -104,16 +113,16 @@ class DishTable(DbTable): self.insert_one(insert) - def update_dish(self, dish_id): - print('После изменения выберите другой пункт для изменения или введите -1 для выхода') - x = int(input('Что вы хотите изменить в рецепте?\n\ - 1 - Название\n2 - Время приготовления\n3 - Инструкция\n=> ')) + def update_dish(self, dish): + print('После изменения выберите другой пункт для изменения или введите 0 для выхода') + x = -10000 + obj_id = self.id_by_name(dish)[1] while(x!=-1): - if(x!=1 or x!=2 or x!=3): - x = int(input('Введите корректное число из списка (-1 - для выхода)\n\ - 1 - Название\n2 - Время приготовления\n3 - Инструкция\n=> ')) - elif(x==1): - new_name = input(f"Текущее название {self.name_by_id(dish_id)}") + x = add_func.validate_input('Что вы хотите изменить в рецепте?\n\ +1 - Название\n2 - Время приготовления\n3 - Инструкция\n0 - для отмены\n=> ', 0, 3) + + if(x==1): + new_name = input(f"Текущее название {dish}.\nВведите новое название: ") while (new_name.strip() == '')or(len(new_name.strip()) > 32)\ or(DishTable().check_by_name(new_name)): if(new_name.strip() == ''): @@ -123,7 +132,7 @@ class DishTable(DbTable): elif(len(new_name.strip()) > 32): new_name = input("Слишком длинная строка. Повторите ввод!\ - Укажите название блюда (0 - отмена): ") + Укажите название блюда (0 - отмена): ") if new_name == "0": return "1" else: @@ -131,22 +140,25 @@ class DishTable(DbTable): new_name = input("Повторите ввод! Укажите название блюда (0 - отмена): ") if new_name == "0": return "1" - self.update('dish_name', new_name, dish_id) + new_name = "'" + new_name + "'" + self.update('dish_name', new_name, obj_id) elif(x==2): new_time = input(f'Введите время приготовления в формате 10 minutes/1 hour 5 minutes (1 - для отмены): ') - while(new_time==0)or(add_func.validate_time_format(new_time)): + while(new_time==0)or(add_func.validate_time_format(new_time)==False): if new_time == "0": return "1" else: new_time = input('Введите время приготовления в формате 10 minutes/1 hour 5 minutes (1 - для отмены): ') - self.update('cook_time', new_time, dish_id) + new_time = "'" + new_time + "'" + self.update('cook_time', new_time, obj_id) elif(x==3): new_manual = input(f'Введите краткую инструкцию приготовления блюда (1 - для отмены): ') if new_manual == "0": return "1" - self.update('manual', new_manual, dish_id) + new_manual = "'" + new_manual + "'" + self.update('manual', new_manual, obj_id) diff --git a/0.7_indev/test.py b/0.7_stable/test.py similarity index 100% rename from 0.7_indev/test.py rename to 0.7_stable/test.py diff --git a/0.7_indev/texts.py b/0.7_stable/texts.py similarity index 96% rename from 0.7_indev/texts.py rename to 0.7_stable/texts.py index f616474..2cbce54 100644 --- a/0.7_indev/texts.py +++ b/0.7_stable/texts.py @@ -18,6 +18,7 @@ show_dish_in_cath_txt = """----------------------------------------------------- 1 - возврат в просмотр категорий; 6 - добавление нового блюда; 7 - удаление блюда; + 88 - для обновления блюда; 9 - выход.""" text_choice_update = """-------------------------------------------------------------------------------------------\n