Пример #1
0
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)
Пример #2
0
def open_creation_datepicker(session, context, poll):
    """Open the datepicker during the creation of a poll."""
    keyboard = get_creation_datepicker_keyboard(poll, date.today())
    # Switch from new option by text to new option via datepicker
    message = context.query.message
    if context.user.expected_input != ExpectedInput.options.name:
        message.edit_text(
            i18n.t("creation.option.finished", locale=context.user.locale))
        return

    context.user.expected_input = ExpectedInput.date.name

    text = get_datepicker_text(poll)

    if len(text) > 4000:
        error_message = i18n.t("misc.too_many_options",
                               locale=context.user.locale)
        raise RollbackException(error_message)

    message.edit_text(text, parse_mode="markdown", reply_markup=keyboard)