Merge branch 'dev' into 'master'
Dev See merge request animath/si/plateforme-tfjm!7
This commit is contained in:
commit
641e53e617
|
@ -59,6 +59,21 @@ class ParticipationForm(forms.ModelForm):
|
||||||
fields = ('tournament',)
|
fields = ('tournament',)
|
||||||
|
|
||||||
|
|
||||||
|
class MotivationLetterForm(forms.ModelForm):
|
||||||
|
def clean_file(self):
|
||||||
|
if "file" in self.files:
|
||||||
|
file = self.files["motivation_letter"]
|
||||||
|
if file.size > 2e6:
|
||||||
|
raise ValidationError(_("The uploaded file size must be under 2 Mo."))
|
||||||
|
if file.content_type not in ["application/pdf", "image/png", "image/jpeg"]:
|
||||||
|
raise ValidationError(_("The uploaded file must be a PDF, PNG of JPEG file."))
|
||||||
|
return self.cleaned_data["motivation_letter"]
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Team
|
||||||
|
fields = ('motivation_letter',)
|
||||||
|
|
||||||
|
|
||||||
class RequestValidationForm(forms.Form):
|
class RequestValidationForm(forms.Form):
|
||||||
"""
|
"""
|
||||||
Form to ask about validation.
|
Form to ask about validation.
|
||||||
|
|
|
@ -22,14 +22,16 @@ class Command(BaseCommand):
|
||||||
avatar_uri = "plop"
|
avatar_uri = "plop"
|
||||||
else: # pragma: no cover
|
else: # pragma: no cover
|
||||||
if not os.path.isfile(".matrix_avatar"):
|
if not os.path.isfile(".matrix_avatar"):
|
||||||
stat_file = os.stat("tfjm/static/logo.png")
|
avatar_uri = Matrix.get_avatar()
|
||||||
with open("tfjm/static/logo.png", "rb") as f:
|
if not isinstance(avatar_uri, str):
|
||||||
resp = Matrix.upload(f, filename="logo.png", content_type="image/png",
|
stat_file = os.stat("tfjm/static/logo.png")
|
||||||
filesize=stat_file.st_size)[0][0]
|
with open("tfjm/static/logo.png", "rb") as f:
|
||||||
avatar_uri = resp.content_uri
|
resp = Matrix.upload(f, filename="logo.png", content_type="image/png",
|
||||||
with open(".matrix_avatar", "w") as f:
|
filesize=stat_file.st_size)[0][0]
|
||||||
f.write(avatar_uri)
|
avatar_uri = resp.content_uri
|
||||||
Matrix.set_avatar(avatar_uri)
|
with open(".matrix_avatar", "w") as f:
|
||||||
|
f.write(avatar_uri)
|
||||||
|
Matrix.set_avatar(avatar_uri)
|
||||||
|
|
||||||
with open(".matrix_avatar", "r") as f:
|
with open(".matrix_avatar", "r") as f:
|
||||||
avatar_uri = f.read().rstrip(" \t\r\n")
|
avatar_uri = f.read().rstrip(" \t\r\n")
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
# Generated by Django 3.0.11 on 2021-01-22 08:15
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import participation.models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('participation', '0002_auto_20210121_2206'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='team',
|
||||||
|
name='motivation_letter',
|
||||||
|
field=models.FileField(blank=True, default='', upload_to=participation.models.get_motivation_letter_filename, verbose_name='motivation letter'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -20,6 +20,10 @@ from tfjm.lists import get_sympa_client
|
||||||
from tfjm.matrix import Matrix, RoomPreset, RoomVisibility
|
from tfjm.matrix import Matrix, RoomPreset, RoomVisibility
|
||||||
|
|
||||||
|
|
||||||
|
def get_motivation_letter_filename(instance, filename):
|
||||||
|
return f"authorization/motivation_letters/motivation_letter_{instance.trigram}"
|
||||||
|
|
||||||
|
|
||||||
class Team(models.Model):
|
class Team(models.Model):
|
||||||
"""
|
"""
|
||||||
The Team model represents a real team that participates to the TFJM².
|
The Team model represents a real team that participates to the TFJM².
|
||||||
|
@ -45,6 +49,13 @@ class Team(models.Model):
|
||||||
help_text=_("The access code let other people to join the team."),
|
help_text=_("The access code let other people to join the team."),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
motivation_letter = models.FileField(
|
||||||
|
verbose_name=_("motivation letter"),
|
||||||
|
upload_to=get_motivation_letter_filename,
|
||||||
|
blank=True,
|
||||||
|
default="",
|
||||||
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def students(self):
|
def students(self):
|
||||||
return self.participants.filter(studentregistration__isnull=False)
|
return self.participants.filter(studentregistration__isnull=False)
|
||||||
|
|
|
@ -85,7 +85,25 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</dd>
|
</dd>
|
||||||
|
|
||||||
|
<dt class="col-sm-6 text-right">{% trans "Motivation letter:" %}</dt>
|
||||||
|
<dd class="col-sm-6">
|
||||||
|
{% if team.motivation_letter %}
|
||||||
|
<a href="{{ team.motivation_letter.url }}" data-turbolinks="false">{% trans "Download" %}</a>
|
||||||
|
{% else %}
|
||||||
|
<em>{% trans "Not uploaded yet" %}</em>
|
||||||
|
{% endif %}
|
||||||
|
{% if user.registration.team == team and not user.registration.team.participation.valid or user.registration.is_admin %}
|
||||||
|
<button class="btn btn-primary" data-toggle="modal" data-target="#uploadMotivationLetterModal">{% trans "Replace" %}</button>
|
||||||
|
{% endif %}
|
||||||
|
</dd>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
<a class="btn btn-info" href="{% url "participation:team_authorizations" pk=team.pk %}" data-turbolinks="false">
|
||||||
|
<i class="fas fa-file-archive"></i> {% trans "Download all authorizations" %}
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-footer text-center">
|
<div class="card-footer text-center">
|
||||||
<button class="btn btn-primary" data-toggle="modal" data-target="#updateTeamModal">{% trans "Update" %}</button>
|
<button class="btn btn-primary" data-toggle="modal" data-target="#updateTeamModal">{% trans "Update" %}</button>
|
||||||
|
@ -146,6 +164,11 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% trans "Upload motivation letter" as modal_title %}
|
||||||
|
{% trans "Upload" as modal_button %}
|
||||||
|
{% url "participation:upload_team_motivation_letter" pk=team.pk as modal_action %}
|
||||||
|
{% include "base_modal.html" with modal_id="uploadMotivationLetter" modal_enctype="multipart/form-data" %}
|
||||||
|
|
||||||
{% trans "Update team" as modal_title %}
|
{% trans "Update team" as modal_title %}
|
||||||
{% trans "Update" as modal_button %}
|
{% trans "Update" as modal_button %}
|
||||||
{% url "participation:update_team" pk=team.pk as modal_action %}
|
{% url "participation:update_team" pk=team.pk as modal_action %}
|
||||||
|
@ -160,6 +183,11 @@
|
||||||
{% block extrajavascript %}
|
{% block extrajavascript %}
|
||||||
<script>
|
<script>
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
$('button[data-target="#uploadMotivationLetterModal"]').click(function() {
|
||||||
|
let modalBody = $("#uploadMotivationLetterModal div.modal-body");
|
||||||
|
if (!modalBody.html().trim())
|
||||||
|
modalBody.load("{% url "participation:upload_team_motivation_letter" pk=team.pk %} #form-content");
|
||||||
|
});
|
||||||
$('button[data-target="#updateTeamModal"]').click(function() {
|
$('button[data-target="#updateTeamModal"]').click(function() {
|
||||||
let modalBody = $("#updateTeamModal div.modal-body");
|
let modalBody = $("#updateTeamModal div.modal-body");
|
||||||
if (!modalBody.html().trim())
|
if (!modalBody.html().trim())
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% load i18n static crispy_forms_filters %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<a class="btn btn-info" href="{% url "participation:team_detail" pk=object.pk %}"><i class="fas fa-arrow-left"></i> {% trans "Back to the team detail" %}</a>
|
||||||
|
<hr>
|
||||||
|
<form method="post" enctype="multipart/form-data">
|
||||||
|
<div id="form-content">
|
||||||
|
{% csrf_token %}
|
||||||
|
{{ form|crispy }}
|
||||||
|
</div>
|
||||||
|
<button class="btn btn-success" type="submit">{% trans "Upload" %}</button>
|
||||||
|
</form>
|
||||||
|
{% endblock %}
|
|
@ -288,6 +288,12 @@ class TestStudentParticipation(TestCase):
|
||||||
self.user.registration.parental_authorization = "authorization/parental/ananas"
|
self.user.registration.parental_authorization = "authorization/parental/ananas"
|
||||||
self.user.registration.save()
|
self.user.registration.save()
|
||||||
|
|
||||||
|
resp = self.client.get(reverse("participation:team_detail", args=(self.team.pk,)))
|
||||||
|
self.assertEqual(resp.status_code, 200)
|
||||||
|
self.assertFalse(resp.context["can_validate"])
|
||||||
|
|
||||||
|
self.team.motivation_letter = "i_am_motivated.pdf"
|
||||||
|
self.team.save()
|
||||||
resp = self.client.get(reverse("participation:team_detail", args=(self.team.pk,)))
|
resp = self.client.get(reverse("participation:team_detail", args=(self.team.pk,)))
|
||||||
self.assertEqual(resp.status_code, 200)
|
self.assertEqual(resp.status_code, 200)
|
||||||
self.assertTrue(resp.context["can_validate"])
|
self.assertTrue(resp.context["can_validate"])
|
||||||
|
|
|
@ -7,8 +7,8 @@ from django.views.generic import TemplateView
|
||||||
from .views import CreateTeamView, JoinTeamView, MyParticipationDetailView, MyTeamDetailView, NoteUpdateView, \
|
from .views import CreateTeamView, JoinTeamView, MyParticipationDetailView, MyTeamDetailView, NoteUpdateView, \
|
||||||
ParticipationDetailView, PassageCreateView, PassageDetailView, PassageUpdateView, PoolCreateView, PoolDetailView, \
|
ParticipationDetailView, PassageCreateView, PassageDetailView, PassageUpdateView, PoolCreateView, PoolDetailView, \
|
||||||
PoolUpdateTeamsView, PoolUpdateView, SolutionUploadView, SynthesisUploadView, TeamAuthorizationsView, \
|
PoolUpdateTeamsView, PoolUpdateView, SolutionUploadView, SynthesisUploadView, TeamAuthorizationsView, \
|
||||||
TeamDetailView, TeamLeaveView, TeamListView, TeamUpdateView, TournamentCreateView, TournamentDetailView, \
|
TeamDetailView, TeamLeaveView, TeamListView, TeamUpdateView, TeamUploadMotivationLetterView, TournamentCreateView, \
|
||||||
TournamentListView, TournamentUpdateView
|
TournamentDetailView, TournamentListView, TournamentUpdateView
|
||||||
|
|
||||||
|
|
||||||
app_name = "participation"
|
app_name = "participation"
|
||||||
|
@ -20,6 +20,8 @@ urlpatterns = [
|
||||||
path("team/", MyTeamDetailView.as_view(), name="my_team_detail"),
|
path("team/", MyTeamDetailView.as_view(), name="my_team_detail"),
|
||||||
path("team/<int:pk>/", TeamDetailView.as_view(), name="team_detail"),
|
path("team/<int:pk>/", TeamDetailView.as_view(), name="team_detail"),
|
||||||
path("team/<int:pk>/update/", TeamUpdateView.as_view(), name="update_team"),
|
path("team/<int:pk>/update/", TeamUpdateView.as_view(), name="update_team"),
|
||||||
|
path("team/<int:pk>/upload-motivation-letter/", TeamUploadMotivationLetterView.as_view(),
|
||||||
|
name="upload_team_motivation_letter"),
|
||||||
path("team/<int:pk>/authorizations/", TeamAuthorizationsView.as_view(), name="team_authorizations"),
|
path("team/<int:pk>/authorizations/", TeamAuthorizationsView.as_view(), name="team_authorizations"),
|
||||||
path("team/leave/", TeamLeaveView.as_view(), name="team_leave"),
|
path("team/leave/", TeamLeaveView.as_view(), name="team_leave"),
|
||||||
path("detail/", MyParticipationDetailView.as_view(), name="my_participation_detail"),
|
path("detail/", MyParticipationDetailView.as_view(), name="my_participation_detail"),
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
import os
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
|
@ -9,13 +10,13 @@ from django.contrib.sites.models import Site
|
||||||
from django.core.exceptions import PermissionDenied
|
from django.core.exceptions import PermissionDenied
|
||||||
from django.core.mail import send_mail
|
from django.core.mail import send_mail
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
from django.http import Http404, HttpResponse
|
from django.http import FileResponse, Http404, HttpResponse
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import redirect
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from django.views.generic import CreateView, DetailView, FormView, RedirectView, TemplateView, UpdateView
|
from django.views.generic import CreateView, DetailView, FormView, RedirectView, TemplateView, UpdateView, View
|
||||||
from django.views.generic.edit import FormMixin, ProcessFormView
|
from django.views.generic.edit import FormMixin, ProcessFormView
|
||||||
from django_tables2 import SingleTableView
|
from django_tables2 import SingleTableView
|
||||||
from magic import Magic
|
from magic import Magic
|
||||||
|
@ -24,8 +25,9 @@ from tfjm.lists import get_sympa_client
|
||||||
from tfjm.matrix import Matrix
|
from tfjm.matrix import Matrix
|
||||||
from tfjm.views import AdminMixin, VolunteerMixin
|
from tfjm.views import AdminMixin, VolunteerMixin
|
||||||
|
|
||||||
from .forms import JoinTeamForm, NoteForm, ParticipationForm, PassageForm, PoolForm, PoolTeamsForm, \
|
from .forms import JoinTeamForm, MotivationLetterForm, NoteForm, ParticipationForm, PassageForm, PoolForm, \
|
||||||
RequestValidationForm, SolutionForm, SynthesisForm, TeamForm, TournamentForm, ValidateParticipationForm
|
PoolTeamsForm, RequestValidationForm, SolutionForm, SynthesisForm, TeamForm, TournamentForm, \
|
||||||
|
ValidateParticipationForm
|
||||||
from .models import Note, Participation, Passage, Pool, Solution, Synthesis, Team, Tournament
|
from .models import Note, Participation, Passage, Pool, Solution, Synthesis, Team, Tournament
|
||||||
from .tables import NoteTable, ParticipationTable, PassageTable, PoolTable, TeamTable, TournamentTable
|
from .tables import NoteTable, ParticipationTable, PassageTable, PoolTable, TeamTable, TournamentTable
|
||||||
|
|
||||||
|
@ -178,7 +180,8 @@ class TeamDetailView(LoginRequiredMixin, FormMixin, ProcessFormView, DetailView)
|
||||||
all(r.email_confirmed for r in team.students.all()) and \
|
all(r.email_confirmed for r in team.students.all()) and \
|
||||||
all(r.photo_authorization for r in team.participants.all()) and \
|
all(r.photo_authorization for r in team.participants.all()) and \
|
||||||
all(r.health_sheet for r in team.students.all() if r.under_18) and \
|
all(r.health_sheet for r in team.students.all() if r.under_18) and \
|
||||||
all(r.parental_authorization for r in team.students.all() if r.under_18)
|
all(r.parental_authorization for r in team.students.all() if r.under_18) and \
|
||||||
|
team.motivation_letter
|
||||||
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
@ -209,7 +212,7 @@ class TeamDetailView(LoginRequiredMixin, FormMixin, ProcessFormView, DetailView)
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
if not self.get_context_data()["can_validate"]:
|
if not self.get_context_data()["can_validate"]:
|
||||||
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, "
|
||||||
"authorizations, people or the chosen problem is not set."))
|
"authorizations, people, motivation letter or the tournament is not set."))
|
||||||
return self.form_invalid(form)
|
return self.form_invalid(form)
|
||||||
|
|
||||||
self.object.participation.valid = False
|
self.object.participation.valid = False
|
||||||
|
@ -304,6 +307,55 @@ class TeamUpdateView(LoginRequiredMixin, UpdateView):
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
|
class TeamUploadMotivationLetterView(LoginRequiredMixin, UpdateView):
|
||||||
|
"""
|
||||||
|
A team can send its motivation letter.
|
||||||
|
"""
|
||||||
|
model = Team
|
||||||
|
form_class = MotivationLetterForm
|
||||||
|
template_name = "participation/upload_motivation_letter.html"
|
||||||
|
extra_context = dict(title=_("Upload motivation letter"))
|
||||||
|
|
||||||
|
def dispatch(self, request, *args, **kwargs):
|
||||||
|
if not self.request.user.is_authenticated or \
|
||||||
|
not self.request.user.registration.is_admin \
|
||||||
|
and self.request.user.registration.team != self.get_object():
|
||||||
|
return self.handle_no_permission()
|
||||||
|
return super().dispatch(request, *args, **kwargs)
|
||||||
|
|
||||||
|
@transaction.atomic
|
||||||
|
def form_valid(self, form):
|
||||||
|
old_instance = Team.objects.get(pk=self.object.pk)
|
||||||
|
if old_instance.motivation_letter:
|
||||||
|
old_instance.motivation_letter.delete()
|
||||||
|
old_instance.save()
|
||||||
|
return super().form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
|
class MotivationLetterView(LoginRequiredMixin, View):
|
||||||
|
"""
|
||||||
|
Display the sent motivation letter.
|
||||||
|
"""
|
||||||
|
def get(self, request, *args, **kwargs):
|
||||||
|
filename = kwargs["filename"]
|
||||||
|
path = f"media/authorization/motivation_letters/{filename}"
|
||||||
|
if not os.path.exists(path):
|
||||||
|
raise Http404
|
||||||
|
team = Team.objects.get(motivation_letter__endswith=filename)
|
||||||
|
user = request.user
|
||||||
|
if not (user.registration in team.participants.all() or user.registration.is_admin
|
||||||
|
or user.registration.is_volunteer
|
||||||
|
and team.participation.tournament in user.registration.organized_tournaments.all()):
|
||||||
|
raise PermissionDenied
|
||||||
|
# Guess mime type of the file
|
||||||
|
mime = Magic(mime=True)
|
||||||
|
mime_type = mime.from_file(path)
|
||||||
|
ext = mime_type.split("/")[1].replace("jpeg", "jpg")
|
||||||
|
# Replace file name
|
||||||
|
true_file_name = _("Motivation letter of {team}.{ext}").format(team=str(team), ext=ext)
|
||||||
|
return FileResponse(open(path, "rb"), content_type=mime_type, filename=true_file_name)
|
||||||
|
|
||||||
|
|
||||||
class TeamAuthorizationsView(LoginRequiredMixin, DetailView):
|
class TeamAuthorizationsView(LoginRequiredMixin, DetailView):
|
||||||
"""
|
"""
|
||||||
Get as a ZIP archive all the authorizations that are sent
|
Get as a ZIP archive all the authorizations that are sent
|
||||||
|
@ -322,10 +374,10 @@ class TeamAuthorizationsView(LoginRequiredMixin, DetailView):
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
team = self.get_object()
|
team = self.get_object()
|
||||||
|
magic = Magic(mime=True)
|
||||||
output = BytesIO()
|
output = BytesIO()
|
||||||
zf = ZipFile(output, "w")
|
zf = ZipFile(output, "w")
|
||||||
for participant in team.participants.all():
|
for participant in team.participants.all():
|
||||||
magic = Magic(mime=True)
|
|
||||||
if participant.photo_authorization:
|
if participant.photo_authorization:
|
||||||
mime_type = magic.from_file("media/" + participant.photo_authorization.name)
|
mime_type = magic.from_file("media/" + participant.photo_authorization.name)
|
||||||
ext = mime_type.split("/")[1].replace("jpeg", "jpg")
|
ext = mime_type.split("/")[1].replace("jpeg", "jpg")
|
||||||
|
@ -344,6 +396,12 @@ class TeamAuthorizationsView(LoginRequiredMixin, DetailView):
|
||||||
ext = mime_type.split("/")[1].replace("jpeg", "jpg")
|
ext = mime_type.split("/")[1].replace("jpeg", "jpg")
|
||||||
zf.write("media/" + participant.health_sheet.name,
|
zf.write("media/" + participant.health_sheet.name,
|
||||||
_("Health sheet of {participant}.{ext}").format(participant=str(participant), ext=ext))
|
_("Health sheet of {participant}.{ext}").format(participant=str(participant), ext=ext))
|
||||||
|
|
||||||
|
if team.motivation_letter:
|
||||||
|
mime_type = magic.from_file("media/" + team.motivation_letter.name)
|
||||||
|
ext = mime_type.split("/")[1].replace("jpeg", "jpg")
|
||||||
|
zf.write("media/" + team.motivation_letter.name,
|
||||||
|
_("Motivation letter of {team}.{ext}").format(team=str(team), ext=ext))
|
||||||
zf.close()
|
zf.close()
|
||||||
response = HttpResponse(content_type="application/zip")
|
response = HttpResponse(content_type="application/zip")
|
||||||
response["Content-Disposition"] = "attachment; filename=\"{filename}\"" \
|
response["Content-Disposition"] = "attachment; filename=\"{filename}\"" \
|
||||||
|
@ -518,6 +576,7 @@ class SolutionUploadView(LoginRequiredMixin, FormView):
|
||||||
# Drop previous solution if existing
|
# Drop previous solution if existing
|
||||||
for sol in sol_qs.all():
|
for sol in sol_qs.all():
|
||||||
sol.file.delete()
|
sol.file.delete()
|
||||||
|
sol.save()
|
||||||
sol.delete()
|
sol.delete()
|
||||||
form_sol.participation = self.participation
|
form_sol.participation = self.participation
|
||||||
form_sol.final = self.participation.final
|
form_sol.final = self.participation.final
|
||||||
|
@ -698,6 +757,7 @@ class SynthesisUploadView(LoginRequiredMixin, FormView):
|
||||||
# Drop previous solution if existing
|
# Drop previous solution if existing
|
||||||
for syn in syn_qs.all():
|
for syn in syn_qs.all():
|
||||||
syn.file.delete()
|
syn.file.delete()
|
||||||
|
syn.save()
|
||||||
syn.delete()
|
syn.delete()
|
||||||
form_syn.participation = self.participation
|
form_syn.participation = self.participation
|
||||||
form_syn.passage = self.passage
|
form_syn.passage = self.passage
|
||||||
|
|
|
@ -100,7 +100,7 @@ class StudentRegistrationForm(forms.ModelForm):
|
||||||
"""
|
"""
|
||||||
class Meta:
|
class Meta:
|
||||||
model = StudentRegistration
|
model = StudentRegistration
|
||||||
fields = ('team', 'student_class', 'birth_date', 'address', 'phone_number',
|
fields = ('team', 'student_class', 'birth_date', 'gender', 'address', 'phone_number',
|
||||||
'school', 'responsible_name', 'responsible_phone', 'responsible_email',
|
'school', 'responsible_name', 'responsible_phone', 'responsible_email',
|
||||||
'give_contact_to_animath', 'email_confirmed',)
|
'give_contact_to_animath', 'email_confirmed',)
|
||||||
|
|
||||||
|
@ -177,7 +177,7 @@ class CoachRegistrationForm(forms.ModelForm):
|
||||||
"""
|
"""
|
||||||
class Meta:
|
class Meta:
|
||||||
model = CoachRegistration
|
model = CoachRegistration
|
||||||
fields = ('team', 'birth_date', 'address', 'phone_number', 'professional_activity',
|
fields = ('team', 'birth_date', 'gender', 'address', 'phone_number', 'professional_activity',
|
||||||
'give_contact_to_animath', 'email_confirmed',)
|
'give_contact_to_animath', 'email_confirmed',)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
# Generated by Django 3.0.11 on 2021-01-22 08:00
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('registration', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='participantregistration',
|
||||||
|
name='gender',
|
||||||
|
field=models.CharField(choices=[('female', 'Female'), ('male', 'Male'), ('other', 'Other')], default='other', max_length=6, verbose_name='gender'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -128,6 +128,17 @@ class ParticipantRegistration(Registration):
|
||||||
default=date.today,
|
default=date.today,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
gender = models.CharField(
|
||||||
|
max_length=6,
|
||||||
|
verbose_name=_("gender"),
|
||||||
|
choices=[
|
||||||
|
("female", _("Female")),
|
||||||
|
("male", _("Male")),
|
||||||
|
("other", _("Other")),
|
||||||
|
],
|
||||||
|
default="other",
|
||||||
|
)
|
||||||
|
|
||||||
address = AddressField(
|
address = AddressField(
|
||||||
verbose_name=_("address"),
|
verbose_name=_("address"),
|
||||||
null=True,
|
null=True,
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p>
|
<p>
|
||||||
Vous avez été invités par {{ inviter }} à rejoindre la plateforme du TFJM², accessible à l'adresse
|
Vous avez été invités par {{ inviter.registration }} à rejoindre la plateforme du TFJM², accessible à l'adresse
|
||||||
<a href="https://{{ domain }}/">https://{{ domain }}/</a>. Vous disposez d'un compte d'organisateur.
|
<a href="https://{{ domain }}/">https://{{ domain }}/</a>. Vous disposez d'un compte d'organisateur.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
Bonjour {{ user.registration }},
|
Bonjour {{ user.registration }},
|
||||||
|
|
||||||
Vous avez été invités par {{ inviter }} à rejoindre la plateforme du TFJM², accessible à l'adresse
|
Vous avez été invités par {{ inviter.registration }} à rejoindre la plateforme du TFJM², accessible à l'adresse
|
||||||
https://{{ domain }}/. Vous disposez d'un compte d'organisateur.
|
https://{{ domain }}/. Vous disposez d'un compte d'organisateur.
|
||||||
|
|
||||||
Un mot de passe aléatoire a été défini : {{ password }}.
|
Un mot de passe aléatoire a été défini : {{ password }}.
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
<dt class="col-sm-6 text-right">{% trans "First name:" %}</dt>
|
<dt class="col-sm-6 text-right">{% trans "First name:" %}</dt>
|
||||||
<dd class="col-sm-6">{{ user_object.first_name }}</dd>
|
<dd class="col-sm-6">{{ user_object.first_name }}</dd>
|
||||||
|
StudentRegistrationForm(
|
||||||
<dt class="col-sm-6 text-right">{% trans "Email:" %}</dt>
|
<dt class="col-sm-6 text-right">{% trans "Email:" %}</dt>
|
||||||
<dd class="col-sm-6"><a href="mailto:{{ user_object.email }}">{{ user_object.email }}</a>
|
<dd class="col-sm-6"><a href="mailto:{{ user_object.email }}">{{ user_object.email }}</a>
|
||||||
{% if not user_object.registration.email_confirmed %} (<em>{% trans "Not confirmed" %}, <a href="{% url "registration:email_validation_resend" pk=user_object.pk %}">{% trans "resend the validation link" %}</a></em>){% endif %}</dd>
|
{% if not user_object.registration.email_confirmed %} (<em>{% trans "Not confirmed" %}, <a href="{% url "registration:email_validation_resend" pk=user_object.pk %}">{% trans "resend the validation link" %}</a></em>){% endif %}</dd>
|
||||||
|
@ -42,6 +42,9 @@
|
||||||
<dt class="col-sm-6 text-right">{% trans "Birth date:" %}</dt>
|
<dt class="col-sm-6 text-right">{% trans "Birth date:" %}</dt>
|
||||||
<dd class="col-sm-6">{{ user_object.registration.birth_date }}</dd>
|
<dd class="col-sm-6">{{ user_object.registration.birth_date }}</dd>
|
||||||
|
|
||||||
|
<dt class="col-sm-6 text-right">{% trans "Gender:" %}</dt>
|
||||||
|
<dd class="col-sm-6">{{ user_object.registration.get_gender_display }}</dd>
|
||||||
|
|
||||||
<dt class="col-sm-6 text-right">{% trans "Address:" %}</dt>
|
<dt class="col-sm-6 text-right">{% trans "Address:" %}</dt>
|
||||||
<dd class="col-sm-6">{{ user_object.registration.address }}</dd>
|
<dd class="col-sm-6">{{ user_object.registration.address }}</dd>
|
||||||
|
|
||||||
|
|
|
@ -130,6 +130,7 @@ class TestRegistration(TestCase):
|
||||||
student_class=12,
|
student_class=12,
|
||||||
school="God",
|
school="God",
|
||||||
birth_date="2000-01-01",
|
birth_date="2000-01-01",
|
||||||
|
gender="other",
|
||||||
address="1 Rue de Rivoli, 75001 Paris, France",
|
address="1 Rue de Rivoli, 75001 Paris, France",
|
||||||
phone_number="0123456789",
|
phone_number="0123456789",
|
||||||
responsible_name="Toto",
|
responsible_name="Toto",
|
||||||
|
@ -153,6 +154,7 @@ class TestRegistration(TestCase):
|
||||||
student_class=12,
|
student_class=12,
|
||||||
school="God",
|
school="God",
|
||||||
birth_date="2000-01-01",
|
birth_date="2000-01-01",
|
||||||
|
gender="other",
|
||||||
address="1 Rue de Rivoli, 75001 Paris, France",
|
address="1 Rue de Rivoli, 75001 Paris, France",
|
||||||
phone_number="0123456789",
|
phone_number="0123456789",
|
||||||
responsible_name="Toto",
|
responsible_name="Toto",
|
||||||
|
@ -173,6 +175,7 @@ class TestRegistration(TestCase):
|
||||||
password2="azertyuiopazertyuiop",
|
password2="azertyuiopazertyuiop",
|
||||||
role="coach",
|
role="coach",
|
||||||
birth_date="1980-01-01",
|
birth_date="1980-01-01",
|
||||||
|
gender="other",
|
||||||
address="1 Rue de Rivoli, 75001 Paris, France",
|
address="1 Rue de Rivoli, 75001 Paris, France",
|
||||||
phone_number="0123456789",
|
phone_number="0123456789",
|
||||||
professional_activity="God",
|
professional_activity="God",
|
||||||
|
@ -252,10 +255,10 @@ class TestRegistration(TestCase):
|
||||||
|
|
||||||
for user, data in [(self.user, dict(role="Bot")),
|
for user, data in [(self.user, dict(role="Bot")),
|
||||||
(self.student, dict(student_class=11, school="Sky", birth_date="2001-01-01",
|
(self.student, dict(student_class=11, school="Sky", birth_date="2001-01-01",
|
||||||
address="1 Rue de Rivoli, 75001 Paris, France", responsible_name="Toto",
|
gender="female", address="1 Rue de Rivoli, 75001 Paris, France",
|
||||||
responsible_email="toto@example.com")),
|
responsible_name="Toto", responsible_email="toto@example.com")),
|
||||||
(self.coach, dict(professional_activity="God", birth_date="2001-01-01",
|
(self.coach, dict(professional_activity="God", birth_date="2001-01-01",
|
||||||
address="1 Rue de Rivoli, 75001 Paris, France"))]:
|
gender="male", address="1 Rue de Rivoli, 75001 Paris, France"))]:
|
||||||
response = self.client.get(reverse("registration:update_user", args=(user.pk,)))
|
response = self.client.get(reverse("registration:update_user", args=(user.pk,)))
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
|
@ -340,6 +343,7 @@ class TestRegistration(TestCase):
|
||||||
|
|
||||||
self.student.registration.refresh_from_db()
|
self.student.registration.refresh_from_db()
|
||||||
self.student.registration.photo_authorization.delete()
|
self.student.registration.photo_authorization.delete()
|
||||||
|
self.student.registration.save()
|
||||||
|
|
||||||
def test_user_detail_forbidden(self):
|
def test_user_detail_forbidden(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -329,6 +329,7 @@ class UserUploadPhotoAuthorizationView(UserMixin, UpdateView):
|
||||||
old_instance = StudentRegistration.objects.get(pk=self.object.pk)
|
old_instance = StudentRegistration.objects.get(pk=self.object.pk)
|
||||||
if old_instance.photo_authorization:
|
if old_instance.photo_authorization:
|
||||||
old_instance.photo_authorization.delete()
|
old_instance.photo_authorization.delete()
|
||||||
|
old_instance.save()
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
@ -355,6 +356,7 @@ class UserUploadHealthSheetView(UserMixin, UpdateView):
|
||||||
old_instance = StudentRegistration.objects.get(pk=self.object.pk)
|
old_instance = StudentRegistration.objects.get(pk=self.object.pk)
|
||||||
if old_instance.health_sheet:
|
if old_instance.health_sheet:
|
||||||
old_instance.health_sheet.delete()
|
old_instance.health_sheet.delete()
|
||||||
|
old_instance.save()
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
@ -381,6 +383,7 @@ class UserUploadParentalAuthorizationView(UserMixin, UpdateView):
|
||||||
old_instance = StudentRegistration.objects.get(pk=self.object.pk)
|
old_instance = StudentRegistration.objects.get(pk=self.object.pk)
|
||||||
if old_instance.parental_authorization:
|
if old_instance.parental_authorization:
|
||||||
old_instance.parental_authorization.delete()
|
old_instance.parental_authorization.delete()
|
||||||
|
old_instance.save()
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|
||||||
def get_success_url(self):
|
def get_success_url(self):
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -9,7 +9,7 @@ _client = None
|
||||||
def get_sympa_client():
|
def get_sympa_client():
|
||||||
global _client
|
global _client
|
||||||
if _client is None:
|
if _client is None:
|
||||||
if os.getenv("SYMPA_PASSWORD", None) is not None: # pragma: no cover
|
if os.getenv("SYMPA_PASSWORD", None): # pragma: no cover
|
||||||
from sympasoap import Client
|
from sympasoap import Client
|
||||||
_client = Client("https://" + os.getenv("SYMPA_URL"))
|
_client = Client("https://" + os.getenv("SYMPA_URL"))
|
||||||
_client.login(os.getenv("SYMPA_EMAIL"), os.getenv("SYMPA_PASSWORD"))
|
_client.login(os.getenv("SYMPA_EMAIL"), os.getenv("SYMPA_PASSWORD"))
|
||||||
|
|
|
@ -68,6 +68,16 @@ class Matrix:
|
||||||
client = await cls._get_client()
|
client = await cls._get_client()
|
||||||
return await client.set_avatar(avatar_url)
|
return await client.set_avatar(avatar_url)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
@async_to_sync
|
||||||
|
async def get_avatar(cls): # pragma: no cover
|
||||||
|
"""
|
||||||
|
Set the display avatar of the bot account.
|
||||||
|
"""
|
||||||
|
client = await cls._get_client()
|
||||||
|
resp = await client.get_avatar()
|
||||||
|
return resp.avatar_url if resp.status_code == 200 else resp
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@async_to_sync
|
@async_to_sync
|
||||||
async def upload(
|
async def upload(
|
||||||
|
|
|
@ -20,8 +20,8 @@ EMAIL_PORT = os.getenv("SMTP_PORT")
|
||||||
EMAIL_HOST_USER = os.getenv("SMTP_HOST_USER")
|
EMAIL_HOST_USER = os.getenv("SMTP_HOST_USER")
|
||||||
EMAIL_HOST_PASSWORD = os.getenv("SMTP_HOST_PASSWORD")
|
EMAIL_HOST_PASSWORD = os.getenv("SMTP_HOST_PASSWORD")
|
||||||
|
|
||||||
DEFAULT_FROM_EMAIL = os.getenv('FROM_EMAIL', 'Contact TFJM² <contact@tfjm.org>')
|
|
||||||
SERVER_EMAIL = os.getenv('SERVER_EMAIL', 'contact@tfjm.org')
|
SERVER_EMAIL = os.getenv('SERVER_EMAIL', 'contact@tfjm.org')
|
||||||
|
DEFAULT_FROM_EMAIL = os.getenv('FROM_EMAIL', 'Contact TFJM²') + f" <{SERVER_EMAIL}>"
|
||||||
|
|
||||||
# Security settings
|
# Security settings
|
||||||
SECURE_CONTENT_TYPE_NOSNIFF = False
|
SECURE_CONTENT_TYPE_NOSNIFF = False
|
||||||
|
|
|
@ -21,6 +21,7 @@ from django.contrib import admin
|
||||||
from django.urls import include, path
|
from django.urls import include, path
|
||||||
from django.views.defaults import bad_request, page_not_found, permission_denied, server_error
|
from django.views.defaults import bad_request, page_not_found, permission_denied, server_error
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
|
from participation.views import MotivationLetterView
|
||||||
from registration.views import HealthSheetView, ParentalAuthorizationView, PhotoAuthorizationView, \
|
from registration.views import HealthSheetView, ParentalAuthorizationView, PhotoAuthorizationView, \
|
||||||
ScholarshipView, SolutionView, SynthesisView
|
ScholarshipView, SolutionView, SynthesisView
|
||||||
|
|
||||||
|
@ -47,6 +48,8 @@ urlpatterns = [
|
||||||
name='parental_authorization'),
|
name='parental_authorization'),
|
||||||
path('media/authorization/scholarship/<str:filename>/', ScholarshipView.as_view(),
|
path('media/authorization/scholarship/<str:filename>/', ScholarshipView.as_view(),
|
||||||
name='scholarship'),
|
name='scholarship'),
|
||||||
|
path('media/authorization/motivation_letters/<str:filename>/', MotivationLetterView.as_view(),
|
||||||
|
name='scholarship'),
|
||||||
|
|
||||||
path('media/solutions/<str:filename>/', SolutionView.as_view(),
|
path('media/solutions/<str:filename>/', SolutionView.as_view(),
|
||||||
name='solution'),
|
name='solution'),
|
||||||
|
|
Loading…
Reference in New Issue