Exemplo n.º 1
0
def make_start_form(visit_key):
    form = Form()
    form.add_actions(
        Section(value=_('Create poll by clicking following button')),
        Submit(name=submit.SETUP_FORM, text=_('Create Poll')))

    return form.render()
Exemplo n.º 2
0
def make_poll_form(option_count):
    form = Form()
    form.add_actions(
        Section(value=_('Your are creating a poll with %(count)d options',
                        count=option_count)),
        Input(label=_('Poll Name'), name='description'),
        Input(name='option_count', hidden=True, value=option_count))

    for each in range(option_count):
        label = _("Option %(idx)d", idx=(each + 1))
        name = "option_{}".format(each + 1)
        form.add_action(Input(name=name, label=label))

    form.add_actions(
        DateSelect(name='end_timestamp',
                   label=_('Poll Expiration'),
                   placeholder=_('Select Expiration')),
        ChannelSelect(name='channels',
                      label=_('Target Channel'),
                      placeholder=_('Select Target Channels'),
                      multi=True),
        PrimarySubmit(name=submit.CONFIRM_CREATE,
                      text=_('Create and Send Poll')),
    )

    return form.render()
Exemplo n.º 3
0
def show_created_polls(user_id):
    polls = Poll.get_multi_by_user_id(user_id)
    options = [
        SelectOption(text=each.description, value=each.id) for each in polls
    ]
    form = Form()
    form.add_actions(
        Select(label=_('Polls I Created'),
               required=True,
               name='poll_id',
               placeholder=_('Choose poll'),
               options=options),
        Submit(name=submit.SHOW_RESULT, text=_('View Result')))
    return form.render()
Exemplo n.º 4
0
def make_option_count_form():
    def build_option(num):
        return SelectOption(text=_('with %(num)d options', num=num),
                            value=str(num))

    form = Form()
    form.add_actions(
        Section(value=_('Your are creating a poll, '
                        'how many options do you want?')),
        Select(name='option_count',
               label=_('Option Count'),
               placeholder=_('Please select the number of options'),
               options=[build_option(n) for n in range(2, 9 + 1)]),
        Submit(name=submit.SELECT_OPTION_COUNT, text=_('Next')),
    )
    return form.render()
Exemplo n.º 5
0
def make_ready_form(user_id):
    created_poll_count = Poll.count_by_user_id(user_id)
    joined_poll_count = UserSelection.count_by_user_id(user_id)

    form = Form()

    if created_poll_count + joined_poll_count == 0:
        form.add_action(Section(value=_("You have not joined any polls yet")))

    if created_poll_count > 0:
        form.add_action(
            Submit(name=submit.SHOW_CREATED_RESULT, text=_('Polls I Created')))

    if joined_poll_count > 0:
        form.add_action(
            Submit(name=submit.SHOW_CREATED_RESULT, text=_('Polls I Joined')))

    return form.render()
Exemplo n.º 6
0
def show_poll(poll):
    poll_options = PollOption.get_multi_by_poll_id(poll.id)

    options = [
        SelectOption(text=each.label, value=str(each.id))
        for each in poll_options
    ]

    form = Form()
    form.add_actions(
        Section(value=_('Poll Name: %(description)s',
                        description=poll.description)),
        Section(value=_('Poll Expiration: %(expiration)s',
                        expiration=poll.end_datetime.strftime(
                            "%Y-%m-%d %H:%M:%S"))),
        Select(name="poll_option",
               options=options,
               placeholder=_('Please Choose your option')),
        PrimarySubmit(name=submit.CONFIRM_POLL, text=_('Confirm')),
    )

    return form.render()
Exemplo n.º 7
0
def show_poll_result(poll):
    form = Form()
    context = Context()
    context.append(_('Poll Created'))

    form.add_actions(
        context,
        Input(value=poll.visit_key, name='token', hidden=True),
        Section(value=_('Poll Name: %(description)s',
                        description=poll.description)),
        Section(value=_('Poll Expiration: %(expiration)s',
                        expiration=poll.end_datetime.strftime(
                            "%Y-%m-%d %H:%M:%S"))),
    )

    poll_options = PollOption.get_multi_by_poll_id(poll.id)

    for idx, each in enumerate(poll_options):
        form.add_action(Section(value='{}. {}'.format(idx + 1, each.label)))

    result_text = Context()
    result_text.append(_('Poll Result'))

    form.add_action(result_text)

    image_url = url_for('poll.preview_poll',
                        poll_id=poll.id,
                        token=poll.visit_key,
                        ts=time.time(),
                        _external=True)

    form.add_actions(Image(title=_('Poll Result'), url=image_url),
                     Submit(name=submit.REFRESH, text=_('Refresh')))

    return form.render()
Exemplo n.º 8
0
def make_msg(msg, submit=None):
    form = Form()
    form.add_action(Section(value=msg))
    if submit:
        form.add_action(Submit(**submit))
    return form.render()