Ejemplo n.º 1
0
def open_new_option_datepicker(session, context, poll):
    """Send a text and tell the user that we expect a new option."""
    context.query.message.edit_text(
        text=get_datepicker_text(poll),
        parse_mode='markdown',
        reply_markup=get_add_option_datepicker_keyboard(poll),
    )
Ejemplo n.º 2
0
def open_external_datepicker(session, context, poll):
    """All options are entered the poll is created."""
    keyboard = get_external_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.new_user_option.name:
        message.edit_text(
            i18n.t("creation.option.finished", locale=context.user.locale))
        return

    message.edit_text(get_datepicker_text(poll),
                      parse_mode="markdown",
                      reply_markup=keyboard)
Ejemplo n.º 3
0
def open_creation_datepicker(session, context, poll):
    """All options are entered the poll is created."""
    keyboard = get_creation_datepicker_keyboard(poll)
    # 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

    message.edit_text(get_datepicker_text(poll),
                      parse_mode='markdown',
                      reply_markup=keyboard)
Ejemplo n.º 4
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

    message.edit_text(get_datepicker_text(poll),
                      parse_mode="markdown",
                      reply_markup=keyboard)
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
def update_datepicker(context, poll):
    """Update the creation datepicker."""
    user = context.user
    if poll.created and poll.user != user:
        keyboard = get_external_datepicker_keyboard(context.poll)
    elif poll.created and poll.user == user:
        if poll.user.expected_input == ExpectedInput.due_date.name:
            context.query.message.edit_reply_markup(
                reply_markup=get_due_date_datepicker_keyboard(context.poll))
            return
        else:
            keyboard = get_add_option_datepicker_keyboard(context.poll)
    elif not poll.created:
        keyboard = get_creation_datepicker_keyboard(context.poll)
    else:
        raise Exception('Unknown update constellation in datepicker')

    context.query.message.edit_text(get_datepicker_text(context.poll),
                                    parse_mode='markdown',
                                    reply_markup=keyboard)
Ejemplo n.º 7
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)