| |
@@ -365,6 +365,17 @@
|
| |
return False
|
| |
return None
|
| |
|
| |
+
|
| |
+ class EmptyStringToNone:
|
| |
+ """ Transform empty text field to None value """
|
| |
+ def __call__(self, value):
|
| |
+ if value is None:
|
| |
+ return None
|
| |
+ if value.strip() == "":
|
| |
+ return None
|
| |
+ return value
|
| |
+
|
| |
+
|
| |
class CoprFormFactory(object):
|
| |
|
| |
@staticmethod
|
| |
@@ -389,13 +400,15 @@
|
| |
"Homepage",
|
| |
validators=[
|
| |
wtforms.validators.Optional(),
|
| |
- wtforms.validators.URL()])
|
| |
+ wtforms.validators.URL()],
|
| |
+ filters=[EmptyStringToNone()])
|
| |
|
| |
contact = wtforms.StringField(
|
| |
"Contact",
|
| |
validators=[
|
| |
wtforms.validators.Optional(),
|
| |
- EmailOrURL()])
|
| |
+ EmailOrURL()],
|
| |
+ filters=[EmptyStringToNone()])
|
| |
|
| |
description = wtforms.TextAreaField("Description")
|
| |
|
| |
Fix forms.py so the empty string in homepage/contact fields are replaced
with None value. That way we fill the database with correct values
(empty string is invalid) and later we can use python-marshmallow to
serialize the Copr info to be sent via APIv2.
I previously tried to fix similar problem in 00f9473. That fix
worked because the invalid empty string values triggered ValidationError
in all previous versions of marshmallow on dump/serialize (sending data
to user). Newer versions of marshmallow though don't validate()
automatically when serializing, only when deserializing! That's why
don't get ValidationError nowadays, and so even invalid values are sent
to the user.
Well, to be precise - previous marshmallow did validate only the
Email and URL versions before, nothing else [1].
So the effect of this patch is that we'll never got invalid values in
database, and all the existing empty values are migrated to None by
Alembic migration.
[1] https://github.com/marshmallow-code/marshmallow/issues/1132
Fixes: #1588