def pick_due_date(session, context, poll): """Set the due date for a poll.""" picked_date = date.fromisoformat(context.data[2]) if picked_date <= date.today(): return i18n.t('callback.due_date_in_past', locale=poll.user.locale) due_date = datetime.combine(picked_date, time(hour=12, minute=00)) if (due_date == poll.due_date): poll.set_due_date(None) context.query.answer( i18n.t('callback.due_date_removed', locale=poll.user.locale)) else: poll.set_due_date(due_date) context.query.message.edit_text( text=get_settings_text(context.poll), parse_mode='markdown', reply_markup=get_due_date_datepicker_keyboard(poll, picked_date))
def update_datepicker(context, poll, datepicker_context, current_date): """Update the creation datepicker.""" message = get_datepicker_text(context.poll) if datepicker_context == DatepickerContext.creation: keyboard = get_creation_datepicker_keyboard(poll, current_date) elif datepicker_context == DatepickerContext.additional_option: keyboard = get_add_option_datepicker_keyboard(poll, current_date) elif datepicker_context == DatepickerContext.external_add_option: keyboard = get_external_datepicker_keyboard(poll, current_date) elif datepicker_context == DatepickerContext.due_date: message = get_settings_text(poll) keyboard = get_due_date_datepicker_keyboard(poll, current_date) else: raise Exception('Unknown DatepickerContext') context.query.message.edit_text(message, parse_mode='markdown', reply_markup=keyboard, disable_web_page_preview=True)
def open_due_date_datepicker(session, context, poll): """Open the datepicker for setting a due date.""" poll.user.expected_input = ExpectedInput.due_date.name keyboard = get_due_date_datepicker_keyboard(poll, date.today()) context.query.message.edit_reply_markup(reply_markup=keyboard)