Make handling of None values in forms clearer

If the browser posts the value of `<input value='None'>` to the server
it does so as a string.

We want to post a value of `None` (actually JSON `null`) to the API. To
do this we:
- set the value in the form class to `'None'` (ie a string)
- convert to `None` (as a type) afterwards

However seeing `x = 'None'` in code looks a bit like a mistake. So to
make sure it looks deliberate and clear what is happening this commit:
- makes a reusable constant for `'None'`
- adds a comment explaining why it’s a string
This commit is contained in:
Chris Hill-Scott
2018-11-12 09:04:39 +00:00
parent 74a4400bc7
commit c18a38d4f1
3 changed files with 26 additions and 9 deletions

View File

@@ -813,9 +813,8 @@ def service_preview_email_branding(service_id):
form = ServicePreviewBranding(branding_style=branding_style)
if form.validate_on_submit():
branding_style = None if form.branding_style.data == 'None' else form.branding_style.data
current_service.update(
email_branding=branding_style
email_branding=form.branding_style.data
)
return redirect(url_for('.service_settings', service_id=service_id))