mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-20 14:29:51 -04:00
Add a form to set priority of top 2 providers
Their priority should always add up to 100%. Currently we have to ensure this by hand. Adding this form means there’s no way to not set their combined priorities to 100%. And it’s a bit more of an intuitive UI than two textboxes on separate pages.
This commit is contained in:
@@ -952,6 +952,22 @@ class ProviderForm(StripWhitespaceForm):
|
||||
priority = IntegerField('Priority', [validators.NumberRange(min=1, max=100, message="Must be between 1 and 100")])
|
||||
|
||||
|
||||
class ProviderRatioForm(StripWhitespaceForm):
|
||||
|
||||
ratio = RadioField(choices=[
|
||||
(str(value), '{}% / {}%'.format(value, 100 - value))
|
||||
for value in range(100, -10, -10)
|
||||
])
|
||||
|
||||
@property
|
||||
def percentage_left(self):
|
||||
return int(self.ratio.data)
|
||||
|
||||
@property
|
||||
def percentage_right(self):
|
||||
return 100 - self.percentage_left
|
||||
|
||||
|
||||
class ServiceContactDetailsForm(StripWhitespaceForm):
|
||||
contact_details_type = RadioField(
|
||||
'Type of contact details',
|
||||
|
||||
@@ -7,7 +7,7 @@ from werkzeug.utils import redirect
|
||||
|
||||
from app import format_date_numeric, provider_client
|
||||
from app.main import main
|
||||
from app.main.forms import ProviderForm
|
||||
from app.main.forms import ProviderForm, ProviderRatioForm
|
||||
from app.utils import user_is_platform_admin
|
||||
|
||||
PROVIDER_PRIORITY_MEANING_SWITCHOVER = datetime(2019, 11, 29, 11, 0)
|
||||
@@ -67,12 +67,19 @@ def edit_sms_provider_ratio():
|
||||
if provider['notification_type'] == 'sms'
|
||||
], key=itemgetter('identifier'), reverse=True)
|
||||
|
||||
form = ProviderRatioForm(ratio=providers[0]['priority'])
|
||||
|
||||
if form.validate_on_submit():
|
||||
provider_client.update_provider(providers[0]['id'], form.percentage_left)
|
||||
provider_client.update_provider(providers[1]['id'], form.percentage_right)
|
||||
|
||||
if len(providers) < 2:
|
||||
abort(400)
|
||||
|
||||
return render_template(
|
||||
'views/providers/edit-sms-provider-ratio.html',
|
||||
versions=_chunk_versions_by_day(_get_versions(providers[0], providers[1])),
|
||||
form=form,
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user