mirror of
https://github.com/ae-utbm/sith.git
synced 2026-11-27 19:32:48 +00:00
forbid banned user to be candidates in elections
This commit is contained in:
1 parent
96800a249d
commit
6bb1a049c6
2 files changed
+25
-4
No files matched your search
+19
-3
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING
|
||||
|
||||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import transaction
|
||||
from django.db.models import Count
|
||||
from django.forms.models import ModelChoiceIterator, ModelChoiceIteratorValue
|
||||
@@ -54,9 +55,7 @@ class CandidateForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Candidature
|
||||
fields = ["user", "role", "program", "election_list"]
|
||||
labels = {
|
||||
"user": _("User to candidate"),
|
||||
}
|
||||
labels = {"user": _("User to candidate")}
|
||||
widgets = {
|
||||
"program": MarkdownInput,
|
||||
"user": AutoCompleteSelectUser,
|
||||
@@ -71,6 +70,23 @@ class CandidateForm(forms.ModelForm):
|
||||
if not can_edit:
|
||||
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):
|
||||
def __init__(self, election: Election, user: User, *args, **kwargs):
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"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"
|
||||
"Last-Translator: Maréchal <thomas.girod@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"
|
||||
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
|
||||
msgid "Blank vote"
|
||||
msgstr "Vote blanc"
|
||||
|
||||
Reference in new issue
Block a user