mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-18 21:49:37 -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:
@@ -1740,29 +1740,26 @@ class EstimateUsageForm(StripWhitespaceForm):
|
||||
return super().validate(*args, **kwargs)
|
||||
|
||||
|
||||
class AdminProviderRatioForm(StripWhitespaceForm):
|
||||
class AdminProviderRatioForm(Form):
|
||||
def __init__(self, providers):
|
||||
# hack: https://github.com/wtforms/wtforms/issues/736
|
||||
self._unbound_fields = [
|
||||
(
|
||||
provider['identifier'],
|
||||
GovukIntegerField(
|
||||
provider['display_name'],
|
||||
validators=[validators.NumberRange(
|
||||
min=0, max=100, message="Must be between 0 and 100"
|
||||
)]
|
||||
)
|
||||
) for provider in providers
|
||||
]
|
||||
|
||||
ratio = GovukRadiosField(choices=[
|
||||
(str(value), '{}% / {}%'.format(value, 100 - value))
|
||||
for value in range(100, -10, -10)
|
||||
],
|
||||
param_extensions={
|
||||
"classes": "govuk-radios--inline",
|
||||
"fieldset": {
|
||||
"legend": {
|
||||
"classes": "govuk-visually-hidden"
|
||||
}
|
||||
}
|
||||
super().__init__(data={
|
||||
provider['identifier']: provider['priority']
|
||||
for provider in providers
|
||||
})
|
||||
|
||||
@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(
|
||||
|
||||
Reference in New Issue
Block a user