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

Preserve commas in milestones without splitting entries #275

Merged
merged 2 commits into from
Aug 30, 2024
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
19 changes: 9 additions & 10 deletions app/org_eleicoes/votepeloclima/candidature/fields.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import sys

from django import forms
Expand Down Expand Up @@ -293,20 +294,18 @@ def decompress(self, value):
return value
if value is None:
return []
return [v.strip() for v in value.split(",")]
try:
return json.loads(value)
except json.JSONDecodeError:
return []

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())

# 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
return json.dumps(values)

def get_context(self, name, value, attrs):
context = super().get_context(name, value, attrs)
Expand Down
Loading