Skip to content

Commit

Permalink
Merge pull request #275 from nossas/hotfix/bad-behavior-inline-widget
Browse files Browse the repository at this point in the history
Preserve commas in milestones without splitting entries
  • Loading branch information
igr-santos authored Aug 30, 2024
2 parents 353097c + 51a4bb2 commit 277b360
Showing 1 changed file with 9 additions and 10 deletions.
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

0 comments on commit 277b360

Please sign in to comment.