toggleable lists also apply status to newly added items
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Remy Moll 2023-07-27 11:43:05 +02:00
parent 86a9762f39
commit e77c106813
2 changed files with 31 additions and 35 deletions

40
Pipfile.lock generated
View File

@ -16,11 +16,11 @@
"default": {
"anyio": {
"hashes": [
"sha256:691adfc3c36c0d922c69a8d4105e73cf4cf697f7e66a1baf04347bf5f1a0d6a9",
"sha256:8ffa2a3572d4a9852481fb6f8b7fd3c678b27860e07b8789da4ddb06675aa219"
"sha256:48d53f0b141f5757c38d648309e6fe254857fae092d67f938fa248d7c0f36804",
"sha256:596b09c520820e7eed961ddc889540972f92d5e8fcb081117fc054c409df34ae"
],
"markers": "python_version >= '3.7'",
"version": "==3.7.0rc1"
"markers": "python_version >= '3.8'",
"version": "==4.0.0rc1"
},
"apscheduler": {
"hashes": [
@ -31,11 +31,11 @@
},
"certifi": {
"hashes": [
"sha256:0f0d56dc5a6ad56fd4ba36484d6cc34451e1c6548c61daad8c320169f91eddc7",
"sha256:c6c2e98f5c7869efca1f8916fed228dd91539f9f1b444c314c06eef02980c716"
"sha256:539cc1d13202e33ca466e88b2807e29f4c13049d6d87031a3c110744495cb082",
"sha256:92d6037539857d8206b8f6ae472e8b77db8058fec5937a1ef3f54304089edbb9"
],
"markers": "python_version >= '3.6'",
"version": "==2023.5.7"
"version": "==2023.7.22"
},
"h11": {
"hashes": [
@ -47,11 +47,11 @@
},
"httpcore": {
"hashes": [
"sha256:628e768aaeec1f7effdc6408ba1c3cdbd7487c1fc570f7d66844ec4f003e1ca4",
"sha256:caf508597c525f9b8bfff187e270666309f63115af30f7d68b16143a403c8356"
"sha256:a6f30213335e34c1ade7be6ec7c47f19f50c56db36abef1a9dfa3815b1cb3888",
"sha256:c2789b767ddddfa2a5782e3199b2b7f6894540b17b16ec26b2c4d8e103510b87"
],
"markers": "python_version >= '3.7'",
"version": "==0.17.1"
"version": "==0.17.3"
},
"httpx": {
"hashes": [
@ -81,11 +81,11 @@
"job-queue"
],
"hashes": [
"sha256:1185edee387db7b08027e87b67fa9a3cc3263ae5ab5bb55513acd1bca5c3cf4b",
"sha256:73e46a534be9d1c790ce8b494765cca18a5c2f3f5b4932d83bcb06bb0051eb4a"
"sha256:a6ac3f9c9674aaf7d1c7e652d8b75cde969fb872f75e9521b8516eceaba82b1b",
"sha256:e426404b0006989a5bcc05e11a7ef3ffe0c086b684a4e963db5bda1d361a049a"
],
"index": "pypi",
"version": "==20.3"
"version": "==20.4"
},
"pytz": {
"hashes": [
@ -96,11 +96,11 @@
},
"setuptools": {
"hashes": [
"sha256:5df61bf30bb10c6f756eb19e7c9f3b473051f48db77fddbe06ff2ca307df9a6f",
"sha256:62642358adc77ffa87233bc4d2354c4b2682d214048f500964dbe760ccedf102"
"sha256:11e52c67415a381d10d6b462ced9cfb97066179f0e871399e006c4ab101fc85f",
"sha256:baf1fdb41c6da4cd2eae722e135500da913332ab3f2f5c7d33af9b492acb5235"
],
"markers": "python_version >= '3.7'",
"version": "==67.8.0"
"version": "==68.0.0"
},
"six": {
"hashes": [
@ -118,14 +118,6 @@
"markers": "python_version >= '3.7'",
"version": "==1.3.0"
},
"tzdata": {
"hashes": [
"sha256:11ef1e08e54acb0d4f95bdb1be05da659673de4acbd21bf9c69e94cc5e907a3a",
"sha256:7e65763eef3120314099b6939b5546db7adce1e7d6f2e179e3df563c70511eda"
],
"markers": "platform_system == 'Windows'",
"version": "==2023.3"
},
"tzlocal": {
"hashes": [
"sha256:46eb99ad4bdb71f3f72b7d24f4267753e240944ecfc16f25d2719ba89827a803",

View File

@ -169,11 +169,17 @@ class ListHandler(BaseHandler):
list_object = context.user_data["current_list"]
content_it = list_object.content.values()
done_it = [
"· " if e is None \
else "" if e \
else "" \
for e in 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 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)])
else:
@ -191,7 +197,6 @@ class ListHandler(BaseHandler):
new = list_object.content
new.update({"random_key": item})
list_object.content = new
# TODO test me!
keyboard = [[InlineKeyboardButton("Add some more", callback_data="add"), InlineKeyboardButton("Back to the menu", callback_data="overview")]]
reply_markup = InlineKeyboardMarkup(keyboard)
await update.message.reply_text(f"Added {item}", reply_markup=reply_markup)
@ -204,11 +209,10 @@ class ListHandler(BaseHandler):
await query.answer()
list_object = context.user_data["current_list"]
old = list_object.done_dict[toggle_key]
# if all None or all False (first toggle or all false) then set all dones to False
if not any(list_object.done_dict.values()):
new_done_dict = dict.fromkeys(list_object.done_dict, False)
else: new_done_dict = list_object.done_dict
old = list_object.done_dict[toggle_key] or False
# if it was previously unset (None), we can later on set it to not old = True
new_done_dict = list_object.done_dict
new_done_dict[toggle_key] = not old
list_object.done_dict = new_done_dict