Consolidate callback forms and convert them to gov uk frontend

We had two identical callback form classes. One for delivery callbacks
and one for inbound sms callbacks. Since they did not differ I consolidated
them into one CallbackForm class that they both inherited from previously.

I also substituted field classes for this form with new fields
that cooperate with gov uk frontend.
This commit is contained in:
Pea Tyczynska
2020-08-03 15:10:02 +01:00
committed by Tom Byers
parent 6f1fc3d16d
commit be7d4891ae
5 changed files with 36 additions and 63 deletions

View File

@@ -34,7 +34,6 @@ from wtforms import (
TextAreaField,
ValidationError,
validators,
widgets,
)
from wtforms.fields.html5 import EmailField, SearchField, TelField
from wtforms.validators import URL, DataRequired, Length, Optional, Regexp
@@ -1804,10 +1803,6 @@ class PlaceholderForm(StripWhitespaceForm):
pass
class PasswordFieldShowHasContent(StringField):
widget = widgets.PasswordInput(hide_value=False)
class ServiceInboundNumberForm(StripWhitespaceForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@@ -1820,37 +1815,21 @@ class ServiceInboundNumberForm(StripWhitespaceForm):
class CallbackForm(StripWhitespaceForm):
url = GovukTextInputField(
"URL",
validators=[DataRequired(message='Cannot be empty'),
Regexp(regex="^https.*", message='Must be a valid https URL')]
)
bearer_token = GovukPasswordField(
"Bearer token",
validators=[DataRequired(message='Cannot be empty'),
Length(min=10, message='Must be at least 10 characters')]
)
def validate(self):
return super().validate() or self.url.data == ''
class ServiceReceiveMessagesCallbackForm(CallbackForm):
url = StringField(
"URL",
validators=[DataRequired(message='Cannot be empty'),
Regexp(regex="^https.*", message='Must be a valid https URL')]
)
bearer_token = PasswordFieldShowHasContent(
"Bearer token",
validators=[DataRequired(message='Cannot be empty'),
Length(min=10, message='Must be at least 10 characters')]
)
class ServiceDeliveryStatusCallbackForm(CallbackForm):
url = StringField(
"URL",
validators=[DataRequired(message='Cannot be empty'),
Regexp(regex="^https.*", message='Must be a valid https URL')]
)
bearer_token = PasswordFieldShowHasContent(
"Bearer token",
validators=[DataRequired(message='Cannot be empty'),
Length(min=10, message='Must be at least 10 characters')]
)
class InternationalSMSForm(StripWhitespaceForm):
enabled = RadioField(
'Send text messages to international phone numbers',