forbid banned user to be candidates in elections

This commit is contained in:
imperosol committed 2026-11-27 11:05:31 +01:00
1 parent 96800a249d
commit 6bb1a049c6
2 files changed
+25 -4

No files matched your search

+19 -3
View File
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING
from django import forms from django import forms
from django.conf import settings from django.conf import settings
from django.core.exceptions import ValidationError
from django.db import transaction from django.db import transaction
from django.db.models import Count from django.db.models import Count
from django.forms.models import ModelChoiceIterator, ModelChoiceIteratorValue from django.forms.models import ModelChoiceIterator, ModelChoiceIteratorValue
@@ -54,9 +55,7 @@ class CandidateForm(forms.ModelForm):
class Meta: class Meta:
model = Candidature model = Candidature
fields = ["user", "role", "program", "election_list"] fields = ["user", "role", "program", "election_list"]
labels = { labels = {"user": _("User to candidate")}
"user": _("User to candidate"),
}
widgets = { widgets = {
"program": MarkdownInput, "program": MarkdownInput,
"user": AutoCompleteSelectUser, "user": AutoCompleteSelectUser,
@@ -71,6 +70,23 @@ class CandidateForm(forms.ModelForm):
if not can_edit: if not can_edit:
self.fields["user"].widget = forms.HiddenInput() self.fields["user"].widget = forms.HiddenInput()
def clean_user(self):
user = self.cleaned_data.get("user")
if (
user
and user.ban_groups.filter(
id__in=[
settings.SITH_GROUP_BANNED_RESPONSIBILITY_ID,
settings.SITH_GROUP_BANNED_SUBSCRIPTION_ID,
]
).exists()
):
raise ValidationError(
_("%(user)s is forbidden to run in a election.")
% {"user": user.get_full_name()}
)
return user
class VoteForm(forms.Form): class VoteForm(forms.Form):
def __init__(self, election: Election, user: User, *args, **kwargs): def __init__(self, election: Election, user: User, *args, **kwargs):
+6 -1
View File
@@ -6,7 +6,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-11-22 22:06+0100\n" "POT-Creation-Date: 2026-11-27 11:02+0100\n"
"PO-Revision-Date: 2016-07-18\n" "PO-Revision-Date: 2016-07-18\n"
"Last-Translator: Maréchal <thomas.girod@utbm.fr\n" "Last-Translator: Maréchal <thomas.girod@utbm.fr\n"
"Language-Team: AE info <ae.info@utbm.fr>\n" "Language-Team: AE info <ae.info@utbm.fr>\n"
@@ -4570,6 +4570,11 @@ msgstr "Vous avez sélectionné trop de candidats."
msgid "User to candidate" msgid "User to candidate"
msgstr "Utilisateur se présentant" msgstr "Utilisateur se présentant"
#: election/forms.py
#, python-format
msgid "%(user)s is forbidden to run in a election."
msgstr "%(user)s n'a pas le droit de se présenter à une élection."
#: election/forms.py election/templates/election/election_detail.jinja #: election/forms.py election/templates/election/election_detail.jinja
msgid "Blank vote" msgid "Blank vote"
msgstr "Vote blanc" msgstr "Vote blanc"