mirror of
https://github.com/ada-dmitry/lab6.git
synced 2026-09-24 01:10:15 +00:00
delete for cath
This commit is contained in:
+64
-47
@@ -1,5 +1,4 @@
|
||||
import sys
|
||||
import texts
|
||||
import math
|
||||
|
||||
# import time
|
||||
@@ -21,10 +20,12 @@ TODO:
|
||||
6) Доделать ограничение на выбор категории - done
|
||||
7) UPDATE для блюд - done 0.7
|
||||
8) Постраничный вывод - indev 0.8 - реализация через offset.
|
||||
9) Реализовать отдельный просмотр(offset)
|
||||
9) Реализовать отдельный просмотр(offset) - done for cath
|
||||
10) И отдельный вывод(offset)
|
||||
|
||||
|
||||
1) detele category - done
|
||||
|
||||
FIXME:
|
||||
1) Откомментировать os.cls
|
||||
2) Исправить вылет при неверном вводе в самое начало(сделать выход на предыдущую менюшку)
|
||||
@@ -60,7 +61,11 @@ class Main:
|
||||
cth.drop()
|
||||
return
|
||||
def show_main_menu(self):
|
||||
menu = texts.show_main_menu_txt
|
||||
menu = """Привутствуем в меню, выберите действие:
|
||||
1 - просмотр категорий;
|
||||
2 - сброс и инициализация БД;
|
||||
9 - выход;"""
|
||||
|
||||
print(menu)
|
||||
return
|
||||
def read_next_step(self):
|
||||
@@ -79,63 +84,68 @@ class Main:
|
||||
else:
|
||||
return next_step
|
||||
|
||||
|
||||
def show_cath(self):
|
||||
self.cath_id = -1
|
||||
menu = texts.show_cath_1txt
|
||||
print(menu)
|
||||
self.max_cath_index = len(CathTable().all())
|
||||
self.cath_page = 1
|
||||
lst = CathTable().get_page(self.cath_page)
|
||||
def show_page_cath(self):
|
||||
menu = """Просмотр списка категорий!
|
||||
№\tНазвание\n-------------------------------------------------------------------------------------------"""
|
||||
|
||||
cath_page = 1
|
||||
lst = CathTable().get_cath_page(cath_page)
|
||||
action = '>'
|
||||
max_page = math.ceil(self.max_cath_index/10)
|
||||
while True:
|
||||
|
||||
self.cath_arr = []
|
||||
|
||||
for i in lst:
|
||||
self.cath_arr.append(str(i[0]))
|
||||
cath_arr = CathTable().get_cath_page(cath_page)
|
||||
add_func.cls()
|
||||
for i in range(len(self.cath_arr)):
|
||||
print(add_func.add_zero_before(str((i+1)+(10*(self.cath_page-1))), len(str(self.max_cath_index))) + "\t" + self.cath_arr[i])
|
||||
print(menu)
|
||||
|
||||
for i in range(len(cath_arr)):
|
||||
print(add_func.add_zero_before(cath_arr[i][0],\
|
||||
len(str(self.max_cath_index))) + "\t" + cath_arr[i][1])
|
||||
|
||||
action = input('-------------------------------------------------------------------------------------------\n\
|
||||
Для переключения между страницами используйте "<" и ">"\nКол-во записей на странице: 10\n\
|
||||
Для выхода в меню действий нажмите любую другую клавишу\n=> ')
|
||||
|
||||
if(action=='>'):
|
||||
if(self.cath_page==max_page):
|
||||
self.cath_page = 1
|
||||
if(cath_page==max_page):
|
||||
cath_page = 1
|
||||
else:
|
||||
self.cath_page += 1
|
||||
lst = CathTable().get_page(self.cath_page)
|
||||
cath_page += 1
|
||||
lst = CathTable().get_cath_page(cath_page)
|
||||
elif(action=='<'):
|
||||
if(self.cath_page==1):
|
||||
self.cath_page = max_page
|
||||
if(cath_page==1):
|
||||
cath_page = max_page
|
||||
else:
|
||||
self.cath_page -= 1
|
||||
lst = CathTable().get_page(self.cath_page)
|
||||
cath_page -= 1
|
||||
lst = CathTable().get_cath_page(cath_page)
|
||||
else:
|
||||
break
|
||||
|
||||
menu = texts.show_cath_2txt
|
||||
|
||||
|
||||
|
||||
def show_cath(self):
|
||||
self.cath_id = -1
|
||||
self.max_cath_index = CathTable().count()
|
||||
self.show_page_cath()
|
||||
menu = """-------------------------------------------------------------------------------------------\nДальнейшие операции:
|
||||
0 - возврат в главное меню;
|
||||
3 - добавление новой категории;
|
||||
4 - удаление категории;
|
||||
5 - просмотр блюд в категории;
|
||||
8 - обновить категорию;
|
||||
9 - выход."""
|
||||
print(menu)
|
||||
return
|
||||
|
||||
def after_show_cath(self, next_step):
|
||||
"""Выбор действий после вывода категорий
|
||||
"""
|
||||
"""
|
||||
while True:
|
||||
if next_step == "4": # Удаление категории
|
||||
if(self.cath_page<(self.max_cath_index//10)):
|
||||
left = ((self.cath_page-1)*10)+1
|
||||
right = left+9
|
||||
print(left)
|
||||
|
||||
else:
|
||||
left = 1+((self.cath_page-1)*10)
|
||||
right = self.max_cath_index
|
||||
left = 0
|
||||
right = self.max_cath_index
|
||||
x = add_func.validate_input('Введите номер удаляемой категории (0 - для отмены): ', left, right)
|
||||
if(x!=-1):
|
||||
CathTable().delete(self.cath_arr[(int(x)-1)-((self.cath_page-1)*10)])
|
||||
CathTable().delete(CathTable().get_cath_from_page(x).get("id"))
|
||||
return "1"
|
||||
|
||||
elif next_step == "6": #Добавление блюда в категорию
|
||||
@@ -143,13 +153,13 @@ class Main:
|
||||
next_step = "5"
|
||||
|
||||
elif next_step == "7":#Удаление блюда из категории
|
||||
if(self.dish_page<(self.max_index//10)):
|
||||
if(self.dish_page<(self.max_dish_index//10)):
|
||||
left = ((self.dish_page-1)*10)+(self.dish_page==1)
|
||||
right = left+9
|
||||
|
||||
else:
|
||||
left = 1+((self.dish_page-1)*10)+(self.dish_page!=1)
|
||||
right = self.max_index
|
||||
right = self.mex_dish_index
|
||||
x = add_func.validate_input('Введите номер удаляемого блюда (0 - для отмены): ', left, right)
|
||||
if(x!=-1):
|
||||
DishTable().delete(self.dish_arr[(int(x)-1)-((self.dish_page-1)*10)][0])
|
||||
@@ -172,14 +182,15 @@ class Main:
|
||||
if(x!=-1):
|
||||
CathTable().cath_update(self.cath_arr[(int(x)-1)-((self.cath_page-1)*10)])
|
||||
return "1"
|
||||
|
||||
elif next_step == "88":
|
||||
if(self.dish_page<(self.max_index//10)):
|
||||
if(self.dish_page<(self.mex_dish_index//10)):
|
||||
left = 1+((self.dish_page-1)*10)
|
||||
right = left+9
|
||||
|
||||
else:
|
||||
left = 0+((self.dish_page-1)*10)
|
||||
right = self.max_index
|
||||
right = self.mex_dish_index
|
||||
x = add_func.validate_input('Введите номер обновляемого блюда (0 - для отмены): ', left, right)
|
||||
if(x!=-1):
|
||||
DishTable().update_dish(self.dish_arr[(int(x)-1)-((self.cath_page-1)*10)][0])
|
||||
@@ -238,9 +249,9 @@ class Main:
|
||||
self.dish_page = 1
|
||||
lst = DishTable().get_page_dish(self.cath_id, self.dish_page)
|
||||
self.max_len_name = 0
|
||||
self.max_index = len(DishTable().all_by_cath_id(self.cath_id))
|
||||
self.mex_dish_index = len(DishTable().all_by_cath_id(self.cath_id))
|
||||
action = '>'
|
||||
max_page = math.ceil(self.max_index/10)
|
||||
max_page = math.ceil(self.mex_dish_index/10)
|
||||
lst = DishTable().get_page_dish(self.cath_id, self.dish_page)
|
||||
|
||||
while True:
|
||||
@@ -250,12 +261,12 @@ class Main:
|
||||
self.dish_arr.append([i[2], str(i[1]), str(i[4])])
|
||||
self.max_len_name = max(self.max_len_name, len(i[2]))
|
||||
add_func.cls()
|
||||
print("№" + " "*(len(str(self.max_index)) + 1)+ "Название" + " "*(self.max_len_name - 4)\
|
||||
print("№" + " "*(len(str(self.mex_dish_index)) + 1)+ "Название" + " "*(self.max_len_name - 4)\
|
||||
+"Время приготовления Краткая инструкция\
|
||||
\n-------------------------------------------------------------------------------------------")
|
||||
|
||||
for i in range(len(self.dish_arr)):
|
||||
txt = add_func.add_zero_before(str((i+1)+(10*(self.dish_page-1))), len(str(self.max_index))) + " "*(2+len(str(self.max_index)))
|
||||
txt = add_func.add_zero_before(str((i+1)+(10*(self.dish_page-1))), len(str(self.mex_dish_index))) + " "*(2+len(str(self.mex_dish_index)))
|
||||
txt += self.dish_arr[i][0] + " "*(4+self.max_len_name - len(self.dish_arr[i][0]))
|
||||
txt += self.dish_arr[i][1] + " "*(5+19-len(self.dish_arr[i][1]))
|
||||
txt += self.dish_arr[i][2]
|
||||
@@ -278,7 +289,13 @@ class Main:
|
||||
else:
|
||||
break
|
||||
|
||||
menu = texts.show_dish_in_cath_txt
|
||||
menu = """-------------------------------------------------------------------------------------------\nДальнейшие операции:
|
||||
0 - возврат в главное меню;
|
||||
1 - возврат в просмотр категорий;
|
||||
6 - добавление нового блюда;
|
||||
7 - удаление блюда;
|
||||
88 - для обновления блюда;
|
||||
9 - выход."""
|
||||
print(menu)
|
||||
return self.read_next_step()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user