From 8398843b85be1a01bbb763f7eb103a70c3335c16 Mon Sep 17 00:00:00 2001 From: Mario Sergio Date: Fri, 30 Aug 2024 19:56:40 -0300 Subject: [PATCH] fix(votepeloclima): changed inline field delimiter --- .../votepeloclima/candidature/fields.py | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/app/org_eleicoes/votepeloclima/candidature/fields.py b/app/org_eleicoes/votepeloclima/candidature/fields.py index 955e05b9..12e6ec2b 100644 --- a/app/org_eleicoes/votepeloclima/candidature/fields.py +++ b/app/org_eleicoes/votepeloclima/candidature/fields.py @@ -294,18 +294,21 @@ def decompress(self, value): return value if value is None: return [] - try: - return json.loads(value) - except json.JSONDecodeError: - return [] + + return [v.strip() for v in value.split("|")] def value_from_datadict(self, data, files, name): values = [] - for key, value in data.items(): - if key.startswith(f"{name}_") and value.strip(): - values.append(value.strip()) - return json.dumps(values) + # Used when save values in model like a list + if name in data: + values = data.get(name) + else: + for key, value in data.items(): + if key.startswith(f"{name}_"): + values.append(value) + + return values def get_context(self, name, value, attrs): context = super().get_context(name, value, attrs) @@ -357,7 +360,7 @@ def __init__( size=5, item_label=None, add_button_text=None, - delimiter=",", + delimiter="|", max_length=None, min_length=None, placeholder=None,