mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-07 23:28:25 -04:00
Rewrite SMS ratio form to cope with 3 providers
This replaces the slider with an integer input for each provider. Unfortunately showing a variable number of inputs isn't easy to achieve in WTForms [^1], but we think this is the least worst way to do it vs e.g. not using WTForms at all. [^1]: https://github.com/wtforms/wtforms/issues/736
This commit is contained in:
@@ -54,23 +54,21 @@ def edit_sms_provider_ratio():
|
||||
and provider['active']
|
||||
], key=itemgetter('identifier'))
|
||||
|
||||
form = AdminProviderRatioForm(ratio=providers[0]['priority'])
|
||||
form = AdminProviderRatioForm(providers)
|
||||
|
||||
if len(providers) < 2:
|
||||
abort(400)
|
||||
|
||||
first_provider, second_provider = providers[0:2]
|
||||
|
||||
if form.validate_on_submit():
|
||||
provider_client.update_provider(first_provider['id'], form.percentage_left)
|
||||
provider_client.update_provider(second_provider['id'], form.percentage_right)
|
||||
for provider in providers:
|
||||
field = getattr(form, provider['identifier'])
|
||||
provider_client.update_provider(provider['id'], field.data)
|
||||
return redirect(url_for('.view_providers'))
|
||||
|
||||
return render_template(
|
||||
'views/providers/edit-sms-provider-ratio.html',
|
||||
form=form,
|
||||
first_provider=providers[0]['display_name'],
|
||||
second_provider=providers[1]['display_name'],
|
||||
providers=providers
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user