fix: bad value for blank vote and better flow for invalid form

* Add an error message when looking at a public election without being logged in
* Add correct value for blank vote on single vote field
* Redirect to view with an error message if an invalid form has been submitted
This commit is contained in:
2026-01-14 11:30:04 +01:00
parent 8c6f7c82c9
commit 2744282fd8
4 changed files with 55 additions and 29 deletions

View File

@@ -60,8 +60,6 @@ class CandidateForm(forms.ModelForm):
class VoteForm(forms.Form):
def __init__(self, election: Election, user: User, *args, **kwargs):
super().__init__(*args, **kwargs)
if not election.can_vote(user):
return
for role in election.roles.all():
cand = role.candidatures
if role.max_choice > 1:
@@ -74,6 +72,7 @@ class VoteForm(forms.Form):
required=False,
widget=forms.RadioSelect(),
empty_label=_("Blank vote"),
blank=True,
)