Define the received participation

This commit is contained in:
Yohann D'ANELLO 2020-10-31 12:51:49 +01:00
parent e0f06179a0
commit e9c56104df
6 changed files with 108 additions and 29 deletions

View File

@ -3,6 +3,7 @@ import re
from bootstrap_datepicker_plus import DateTimePickerInput
from django import forms
from django.core.exceptions import ValidationError
from django.db.models import Q
from django.utils.translation import gettext_lazy as _
from .models import Participation, Phase, Team, Video
@ -99,6 +100,21 @@ class UploadVideoForm(forms.ModelForm):
return super().clean()
class ReceiveParticipationForm(forms.ModelForm):
"""
Update the received participation of a participation.
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields["received_participation"].queryset = Participation.objects.filter(
~Q(pk=self.instance.pk) & Q(problem=self.instance.problem, valid=True)
)
class Meta:
model = Participation
fields = ('received_participation',)
class PhaseForm(forms.ModelForm):
"""
Form to update the calendar of a phase.

View File

@ -46,8 +46,13 @@
</div>
<div class="card-body">
<dl class="row">
<dt class="col-md-8 text-right">{% trans "Team that received your solution:" %}</dt>
<dd class="col-md-4">{{ participation.sent_participation|default:any }}</dd>
<dt class="col-xl-5 text-right">{% trans "Team that received your solution:" %}</dt>
<dd class="col-md-5">{{ participation.sent_participation.team|default:any }}</dd>
{% if user.registration.is_admin %}
<dd class="col-xs-2">
<button class="btn btn-primary">{% trans "Change" %}</button>
</dd>
{% endif %}
</dl>
{% if current_phase.phase_number == 2 %}
@ -82,8 +87,13 @@
</div>
<div class="card-body">
<dl class="row">
<dt class="col-md-8 text-right">{% trans "Team that sent you their solution:" %}</dt>
<dd class="col-md-4">{{ participation.received_participation|default:any }}</dd>
<dt class="col-xl-5 text-right">{% trans "Team that sent you their solution:" %}</dt>
<dd class="col-md-5">{{ participation.received_participation.team|default:any }}</dd>
{% if user.registration.is_admin %}
<dd class="col-xs-2">
<button class="btn btn-primary" data-toggle="modal" data-target="#defineReceivedParticipationModal">{% trans "Change" %}</button>
</dd>
{% endif %}
</dl>
{# TODO Display solution #}
@ -110,6 +120,13 @@
</div>
{% endif %}
{% if user.registration.is_admin %}
{% trans "Define received video" as modal_title %}
{% trans "Update" as modal_button %}
{% url "participation:participation_receive_participation" pk=participation.pk as modal_action %}
{% include "base_modal.html" with modal_id="defineReceivedParticipation" %}
{% endif %}
{% trans "Upload video" as modal_title %}
{% trans "Upload" as modal_button %}
{% url "participation:upload_video" pk=participation.solution_id as modal_action %}
@ -122,6 +139,13 @@
{% block extrajavascript %}
<script>
$(document).ready(function() {
{% if user.registration.is_admin %}
$('button[data-target="#defineReceivedParticipationModal"]').click(function() {
let modalBody = $("#defineReceivedParticipationModal div.modal-body");
if (!modalBody.html().trim())
modalBody.load("{% url "participation:participation_receive_participation" pk=participation.pk %} #form-content");
});
{% endif %}
$('button[data-target="#uploadSolutionModal"]').click(function() {
let modalBody = $("#uploadSolutionModal div.modal-body");
if (!modalBody.html().trim())

View File

@ -0,0 +1,14 @@
{% extends "base.html" %}
{% load crispy_forms_filters i18n %}
{% block content %}
<form method="post">
<div id="form-content">
{% csrf_token %}
{{ form|crispy }}
</div>
<button class="btn btn-primary" type="submit">{% trans "Update" %}</button>
</form>
{% endblock content %}

View File

@ -2,8 +2,8 @@ from django.urls import path
from django.views.generic import TemplateView
from .views import CalendarView, CreateTeamView, JoinTeamView, MyParticipationDetailView, MyTeamDetailView, \
ParticipationDetailView, PhaseUpdateView, TeamAuthorizationsView, TeamDetailView, TeamLeaveView, TeamUpdateView, \
UploadVideoView
ParticipationDetailView, PhaseUpdateView, SetParticipationReceiveParticipationView, TeamAuthorizationsView, \
TeamDetailView, TeamLeaveView, TeamUpdateView, UploadVideoView
app_name = "participation"
@ -19,6 +19,8 @@ urlpatterns = [
path("detail/", MyParticipationDetailView.as_view(), name="my_participation_detail"),
path("detail/<int:pk>/", ParticipationDetailView.as_view(), name="participation_detail"),
path("detail/upload-video/<int:pk>/", UploadVideoView.as_view(), name="upload_video"),
path("detail/<int:pk>/receive-participation/", SetParticipationReceiveParticipationView.as_view(),
name="participation_receive_participation"),
path("calendar/", CalendarView.as_view(), name="calendar"),
path("calendar/<int:pk>/", PhaseUpdateView.as_view(), name="update_phase"),
path("chat/", TemplateView.as_view(template_name="participation/chat.html"), name="chat")

View File

@ -20,8 +20,8 @@ from django_tables2 import SingleTableView
from magic import Magic
from registration.models import AdminRegistration
from .forms import JoinTeamForm, ParticipationForm, PhaseForm, RequestValidationForm, TeamForm, UploadVideoForm,\
ValidateParticipationForm
from .forms import JoinTeamForm, ParticipationForm, PhaseForm, ReceiveParticipationForm, RequestValidationForm,\
TeamForm, UploadVideoForm, ValidateParticipationForm
from .models import Participation, Phase, Team, Video
from .tables import CalendarTable
@ -358,6 +358,18 @@ class ParticipationDetailView(LoginRequiredMixin, DetailView):
return context
class SetParticipationReceiveParticipationView(AdminMixin, UpdateView):
"""
Define the solution that a team will receive.
"""
model = Participation
form_class = ReceiveParticipationForm
template_name = "participation/receive_participation_form.html"
def get_success_url(self):
return reverse_lazy("participation:participation_detail", args=(self.object.pk,))
class UploadVideoView(LoginRequiredMixin, UpdateView):
"""
Upload a solution video for a team.

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Corres2math\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-10-30 22:32+0100\n"
"POT-Creation-Date: 2020-10-31 12:36+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Yohann D'ANELLO <yohann.danello@animath.fr>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -119,15 +119,15 @@ msgstr "Message à adresser à l'équipe :"
msgid "You can't upload your video after the deadline."
msgstr "Vous ne pouvez pas envoyer de vidéo après la date limite."
#: apps/participation/forms.py:118
#: apps/participation/forms.py:127
msgid "Start date must be before the end date."
msgstr "La date de début doit être avant la date de fin."
#: apps/participation/forms.py:120
#: apps/participation/forms.py:129
msgid "This phase must start after the previous phases."
msgstr "Cette phase doit commencer après les phases précédentes."
#: apps/participation/forms.py:122
#: apps/participation/forms.py:131
msgid "This phase must end after the next phases."
msgstr "Cette phase doit finir avant les phases suivantes."
@ -312,7 +312,7 @@ msgid "Proposed solution:"
msgstr "Solution proposée :"
#: apps/participation/templates/participation/participation_detail.html:27
#: apps/participation/templates/participation/participation_detail.html:114
#: apps/participation/templates/participation/participation_detail.html:131
#: apps/participation/templates/participation/upload_video.html:11
#: apps/registration/templates/registration/upload_photo_authorization.html:18
#: apps/registration/templates/registration/user_detail.html:78
@ -331,7 +331,12 @@ msgstr "Solution envoyée :"
msgid "Team that received your solution:"
msgstr "Équipe qui a reçu votre solution :"
#: apps/participation/templates/participation/participation_detail.html:55
#: apps/participation/templates/participation/participation_detail.html:53
#: apps/participation/templates/participation/participation_detail.html:94
msgid "Change"
msgstr "Modifier"
#: apps/participation/templates/participation/participation_detail.html:60
msgid ""
"The mentioned team received your video. They are now watching your video, "
"and formulating questions. You would be able to exchange with the other "
@ -341,7 +346,7 @@ msgstr ""
"visionner, et de formuler des questions. Lors de la prochaine phase, vous "
"serez invités à répondre aux questions et échanger avec l'autre équipe."
#: apps/participation/templates/participation/participation_detail.html:63
#: apps/participation/templates/participation/participation_detail.html:68
#, python-format
msgid ""
"The other team sent you questions about your solution. Your are now able to "
@ -360,15 +365,15 @@ msgstr ""
"client Element dédié : <a href=\"https://element.correspondances-maths.fr"
"\">element.correpondances-maths.fr</a>"
#: apps/participation/templates/participation/participation_detail.html:81
#: apps/participation/templates/participation/participation_detail.html:86
msgid "Received solution"
msgstr "Solution reçue :"
#: apps/participation/templates/participation/participation_detail.html:85
#: apps/participation/templates/participation/participation_detail.html:90
msgid "Team that sent you their solution:"
msgstr "Équipe qui vous a envoyé leur solution :"
#: apps/participation/templates/participation/participation_detail.html:95
#: apps/participation/templates/participation/participation_detail.html:105
#, python-format
msgid ""
"You sent your questions to the other team about their solution. When they "
@ -387,20 +392,14 @@ msgstr ""
"client Element dédié : <a href=\"https://element.correspondances-maths.fr"
"\">element.correpondances-maths.fr</a>"
#: apps/participation/templates/participation/participation_detail.html:113
msgid "Upload video"
msgstr "Envoyer la vidéo"
#: apps/participation/templates/participation/participation_detail.html:117
msgid "Display solution"
msgstr "Afficher la solution"
#: apps/participation/templates/participation/participation_detail.html:118
msgid "This video platform is not supported yet."
msgstr "La plateforme de cette vidéo n'est pas encore supportée."
#: apps/participation/templates/participation/participation_detail.html:124
msgid "Define received video"
msgstr "Définir la vidéo reçue"
#: apps/participation/templates/participation/participation_detail.html:125
#: apps/participation/templates/participation/phase_form.html:11
#: apps/participation/templates/participation/phase_list.html:18
#: apps/participation/templates/participation/receive_participation_form.html:11
#: apps/participation/templates/participation/team_detail.html:64
#: apps/participation/templates/participation/team_detail.html:123
#: apps/participation/templates/participation/update_team.html:12
@ -410,6 +409,18 @@ msgstr "La plateforme de cette vidéo n'est pas encore supportée."
msgid "Update"
msgstr "Modifier"
#: apps/participation/templates/participation/participation_detail.html:130
msgid "Upload video"
msgstr "Envoyer la vidéo"
#: apps/participation/templates/participation/participation_detail.html:134
msgid "Display solution"
msgstr "Afficher la solution"
#: apps/participation/templates/participation/participation_detail.html:135
msgid "This video platform is not supported yet."
msgstr "La plateforme de cette vidéo n'est pas encore supportée."
#: apps/participation/templates/participation/phase_list.html:10
#: templates/base.html:68 templates/base.html:70 templates/base.html:217
msgid "Calendar"