mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-06-23 06:36:33 +02:00
Teams can request a validation
This commit is contained in:
18
apps/participation/migrations/0005_participation_valid.py
Normal file
18
apps/participation/migrations/0005_participation_valid.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.1.1 on 2020-10-11 13:58
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('participation', '0004_auto_20200927_1322'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='participation',
|
||||
name='valid',
|
||||
field=models.BooleanField(default=None, help_text='The video got the validation of the administrators.', null=True, verbose_name='valid'),
|
||||
),
|
||||
]
|
@ -1,6 +1,7 @@
|
||||
{% extends "base.html" %}
|
||||
|
||||
{% load i18n %}
|
||||
{% load crispy_forms_filters %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
@ -61,16 +62,42 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% if team.participation.valid %}
|
||||
<hr>
|
||||
<hr>
|
||||
|
||||
{% if team.participation.valid %}
|
||||
<div class="text-center">
|
||||
<a class="btn btn-info" href="{% url "participation:participation_detail" pk=team.participation.pk %}">
|
||||
<i class="fas fa-video"></i> {% trans "Access to team participation" %} <i class="fas fa-video"></i>
|
||||
</a>
|
||||
</div>
|
||||
{% else %}
|
||||
{# TODO Validate team #}
|
||||
{% elif team.participation.valid is None %} {# Team did not ask for validation #}
|
||||
{% if user.registration.participates %}
|
||||
{% if can_validate %}
|
||||
<div class="alert alert-info">
|
||||
{% trans "Your team has at least 3 members and all photo authorizations were given: the team can be validated." %}
|
||||
<div class="text-center">
|
||||
<button class="btn btn-success">{% trans "Submit my team to validation" %}</button>
|
||||
</div>
|
||||
</div>
|
||||
{% else %}
|
||||
<div class="alert alert-warning">
|
||||
{% trans "Your team must be composed of 3 members and each member must upload its photo authorization." %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<div class="alert alert-warning">
|
||||
{% trans "This team didn't ask for validation yet." %}
|
||||
</div>
|
||||
{% endif %}
|
||||
{% else %} {# Team is waiting for validation #}
|
||||
{% if user.registration.participates %}
|
||||
<div class="alert alert-warning">
|
||||
{% trans "Your validation is pending." %}
|
||||
</div>
|
||||
{% else %}
|
||||
Team asked for validation.
|
||||
{# TODO Add validation form: validate or invalidate, with a message #}
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
|
||||
{% trans "Update team" as modal_title %}
|
||||
|
@ -90,12 +90,22 @@ class MyTeamDetailView(LoginRequiredMixin, RedirectView):
|
||||
class TeamDetailView(LoginRequiredMixin, DetailView):
|
||||
model = Team
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
def get(self, request, *args, **kwargs):
|
||||
user = request.user
|
||||
if user.registration.is_admin or user.registration.participates and user.registration.team.pk == kwargs["pk"]:
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
return super().get(request, *args, **kwargs)
|
||||
raise PermissionDenied
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
team = self.object
|
||||
context["can_validate"] = team.students.count() >= 3 and \
|
||||
all(r.photo_authorization for r in team.students.all()) and \
|
||||
team.participation.problem
|
||||
|
||||
return context
|
||||
|
||||
|
||||
class TeamUpdateView(LoginRequiredMixin, UpdateView):
|
||||
model = Team
|
||||
@ -148,7 +158,7 @@ class TeamAuthorizationsView(LoginRequiredMixin, DetailView):
|
||||
_("Photo authorization of {student}.{ext}").format(student=str(student), ext=ext))
|
||||
zf.close()
|
||||
response = HttpResponse(content_type="application/zip")
|
||||
response["Content-Disposition"] = "attachment; filename=\"{filename}\""\
|
||||
response["Content-Disposition"] = "attachment; filename=\"{filename}\"" \
|
||||
.format(filename=_("Photo authorizations of team {trigram}.zip").format(trigram=team.trigram))
|
||||
response.write(output.getvalue())
|
||||
return response
|
||||
@ -172,7 +182,7 @@ class ParticipationDetailView(LoginRequiredMixin, DetailView):
|
||||
user = request.user
|
||||
if not self.get_object().valid:
|
||||
raise PermissionDenied(_("The team is not validated yet."))
|
||||
if user.registration.is_admin or user.registration.participates\
|
||||
if user.registration.is_admin or user.registration.participates \
|
||||
and user.registration.team.participation.pk == kwargs["pk"]:
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
raise PermissionDenied
|
||||
@ -185,7 +195,7 @@ class UploadVideoView(LoginRequiredMixin, UpdateView):
|
||||
|
||||
def dispatch(self, request, *args, **kwargs):
|
||||
user = request.user
|
||||
if user.registration.is_admin or user.registration.participates\
|
||||
if user.registration.is_admin or user.registration.participates \
|
||||
and user.registration.team.participation.pk == self.get_object().participation.pk:
|
||||
return super().dispatch(request, *args, **kwargs)
|
||||
raise PermissionDenied
|
||||
|
Reference in New Issue
Block a user