This commit is contained in:
@@ -12,13 +12,15 @@ DB_DIR.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
NAME, NEW, ACTION, ITEMADD, ITEMREMOVE = range(5)
|
||||
|
||||
from ..basehandler import BaseHandler
|
||||
|
||||
class ListHandler:
|
||||
|
||||
class ListHandler(BaseHandler):
|
||||
"""Create and edit lists"""
|
||||
|
||||
def __init__(self, entry_string, models):
|
||||
self.models = models
|
||||
|
||||
self.entry_string = entry_string
|
||||
self.handler = ConversationHandler(
|
||||
entry_points=[CommandHandler(entry_string, self.entry_point)],
|
||||
states={
|
||||
@@ -43,6 +45,7 @@ class ListHandler:
|
||||
|
||||
|
||||
async def entry_point(self, update, context) -> None:
|
||||
await super().entry_point(update, context)
|
||||
set_db(DB_DIR / f"{update.message.chat_id}.db")
|
||||
lists = ListModel.select()
|
||||
keyboard = [[InlineKeyboardButton(k.name, callback_data=f"list-{k.name}")] for k in lists] + \
|
||||
@@ -121,9 +124,9 @@ class ListHandler:
|
||||
async def list_remove(self, update, context) -> None:
|
||||
query = update.callback_query
|
||||
await query.answer()
|
||||
sl = ListModel.get(name = self.current_name)
|
||||
list_object = ListModel.get(name = self.current_name)
|
||||
|
||||
keyboard = [[InlineKeyboardButton(k, callback_data=i)] for i,k in enumerate(sl)]
|
||||
keyboard = [[InlineKeyboardButton(k, callback_data=i)] for i,k in enumerate(list_object.content_list)]
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
|
||||
await query.edit_message_text("Which item would you like to remove?", reply_markup = reply_markup)
|
||||
@@ -153,7 +156,7 @@ class ListHandler:
|
||||
await query.answer()
|
||||
it = ListModel.get(name = self.current_name).content_list
|
||||
if it:
|
||||
content = "\n* ".join(it)
|
||||
content = "·" + "\n· ".join(it)
|
||||
else:
|
||||
content = "List empty"
|
||||
|
||||
@@ -181,7 +184,7 @@ class ListHandler:
|
||||
list_object = ListModel.get(name = self.current_name)
|
||||
old = list_object.content_list
|
||||
name = old.pop(ind)
|
||||
self.db_utils.list_update(self.current_name, replace=old)
|
||||
list_object.content_list = old
|
||||
|
||||
keyboard = [[InlineKeyboardButton("Remove another", callback_data="remove"), InlineKeyboardButton("Back to the menu", callback_data="overview")]]
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
|
Reference in New Issue
Block a user