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):
|
||||
|
||||
Reference in new issue
Block a user