Skip to content

Commit

Permalink
Merge pull request #279 from nossas/hotfix/changed-delimiter-inline-f…
Browse files Browse the repository at this point in the history
…ield

fix(votepeloclima): changed inline field delimiter
  • Loading branch information
igr-santos authored Aug 30, 2024
2 parents e0312bd + 8398843 commit 453cedb
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions app/org_eleicoes/votepeloclima/candidature/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 453cedb

Please sign in to comment.