Fix pattern generation

This commit is contained in:
Aarni Halinen
2020-06-15 20:02:01 +03:00
parent 0edde936cc
commit 2433c7828d
+6 -6
View File
@@ -119,18 +119,18 @@ class SignupForm(models.Model):
}
elif question_type == "radiobutton":
options = q["options"]
pattern = ""
map(lambda x: pattern.join(f"^{x}$|"), options)
regexes = map(lambda x: f"^{x}$", options)
pattern = "|".join(regexes)
properties[id] = {
"type": "string",
# Remove last regex or
"pattern": pattern[:-1],
"pattern": pattern,
}
elif question_type == "checkbox":
options = q["options"]
pattern = ""
map(lambda x: pattern.join(f"^{x}$|"), options)
regexes = map(lambda x: f"^{x}$", options)
pattern = "|".join(regexes)
properties[id] = {
"type": "array",
@@ -138,7 +138,7 @@ class SignupForm(models.Model):
"maxItems": len(options),
"items": {
"type": "string",
"pattern": pattern[:-1]
"pattern": pattern
}
}
else: raise Exception("invalid question type!")