mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-03-15 08:07:33 +00:00
Linting
This commit is contained in:
parent
25756fb2ef
commit
4181742133
@ -113,8 +113,7 @@ class TestStudentParticipation(TestCase):
|
|||||||
response = self.client.get(reverse("admin:index") + "participation/phase/")
|
response = self.client.get(reverse("admin:index") + "participation/phase/")
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
response = self.client.get(reverse("admin:index")
|
response = self.client.get(reverse("admin:index") + "participation/phase/1/change/")
|
||||||
+ f"participation/phase/1/change/")
|
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
def test_create_team(self):
|
def test_create_team(self):
|
||||||
|
@ -176,16 +176,22 @@ class TeamDetailView(LoginRequiredMixin, FormMixin, ProcessFormView, DetailView)
|
|||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
self.object = self.get_object()
|
self.object = self.get_object()
|
||||||
if isinstance(form, RequestValidationForm):
|
if isinstance(form, RequestValidationForm):
|
||||||
|
return self.handle_request_validation(form)
|
||||||
|
elif isinstance(form, ValidateParticipationForm):
|
||||||
|
return self.handle_validate_participation(form)
|
||||||
|
return self.form_invalid(form)
|
||||||
|
|
||||||
|
def handle_request_validation(self, form):
|
||||||
|
"""
|
||||||
|
A team requests to be validated
|
||||||
|
"""
|
||||||
if not self.request.user.registration.participates:
|
if not self.request.user.registration.participates:
|
||||||
form.add_error(None, _("You don't participate, so you can't request the validation of the team."))
|
form.add_error(None, _("You don't participate, so you can't request the validation of the team."))
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
if self.object.participation.valid is not None:
|
if self.object.participation.valid is not None:
|
||||||
form.add_error(None, _("The validation of the team is already done or pending."))
|
form.add_error(None, _("The validation of the team is already done or pending."))
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
if not (self.object.students.count() >= 3 and
|
if not self.get_context_data()["can_validate"]:
|
||||||
all(r.email_confirmed for r in self.object.students.all()) and
|
|
||||||
all(r.photo_authorization for r in self.object.students.all()) and
|
|
||||||
self.object.participation.problem):
|
|
||||||
form.add_error(None, _("The team can't be validated: missing email address confirmations, "
|
form.add_error(None, _("The team can't be validated: missing email address confirmations, "
|
||||||
"photo authorizations, people or the chosen problem is not set."))
|
"photo authorizations, people or the chosen problem is not set."))
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
@ -198,7 +204,12 @@ class TeamDetailView(LoginRequiredMixin, FormMixin, ProcessFormView, DetailView)
|
|||||||
mail_plain = render_to_string("participation/mails/request_validation.txt", mail_context)
|
mail_plain = render_to_string("participation/mails/request_validation.txt", mail_context)
|
||||||
mail_html = render_to_string("participation/mails/request_validation.html", mail_context)
|
mail_html = render_to_string("participation/mails/request_validation.html", mail_context)
|
||||||
admin.user.email_user("[Corres2math] Validation d'équipe", mail_plain, html_message=mail_html)
|
admin.user.email_user("[Corres2math] Validation d'équipe", mail_plain, html_message=mail_html)
|
||||||
elif isinstance(form, ValidateParticipationForm):
|
return self.form_valid(form)
|
||||||
|
|
||||||
|
def handle_validate_participation(self, form):
|
||||||
|
"""
|
||||||
|
An admin validates the team (or not)
|
||||||
|
"""
|
||||||
if not self.request.user.registration.is_admin:
|
if not self.request.user.registration.is_admin:
|
||||||
form.add_error(None, _("You are not an administrator."))
|
form.add_error(None, _("You are not an administrator."))
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
@ -224,7 +235,6 @@ class TeamDetailView(LoginRequiredMixin, FormMixin, ProcessFormView, DetailView)
|
|||||||
else:
|
else:
|
||||||
form.add_error(None, _("You must specify if you validate the registration or not."))
|
form.add_error(None, _("You must specify if you validate the registration or not."))
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
from django.contrib.sites.models import Site
|
|
||||||
|
|
||||||
from corres2math.tokens import email_validation_token
|
from corres2math.tokens import email_validation_token
|
||||||
from django.contrib.contenttypes.models import ContentType
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
from django.contrib.sites.models import Site
|
||||||
from django.core.management import call_command
|
from django.core.management import call_command
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
Loading…
x
Reference in New Issue
Block a user