toggle option shows current status
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
cd7594350f
commit
9b54f05d75
@ -123,10 +123,17 @@ class ListHandler(BaseHandler):
|
||||
await query.answer()
|
||||
|
||||
list_object = context.user_data["current_list"]
|
||||
keyboard = [[InlineKeyboardButton(v, callback_data=k)] for k,v in list_object.content.items()]
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
readable_it = printable_list(list_object)
|
||||
|
||||
if readable_it:
|
||||
msg_content = "Which item would you like to toggle?"
|
||||
keyboard = [[InlineKeyboardButton(v, callback_data=k)] for k,v in zip(list_object.content.keys(), readable_it)]
|
||||
reply_markup = InlineKeyboardMarkup(keyboard)
|
||||
else:
|
||||
msg_content = "List empty"
|
||||
reply_markup = None
|
||||
|
||||
await query.edit_message_text("Which item would you like to toggle?", reply_markup = reply_markup)
|
||||
await query.edit_message_text(msg_content, reply_markup = reply_markup)
|
||||
return ITEMTOGGLE
|
||||
|
||||
|
||||
@ -168,20 +175,10 @@ class ListHandler(BaseHandler):
|
||||
await query.answer()
|
||||
list_object = context.user_data["current_list"]
|
||||
|
||||
content_it = list_object.content.values()
|
||||
# distinguish the enumeration:
|
||||
# either all done_dict values are None -> the list is not toggleable
|
||||
# or at least one value is of type bool -> the list is toggleable and None === False
|
||||
if any([type(e) == bool for e in list_object.done_dict.values()]):
|
||||
done_it = [
|
||||
"✅ " if e else "❌ " \
|
||||
for e in list_object.done_dict.values()
|
||||
]
|
||||
else:
|
||||
done_it = [". " for e in list_object.done_dict]
|
||||
|
||||
if content_it:
|
||||
msg_content = "\n".join([f"{d} {c}" for d, c in zip(done_it, content_it)])
|
||||
readable_it = printable_list(list_object)
|
||||
|
||||
if readable_it:
|
||||
msg_content = "\n".join(readable_it)
|
||||
else:
|
||||
msg_content = "List empty"
|
||||
|
||||
@ -238,3 +235,22 @@ class ListHandler(BaseHandler):
|
||||
|
||||
await query.edit_message_text(f"Removed {name}", reply_markup=reply_markup)
|
||||
return ACTION
|
||||
|
||||
|
||||
|
||||
def printable_list(list_object: ListModel):
|
||||
content_it = list_object.content.values()
|
||||
done_bool_it = list_object.done_dict.values()
|
||||
# distinguish the enumeration:
|
||||
# either all done_dict values are None -> the list is not toggleable
|
||||
# or at least one value is of type bool -> the list is toggleable and None === False
|
||||
if any([type(e) == bool for e in done_bool_it]):
|
||||
done_it = [
|
||||
"✅" if e else "❌" \
|
||||
for e in list_object.done_dict.values()
|
||||
]
|
||||
else:
|
||||
done_it = ["-" for e in done_bool_it]
|
||||
|
||||
readable_it = [f"{d} {c}" for d, c in zip(done_it, content_it)]
|
||||
return readable_it
|
||||
|
Loading…
x
Reference in New Issue
Block a user