Skip to content

Commit

Permalink
Merge branch 'update-form'
Browse files Browse the repository at this point in the history
  • Loading branch information
shonenada committed Feb 21, 2019
2 parents f630beb + 49b739a commit 3831ea3
Show file tree
Hide file tree
Showing 12 changed files with 221 additions and 256 deletions.
108 changes: 51 additions & 57 deletions stalls/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PROJECT VERSION\n"
"Report-Msgid-Bugs-To: EMAIL@ADDRESS\n"
"POT-Creation-Date: 2019-02-20 23:56+0800\n"
"POT-Creation-Date: 2019-02-21 22:27+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -28,15 +28,15 @@ msgid "Operation Failed"
msgstr ""

#: stalls/modules/poll/api.py:88 stalls/modules/poll/api.py:108
#: stalls/modules/poll/service.py:194
#: stalls/modules/poll/service.py:168
msgid "Invalid Poll"
msgstr ""

#: stalls/modules/poll/api.py:91 stalls/modules/poll/api.py:111
msgid "Poll Expired"
msgstr ""

#: stalls/modules/poll/api.py:95 stalls/modules/poll/service.py:198
#: stalls/modules/poll/api.py:95 stalls/modules/poll/service.py:172
msgid "You have voted"
msgstr ""

Expand All @@ -49,111 +49,105 @@ msgstr ""
msgid "Success"
msgstr ""

#: stalls/modules/poll/message.py:11
msgid "Create Poll"
msgstr ""

#: stalls/modules/poll/form/setup_option_count.py:36
#: stalls/modules/poll/service.py:35 stalls/modules/poll/service.py:66
#: stalls/modules/poll/service.py:72
#: stalls/modules/poll/service.py:32 stalls/modules/poll/service.py:46
msgid "Cancel"
msgstr ""

#: stalls/modules/poll/service.py:44 stalls/modules/poll/service.py:85
#: stalls/modules/poll/service.py:41 stalls/modules/poll/service.py:59
msgid "Parameters Error"
msgstr ""

#: stalls/modules/poll/service.py:47
#, python-format
msgid "Your are creating a poll with %(count)d options"
#: stalls/modules/poll/service.py:69
msgid "Invalid Expiration"
msgstr ""

#: stalls/modules/poll/form/show_poll.py:20 stalls/modules/poll/service.py:50
msgid "Description"
#: stalls/modules/poll/service.py:159
msgid "Please Choose Your Option"
msgstr ""

#: stalls/modules/poll/service.py:55
#, python-format
msgid "Option %(idx)d"
#: stalls/modules/poll/service.py:164
msgid "Invalid Option"
msgstr ""

#: stalls/modules/poll/service.py:59
msgid "Public or Anonymous"
#: stalls/modules/poll/service.py:182
msgid "Opeartion Success"
msgstr ""

#: stalls/modules/poll/form/create_poll.py:14
#, python-format
msgid "Your are creating a poll with %(count)d options"
msgstr ""

#: stalls/modules/poll/service.py:60
msgid "Public"
#: stalls/modules/poll/form/create_poll.py:17
msgid "Poll Name"
msgstr ""

#: stalls/modules/poll/service.py:61
msgid "Anonymous"
#: stalls/modules/poll/form/create_poll.py:22
#, python-format
msgid "Option %(idx)d"
msgstr ""

#: stalls/modules/poll/service.py:62
msgid "Expiration"
#: stalls/modules/poll/form/create_poll.py:27
msgid "Poll Expiration"
msgstr ""

#: stalls/modules/poll/service.py:63
#: stalls/modules/poll/form/create_poll.py:29
msgid "Target Channel"
msgstr ""

#: stalls/modules/poll/form/setup_option_count.py:35
#: stalls/modules/poll/form/show_poll.py:25 stalls/modules/poll/service.py:65
msgid "Confirm"
#: stalls/modules/poll/form/create_poll.py:31
msgid "Create and Send Poll"
msgstr ""

#: stalls/modules/poll/service.py:95
msgid "Invalid Expiration"
#: stalls/modules/poll/form/setup_option_count.py:11
#, python-format
msgid "with %(num)d options"
msgstr ""

#: stalls/modules/poll/service.py:185
msgid "Please Choose Your Option"
#: stalls/modules/poll/form/setup_option_count.py:17
msgid "Your are creating a poll, how many options do you want?"
msgstr ""

#: stalls/modules/poll/service.py:190
msgid "Invalid Option"
#: stalls/modules/poll/form/setup_option_count.py:20
msgid "Option Count"
msgstr ""

#: stalls/modules/poll/service.py:208
msgid "Opeartion Success"
#: stalls/modules/poll/form/setup_option_count.py:21
msgid "Please select the number of options"
msgstr ""

#: stalls/modules/poll/form/setup_option_count.py:12
msgid "Your are creating a poll, how many options do you want?"
#: stalls/modules/poll/form/setup_option_count.py:24
msgid "Next"
msgstr ""

#: stalls/modules/poll/form/setup_option_count.py:15
msgid "Option Count"
#: stalls/modules/poll/form/show_poll.py:20
msgid "Description"
msgstr ""

#: stalls/modules/poll/form/setup_option_count.py:17
#: stalls/modules/poll/form/setup_option_count.py:19
#: stalls/modules/poll/form/setup_option_count.py:21
#: stalls/modules/poll/form/setup_option_count.py:23
#: stalls/modules/poll/form/setup_option_count.py:25
#: stalls/modules/poll/form/setup_option_count.py:27
#: stalls/modules/poll/form/setup_option_count.py:29
#: stalls/modules/poll/form/setup_option_count.py:31
#, python-format
msgid "with %(num)d options"
#: stalls/modules/poll/form/show_poll.py:24
msgid "Confirm"
msgstr ""

#: stalls/modules/poll/form/show_poll_result.py:18
msgid "You have not joined any polls yet"
msgstr ""

#: stalls/modules/poll/form/show_poll_result.py:22
#: stalls/modules/poll/form/show_poll_result.py:35
#: stalls/modules/poll/form/show_poll_result.py:37
msgid "Polls I Created"
msgstr ""

#: stalls/modules/poll/form/show_poll_result.py:26
#: stalls/modules/poll/form/show_poll_result.py:48
#: stalls/modules/poll/form/show_poll_result.py:51
msgid "Polls I Joined"
msgstr ""

#: stalls/modules/poll/form/show_poll_result.py:39
#: stalls/modules/poll/form/show_poll_result.py:52
#: stalls/modules/poll/form/show_poll_result.py:40
#: stalls/modules/poll/form/show_poll_result.py:53
msgid "View Result"
msgstr ""

#: stalls/modules/poll/form/start.py:13
msgid "Create Poll"
msgstr ""

24 changes: 12 additions & 12 deletions stalls/modules/poll/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
create_show_created_poll_result_form,
create_show_joined_poll_result_form)
from stalls.modules.poll.form.start import getting_start
from stalls.modules.poll.message import make_error
from stalls.modules.poll.form.create_error import create_error
from stalls.modules.poll.model.poll import Poll, UserSelection
from stalls.modules.poll.service import process_create, process_vote
from stalls.modules.poll.utils import (create_result_chart,
Expand Down Expand Up @@ -74,7 +74,7 @@ def handle_poll():
response = process_create(payload)
if response is None:
logging.getLogger('poll').info('none respond')
return json_response(make_error(_('Operation Failed')))
return json_response(create_error(_('Operation Failed')))
return json_response(response)


Expand All @@ -85,14 +85,14 @@ def get_poll():
user_id = args['user_id']
poll = Poll.query.get(id_)
if poll is None:
return json_response(make_error(_('Invalid Poll')))
return json_response(create_error(_('Invalid Poll')))

if datetime.utcnow() > poll.end_datetime:
return json_response(make_error(_('Poll Expired')))
return json_response(create_error(_('Poll Expired')))

us = UserSelection.get_by_poll_id_and_user_id(poll.id, user_id)
if us:
return json_response(make_error(_('You have voted')))
return json_response(create_error(_('You have voted')))

response = create_show_poll_form(poll)

Expand All @@ -105,18 +105,18 @@ def do_poll():
id_ = args['poll_id']
poll = Poll.query.get(id_)
if poll is None:
return json_response(make_error(_('Invalid Poll')))
return json_response(create_error(_('Invalid Poll')))

if datetime.utcnow() > poll.end_datetime:
return json_response(make_error(_('Poll Expired')))
return json_response(create_error(_('Poll Expired')))

payload = deepcopy(request.json)
payload.update(args.to_dict())

response = process_vote(payload)
if response is None:
logging.getLogger('poll').info('none respond')
return json_response(make_error(_('Operation Failed')))
return json_response(create_error(_('Operation Failed')))
return json_response(response)


Expand Down Expand Up @@ -172,10 +172,10 @@ def show_poll_result():
}
resp = send_message_to_bearychat(token, data)
if 'error' in resp:
return json_response(make_error(_('Operation Failed')))
return json_response(create_error(_('Operation Failed')))
else:
return json_response(make_error(_('Operation Failed')))
return json_response(create_error(_('Operation Failed')))

return json_response(make_error(_('Success')))
return json_response(create_error(_('Success')))

return json_response(make_error(_('Operation Failed')))
return json_response(create_error(_('Operation Failed')))
1 change: 1 addition & 0 deletions stalls/modules/poll/form/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .create_poll import create_poll_form # noqa
from .create_error import create_error # noqa
from .setup_option_count import create_setup_option_form # noqa
from .show_poll import create_show_poll_form # noqa
from .show_poll_result import (create_ready_show_poll_result_form, # noqa
Expand Down
14 changes: 14 additions & 0 deletions stalls/modules/poll/form/create_error.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-

from flask_babel import gettext as _

from component import Form, Section, Input
from component import Select, SelectOption
from component import ChannelSelect, MemberSelect, DateSelect
from component import PrimarySubmit, DangerSubmit


def create_error(msg):
form = Form()
form.add_action(Section(value=msg))
return form.render()
19 changes: 6 additions & 13 deletions stalls/modules/poll/form/create_poll.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,21 @@ def create_poll_form(option_count):
Section(value=_('Your are creating a poll with %(count)d options',
count=option_count)),

Input(label=_('Description'), name='description'),
Input(label=_('Poll Name'), name='description'),

Input(name='option_count', hidden=True))

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

form.add_actions(
Select(name='is_anonymous', label=_('Public or Anonymous'),
options=[SelectOption(text=_('Public'), value=False),
SelectOption(text=_('Anonymous'), value=True)]),
DateSelect(name='end_datetime', label=_('Poll Expiration')),

DateSelect(name='end_datetime', label=_('Expiration')),
ChannelSelect(name='channels', label=_('Target Channel'), multi=True),

ChannelSelect(name='channel', label=_('Target Channel'), multi=True),

MemberSelect(name='member', label=_('Target Member'), multi=True),

PrimarySubmit(name='poll/confirm-create', text=_('Confirm')),

DangerSubmit(name='poll/cancel-create', text=_('Cancel')))
Submit(name='poll/confirm-create', text=_('Create and Send Poll')),
)

return form.render()
5 changes: 2 additions & 3 deletions stalls/modules/poll/form/setup_option_count.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ def create_setup_option_form():
'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)]),

PrimarySubmit(name='poll/select-option-count', text=_('Confirm')),

DangerSubmit(name='poll/cancel-select-option-count', text=_('Cancel')),
Submit(name='poll/select-option-count', text=_('Next')),
)
return form.render()
29 changes: 0 additions & 29 deletions stalls/modules/poll/message.py

This file was deleted.

Loading

0 comments on commit 3831ea3

Please sign in to comment.