Add a new boolean radios fields and change forms to use it

This adds a new OnOffField class that implements a boolean field
that is rendered as two On / Off radio buttons. This allows us to
avoid comparing 'on' and 'off' string values in the views since
the field takes care of transforming form data into python booleans.

This also adds a form class that can be used for any single On / Off
switch forms (e.g. service permissions).
This commit is contained in:
Alexey Bezhan
2019-02-18 16:27:53 +00:00
parent ddbd4380c9
commit 75fd2d4ffc
3 changed files with 31 additions and 17 deletions

View File

@@ -518,13 +518,13 @@ def service_set_channel(service_id, channel):
form = ServiceSwitchChannelForm(
channel=channel,
enabled='on' if current_service.has_permission(channel) else 'off'
enabled=current_service.has_permission(channel)
)
if form.validate_on_submit():
current_service.force_permission(
channel,
on=(form.enabled.data == 'on'),
on=form.enabled.data,
)
return redirect(
url_for(".service_settings", service_id=service_id)