aiogram_calendar icon indicating copy to clipboard operation
aiogram_calendar copied to clipboard

Update simple_calendar.py

Open mostepunk opened this issue 4 years ago • 1 comments

added come functionality to simple calendar I'm developer from Russia and I decided that it will be great to add some local functionality to other people from other countries that helps to faster localize it's apps. Added button "Cancel" for canceling operation. And added button "Today" to return in current month if user decided to return to today's calendar view. Added visual selection of current day in calendar

cal

Example of cancel button

# example_bot.py
@dp.callback_query_handler(cancel_callback.filter())
async def cancel_action(callback_query: CallbackQuery, callback_data: dict):
    await callback_query.message.edit_text('You canceled action')
    await callback_query.answer()

Hope it will helps to other developers

mostepunk avatar Dec 14 '21 15:12 mostepunk

OOOOPS I missed one important thing Aiogram raises Error MessageNotModified if user accidentally selected "Today" in today's calendar view

I don't know how to modify my merge request, I will write here: in simple_calendar.py you should insert this:

from contextlib import suppress
from aiogram.utils.exceptions import MessageNotModified
...

class SimpleCalendar:
    ...
    async def process_selection(self, query: CallbackQuery, data: CallbackData) -> tuple:
           ...
        if data['act'] == "CURR-MONTH":
            next_date = datetime.now()
            with suppress(MessageNotModified):
                await query.answer()
                await query.message.edit_reply_markup(
                        await self.start_calendar((next_date.year),(next_date.month))
                        )

mostepunk avatar Dec 14 '21 16:12 mostepunk

How can I hide the dates that have passed?

Снимок экрана 2023-01-04 в 18 12 41

lamin1792 avatar Jan 04 '23 15:01 lamin1792

package updated for aiogram 3, also has a built in localisation ability

noXplode avatar Nov 28 '23 21:11 noXplode