From e9c56104df19aae21c507f16fe32e603607a0a84 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 31 Oct 2020 12:51:49 +0100 Subject: [PATCH] Define the received participation --- apps/participation/forms.py | 16 ++++++ .../participation/participation_detail.html | 32 +++++++++-- .../receive_participation_form.html | 14 +++++ apps/participation/urls.py | 6 ++- apps/participation/views.py | 16 +++++- locale/fr/LC_MESSAGES/django.po | 53 +++++++++++-------- 6 files changed, 108 insertions(+), 29 deletions(-) create mode 100644 apps/participation/templates/participation/receive_participation_form.html diff --git a/apps/participation/forms.py b/apps/participation/forms.py index fdc9802..47256bd 100644 --- a/apps/participation/forms.py +++ b/apps/participation/forms.py @@ -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. diff --git a/apps/participation/templates/participation/participation_detail.html b/apps/participation/templates/participation/participation_detail.html index a59b220..bef3de4 100644 --- a/apps/participation/templates/participation/participation_detail.html +++ b/apps/participation/templates/participation/participation_detail.html @@ -46,8 +46,13 @@
-
{% trans "Team that received your solution:" %}
-
{{ participation.sent_participation|default:any }}
+
{% trans "Team that received your solution:" %}
+
{{ participation.sent_participation.team|default:any }}
+ {% if user.registration.is_admin %} +
+ +
+ {% endif %}
{% if current_phase.phase_number == 2 %} @@ -82,8 +87,13 @@
-
{% trans "Team that sent you their solution:" %}
-
{{ participation.received_participation|default:any }}
+
{% trans "Team that sent you their solution:" %}
+
{{ participation.received_participation.team|default:any }}
+ {% if user.registration.is_admin %} +
+ +
+ {% endif %}
{# TODO Display solution #} @@ -110,6 +120,13 @@
{% 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 %}