On ne peut pas ouvrir l'élection si le mail d'annonce a été envoyé
This commit is contained in:
parent
d3df3ac037
commit
3af0ab9971
3 changed files with 23 additions and 1 deletions
|
@ -22,6 +22,15 @@ class ElectionForm(forms.ModelForm):
|
|||
self.add_error(
|
||||
"end_date", _("Impossible de terminer l'élection avant de la commencer")
|
||||
)
|
||||
|
||||
if self.instance.sent_mail and not cleaned_data["restricted"]:
|
||||
self.add_error(
|
||||
"restricted",
|
||||
_(
|
||||
"Le mail d'annonce a déjà été envoyé, il n'est pas possible "
|
||||
"d'ouvrir l'élection à tout le monde"
|
||||
),
|
||||
)
|
||||
return cleaned_data
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -196,9 +196,22 @@ class ElectionUpdateView(CreatorOnlyEditMixin, SuccessMessageMixin, UpdateView):
|
|||
success_message = _("Élection modifiée avec succès !")
|
||||
template_name = "elections/election_update.html"
|
||||
|
||||
def get_form(self, form_class=None):
|
||||
form = super().get_form(form_class)
|
||||
if self.object.sent_mail:
|
||||
form.fields["restricted"].disabled = True
|
||||
return form
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse("election.admin", args=[self.object.pk])
|
||||
|
||||
def form_valid(self, form):
|
||||
# Si on ouvre l'élection à tout le monde, on supprime les votant·e·s
|
||||
# pré-enregistré·e·s
|
||||
if not form.cleaned_data["restricted"]:
|
||||
self.object.registered_voters.all().delete()
|
||||
return super().form_valid(form)
|
||||
|
||||
|
||||
class DeleteVoteView(ClosedElectionMixin, FormView):
|
||||
model = Election
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<div class="control">
|
||||
{% if field.auto_id %}
|
||||
<label class="checkbox {% if field.field.required %}{{ form.required_css_class }}{% endif %}">
|
||||
<label class="checkbox {% if field.field.required %}{{ form.required_css_class }}{% endif %}" {% if field.field.disabled %}disabled="" {% endif %}>
|
||||
{{ field }} {{ field.label }}
|
||||
</label>
|
||||
{% endif %}
|
||||
|
|
Loading…
Reference in a new issue