Browse Source

fix(widget): gère la possible absence de valeur dans un multiwidget

pull/52/head
François Poulain 7 months ago
parent
commit
85e59d5eb1
  1. 7
      gvot/base/form_builder.py

7
gvot/base/form_builder.py

@ -99,18 +99,19 @@ class PonderatedField(forms.MultiValueField):
)
def compress(self, data_list):
if self.required and sum(data_list) < self.ponderation:
cleaned_data = [i or 0 for i in data_list]
if self.required and sum(cleaned_data) < self.ponderation:
raise ValidationError(
"Vous devez affecter tous les choix disponibles "
"parmi les options proposées."
)
if sum(data_list) > self.ponderation:
if sum(cleaned_data) > self.ponderation:
raise ValidationError(
"Vous ne pouvez pas affecter plus de choix que "
"le nombre de mandats disponibles."
)
return ','.join([str(i) for i in data_list])
return ','.join([str(i) for i in cleaned_data])
class MyFormBuilder(FormBuilder):

Loading…
Cancel
Save
Map all the world