Warn administrators when a team is requesting validation

This commit is contained in:
Yohann D'ANELLO 2020-10-11 17:40:18 +02:00
parent 15d096a328
commit 3c8615b487
3 changed files with 46 additions and 2 deletions

View File

@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Demande de validation - Correspondances des Jeunes Mathématicien·ne·s</title>
</head>
<body>
<p>
Bonjour {{ user.registration }},
</p>
<p>
L'équipe « {{ team.name }} » ({{ team.trigram }}) vient de demander à valider son équipe pour participer
au {{ team.participation.get_problem_display }} des Correspondances des Jeunes Mathématicien·ne·s.
Vous pouvez décider d'accepter ou de refuser l'équipe en vous rendant sur la page de l'équipe :
<a href="{% url "participation:team_detail" pk=team.pk %}">{% url "participation:team_detail" pk=team.pk %}</a>
</p>
<p>
Cordialement,
</p>
<p>
L'organisation des Correspondances des Jeunes Mathématicien·ne·s
</p>
</body>
</html>

View File

@ -0,0 +1,10 @@
Bonjour {{ user.registration }},
L'équipe « {{ team.name }} » ({{ team.trigram }}) vient de demander à valider son équipe pour participer
au {{ team.participation.get_problem_display }} des Correspondances des Jeunes Mathématicien·ne·s.
Vous pouvez décider d'accepter ou de refuser l'équipe en vous rendant sur la page de l'équipe :
{% url "participation:team_detail" pk=team.pk %}
Cordialement,
L'organisation des Correspondances des Jeunes Mathématicien·ne·s

View File

@ -6,11 +6,13 @@ from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.exceptions import PermissionDenied
from django.db import transaction
from django.http import HttpResponse
from django.shortcuts import redirect
from django.template.loader import render_to_string
from django.urls import reverse_lazy
from django.utils.translation import gettext_lazy as _
from django.views.generic import CreateView, DetailView, FormView, RedirectView, UpdateView
from django.shortcuts import redirect
from magic import Magic
from registration.models import AdminRegistration
from .forms import JoinTeamForm, ParticipationForm, TeamForm, UploadVideoForm
from .models import Participation, Team, Video
@ -101,8 +103,13 @@ class TeamDetailView(LoginRequiredMixin, DetailView):
if request.user.registration.participates:
if "request-validation" in request.POST:
request.user.registration.team.participation.valid = False
# TODO Send mail to admins
request.user.registration.team.participation.save()
for admin in AdminRegistration.objects.all():
mail_context = dict(user=admin.user, team=request.user.registration.team)
mail_plain = render_to_string("participation/mails/request_validation.txt", 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)
return redirect(request.path)
def get_context_data(self, **kwargs):