Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(votepeloclima): changed inline field delimiter #279

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading