Skip to content

Commit

Permalink
fix(votepeloclima): preserve commas in milestones without splitting e…
Browse files Browse the repository at this point in the history
…ntries
  • Loading branch information
sergiomario committed Aug 30, 2024
1 parent be4c544 commit b0bc00a
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 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 @@ -287,26 +288,24 @@ def media(self):
"js/inline-array-widget.js",
],
)

def decompress(self, value):
if isinstance(value, list):
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

0 comments on commit b0bc00a

Please sign in to comment.