cleaner journal date entry
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
d40afca1a4
commit
35dbbe4ece
@ -20,7 +20,7 @@ class JournalHandler(BaseHandler):
|
||||
states={
|
||||
ENTRY_OPTIONS: [
|
||||
CallbackQueryHandler(self.date_button, pattern=r"^\d{8}$"), # a serialized date
|
||||
CallbackQueryHandler(self.date_custom, pattern=r"^\d{1,3}$"), # a ~ small delta
|
||||
CallbackQueryHandler(self.date_custom, pattern=r"^\d{1,3}$"), # a ~ small delta, symbolizing a new range to show
|
||||
CallbackQueryHandler(self.option_delete, pattern="delete"),
|
||||
MessageHandler(filters.ALL, self.date_entry),
|
||||
],
|
||||
@ -40,7 +40,8 @@ class JournalHandler(BaseHandler):
|
||||
await update.message.reply_text("You are not authorized to use this bot")
|
||||
return ConversationHandler.END
|
||||
|
||||
dates = [(datetime.datetime.now() - datetime.timedelta(days = i)).date() for i in range(BUTTON_COUNT)][::-1]
|
||||
dates = [(datetime.datetime.now() - datetime.timedelta(days = i)).date() for i in range(BUTTON_COUNT + 2)][::-1]
|
||||
# since there are two buttons additional buttons, we need to have two more days
|
||||
names = [d.strftime("%d.%m.") for d in dates]
|
||||
callbacks = [d.strftime("%d%m%Y") for d in dates]
|
||||
names[-1] = "Today"
|
||||
@ -48,9 +49,16 @@ class JournalHandler(BaseHandler):
|
||||
|
||||
options = [
|
||||
[
|
||||
InlineKeyboardButton("<<", callback_data=BUTTON_COUNT)
|
||||
] + [
|
||||
InlineKeyboardButton(n, callback_data=c) for n,c in zip(names, callbacks)
|
||||
InlineKeyboardButton(names[-1], callback_data=callbacks[-1])
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton(names[-2], callback_data=callbacks[-2])
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton(n, callback_data=c) for n,c in zip(names[:-2], callbacks[:-2])
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton("<<", callback_data=BUTTON_COUNT + 2)
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton("Delete", callback_data="delete")
|
||||
@ -87,24 +95,26 @@ class JournalHandler(BaseHandler):
|
||||
await query.answer()
|
||||
delta = int(query.data)
|
||||
|
||||
dates = [(datetime.datetime.now() - datetime.timedelta(days = i + delta)).date() for i in range(BUTTON_COUNT - 1)][::-1]
|
||||
dates = [(datetime.datetime.now() - datetime.timedelta(days = i + delta)).date() for i in range(BUTTON_COUNT)][::-1]
|
||||
names = [d.strftime("%d.%m.") for d in dates]
|
||||
callbacks = [d.strftime("%d%m%Y") for d in dates]
|
||||
|
||||
options = [
|
||||
[
|
||||
InlineKeyboardButton("<<", callback_data=delta + (BUTTON_COUNT - 1))
|
||||
] + [
|
||||
InlineKeyboardButton(">>", callback_data=delta - BUTTON_COUNT)
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton(n, callback_data=c) for n,c in zip(names, callbacks)
|
||||
] + [
|
||||
InlineKeyboardButton(">>", callback_data=delta - (BUTTON_COUNT - 1))
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton("<<", callback_data=delta + BUTTON_COUNT)
|
||||
],
|
||||
[
|
||||
InlineKeyboardButton("Delete", callback_data="delete")
|
||||
]
|
||||
]
|
||||
keyboard = InlineKeyboardMarkup(options)
|
||||
await query.edit_message_text("Please choose a date \(or type it in the format _DDMMYYYY_\)", parse_mode=ParseMode.MARKDOWN_V2)
|
||||
await query.edit_message_text("Please choose a date \(or type it in the format _DDMMYYYY_\)", parse_mode=ParseMode.MARKDOWN_V2, reply_markup=keyboard)
|
||||
|
||||
return ENTRY_OPTIONS
|
||||
|
||||
@ -161,7 +171,7 @@ class JournalHandler(BaseHandler):
|
||||
self.current_model.save_media(file_bytes, file_path)
|
||||
|
||||
self.current_model.text = update.message.caption
|
||||
|
||||
|
||||
self.current_model.save()
|
||||
|
||||
await update.message.reply_text(f"Saved entry ✅")
|
||||
@ -180,4 +190,4 @@ class JournalHandler(BaseHandler):
|
||||
with self.models.db:
|
||||
self.current_model.delete_instance()
|
||||
context.chat_data["delete"] = False
|
||||
await update.message.reply_text(text="Entry deleted ✅")
|
||||
await update.message.reply_text(text="Entry deleted ✅")
|
||||
|
Loading…
x
Reference in New Issue
Block a user