def __rename_recipe(message): _user_data = self.get_user_data(message) new_title = _user_data.text _response = book_recipes(self.id, self.username).rename(self.category, self.recipe_title, new_title) recipe = new_title if _response.status else self.recipe_title self.send_notification(_response) routes(message, command='get_recipe', category=self.category, recipe=recipe)
def get_all(self): response = book_recipes(self.id, self.username).get_all() for recipe in response.body: recipe_title = recipe.split('(')[0].strip() category = recipe.split('"')[1].strip() self.markup.add(self.button(recipe, callback_data='get_recipe' + ':' + category + ':' + recipe_title)) self.markup.add(go_home) bot.send_message(self.id, text='*Все рецепты*', parse_mode='Markdown', reply_markup=self.markup)
def edit(self): def __edit(message): user_data = self.get_user_data(message) response = book_recipes(self.id, self.username).edit(self.category, self.recipe_title, user_data.text) self.send_notification(response) routes(message, command='get_recipe', category=self.category, recipe=self.recipe_title) recipe = book_recipes(self.id, self.username).get(self.category, self.recipe_title).body bot.send_message(self.id, text=recipe) bot.send_message(self.id, text='Введите текст рецпета') bot.register_next_step_handler(self.message, __edit)
def get(self): response = book_recipes(self.id, self.username).get(self.category, self.recipe_title) go_back = self.button(text='----назад----', callback_data='get_from_category' + ':' + self.category) rename = self.button(text='----переименовать----', callback_data='rename_recipe' + ':' + self.category + ':' + self.recipe_title) edit = self.button(text='----редактировать----', callback_data='edit_recipe' + ':' + self.category + ':' + self.recipe_title) delete = self.button(text='----удалить----', callback_data='delete_recipe' + ':' + self.category + ':' + self.recipe_title) self.markup.add(rename, delete) self.markup.add(edit) self.markup.add(go_back, go_home) bot.send_message(self.id, f'*{self.recipe_title}*\n\n{response.body}', reply_markup=self.markup, parse_mode='Markdown')
def get_from_category(self): response = book_recipes(self.id, self.username).get_titles(self.category) add_recipe_button = self.button(text='----добавить рецепт----', callback_data='add_recipe' + ':' + self.category) go_back = self.button(text='----назад----', callback_data='get_categories') rename_category_button = self.button(text='----переименовать---- ', callback_data='rename_category' + ':' + self.category) delete_category_button = self.button(text='----удалить----', callback_data='delete_category' + ':' + self.category) if response.status: for recipe_title in response.body: self.markup.add(self.button( text=recipe_title, callback_data='get_recipe' + ':' + self.category + ':' + recipe_title)) self.markup.add(add_recipe_button) self.markup.add(rename_category_button, delete_category_button) self.markup.add(go_back, go_home) bot.send_message(self.id, f'*Рецпты в категории "{self.category}"*', parse_mode='Markdown', reply_markup=self.markup) else: self.markup.add(add_recipe_button) self.markup.add(rename_category_button, delete_category_button) self.markup.add(go_back, go_home) bot.send_message(self.id, f'_{response.body}_', parse_mode='Markdown', reply_markup=self.markup)
def delete(self): response = book_recipes(self.id, self.username).delete(self.category, self.recipe_title) self.send_notification(response) routes(self.call, command='get_from_category', category=self.category)
def __edit(message): user_data = self.get_user_data(message) response = book_recipes(self.id, self.username).edit(self.category, self.recipe_title, user_data.text) self.send_notification(response) routes(message, command='get_recipe', category=self.category, recipe=self.recipe_title)
def __add_recipe_body(_call, title): _user_data = self.get_user_data(_call) response = book_recipes(self.id, self.username).add(self.category, title, _user_data.text) self.send_notification(response) routes(_call, command='get_from_category', category=self.category)