From 2433c7828dfb3a0d761f9d518b5c8d7e8995d0a4 Mon Sep 17 00:00:00 2001 From: Aarni Halinen Date: Mon, 15 Jun 2020 20:02:01 +0300 Subject: [PATCH] Fix pattern generation --- webapp/models.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/webapp/models.py b/webapp/models.py index f81f8f7..f60e026 100644 --- a/webapp/models.py +++ b/webapp/models.py @@ -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!")