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:
		| @@ -20,7 +20,7 @@ class JournalHandler(BaseHandler): | |||||||
|             states={ |             states={ | ||||||
|                 ENTRY_OPTIONS: [ |                 ENTRY_OPTIONS: [ | ||||||
|                     CallbackQueryHandler(self.date_button, pattern=r"^\d{8}$"), # a serialized date |                     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"), |                     CallbackQueryHandler(self.option_delete, pattern="delete"), | ||||||
|                     MessageHandler(filters.ALL, self.date_entry), |                     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") |             await update.message.reply_text("You are not authorized to use this bot") | ||||||
|             return ConversationHandler.END |             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] |         names = [d.strftime("%d.%m.") for d in dates] | ||||||
|         callbacks = [d.strftime("%d%m%Y") for d in dates] |         callbacks = [d.strftime("%d%m%Y") for d in dates] | ||||||
|         names[-1] = "Today" |         names[-1] = "Today" | ||||||
| @@ -48,9 +49,16 @@ class JournalHandler(BaseHandler): | |||||||
|  |  | ||||||
|         options = [ |         options = [ | ||||||
|             [ |             [ | ||||||
|                 InlineKeyboardButton("<<", callback_data=BUTTON_COUNT) |                 InlineKeyboardButton(names[-1], callback_data=callbacks[-1]) | ||||||
|                 ] + [ |             ], | ||||||
|                 InlineKeyboardButton(n, callback_data=c) for n,c in zip(names, callbacks) |             [ | ||||||
|  |                 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") |                 InlineKeyboardButton("Delete", callback_data="delete") | ||||||
| @@ -87,24 +95,26 @@ class JournalHandler(BaseHandler): | |||||||
|         await query.answer() |         await query.answer() | ||||||
|         delta = int(query.data) |         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] |         names = [d.strftime("%d.%m.") for d in dates] | ||||||
|         callbacks = [d.strftime("%d%m%Y") for d in dates] |         callbacks = [d.strftime("%d%m%Y") for d in dates] | ||||||
|  |  | ||||||
|         options = [ |         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(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") |                 InlineKeyboardButton("Delete", callback_data="delete") | ||||||
|             ] |             ] | ||||||
|         ] |         ] | ||||||
|         keyboard = InlineKeyboardMarkup(options) |         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 |         return ENTRY_OPTIONS | ||||||
|  |  | ||||||
| @@ -161,7 +171,7 @@ class JournalHandler(BaseHandler): | |||||||
|                 self.current_model.save_media(file_bytes, file_path) |                 self.current_model.save_media(file_bytes, file_path) | ||||||
|  |  | ||||||
|                 self.current_model.text = update.message.caption |                 self.current_model.text = update.message.caption | ||||||
|              |  | ||||||
|             self.current_model.save() |             self.current_model.save() | ||||||
|  |  | ||||||
|         await update.message.reply_text(f"Saved entry ✅") |         await update.message.reply_text(f"Saved entry ✅") | ||||||
| @@ -180,4 +190,4 @@ class JournalHandler(BaseHandler): | |||||||
|         with self.models.db: |         with self.models.db: | ||||||
|             self.current_model.delete_instance() |             self.current_model.delete_instance() | ||||||
|         context.chat_data["delete"] = False |         context.chat_data["delete"] = False | ||||||
|         await update.message.reply_text(text="Entry deleted ✅") |         await update.message.reply_text(text="Entry deleted ✅") | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user