From 95e1c4f8214beab6250f7a3ee0c1b25b72c34c41 Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Sat, 31 Oct 2020 13:35:00 +0100 Subject: [PATCH] Define the team which receives our video --- apps/participation/forms.py | 29 +++++++++++++++ .../participation/participation_detail.html | 12 ++++++- .../send_participation_form.html | 14 ++++++++ apps/participation/urls.py | 7 ++-- apps/participation/views.py | 16 +++++++-- locale/fr/LC_MESSAGES/django.po | 36 ++++++++++++------- 6 files changed, 96 insertions(+), 18 deletions(-) create mode 100644 apps/participation/templates/participation/send_participation_form.html diff --git a/apps/participation/forms.py b/apps/participation/forms.py index 47256bd..d43a073 100644 --- a/apps/participation/forms.py +++ b/apps/participation/forms.py @@ -115,6 +115,35 @@ class ReceiveParticipationForm(forms.ModelForm): fields = ('received_participation',) +class SendParticipationForm(forms.ModelForm): + """ + Update the sent participation of a participation. + """ + sent_participation = forms.ModelChoiceField( + queryset=Participation.objects, + label=lambda: _("Send to team"), + ) + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.fields["sent_participation"].initial = self.instance.sent_participation + self.fields["sent_participation"].queryset = Participation.objects.filter( + ~Q(pk=self.instance.pk) & Q(problem=self.instance.problem, valid=True) + ) + + def clean(self, commit=True): + cleaned_data = super().clean() + participation = cleaned_data["sent_participation"] + participation.received_participation = self.instance + self.instance = participation + return cleaned_data + + + class Meta: + model = Participation + fields = ('sent_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 bef3de4..878292b 100644 --- a/apps/participation/templates/participation/participation_detail.html +++ b/apps/participation/templates/participation/participation_detail.html @@ -50,7 +50,7 @@
{{ participation.sent_participation.team|default:any }}
{% if user.registration.is_admin %}
- +
{% endif %} @@ -125,6 +125,11 @@ {% trans "Update" as modal_button %} {% url "participation:participation_receive_participation" pk=participation.pk as modal_action %} {% include "base_modal.html" with modal_id="defineReceivedParticipation" %} + + {% trans "Define team that receives your video" as modal_title %} + {% trans "Update" as modal_button %} + {% url "participation:participation_send_participation" pk=participation.pk as modal_action %} + {% include "base_modal.html" with modal_id="defineSentParticipation" %} {% endif %} {% trans "Upload video" as modal_title %} @@ -145,6 +150,11 @@ if (!modalBody.html().trim()) modalBody.load("{% url "participation:participation_receive_participation" pk=participation.pk %} #form-content"); }); + $('button[data-target="#defineSentParticipationModal"]').click(function() { + let modalBody = $("#defineSentParticipationModal div.modal-body"); + if (!modalBody.html().trim()) + modalBody.load("{% url "participation:participation_send_participation" pk=participation.pk %} #form-content"); + }); {% endif %} $('button[data-target="#uploadSolutionModal"]').click(function() { let modalBody = $("#uploadSolutionModal div.modal-body"); diff --git a/apps/participation/templates/participation/send_participation_form.html b/apps/participation/templates/participation/send_participation_form.html new file mode 100644 index 0000000..a5bb901 --- /dev/null +++ b/apps/participation/templates/participation/send_participation_form.html @@ -0,0 +1,14 @@ +{% extends "base.html" %} + +{% load crispy_forms_filters i18n %} + +{% block content %} +
+
+ {% csrf_token %} + {{ form|crispy }} +
+ +
+{% endblock content %} + diff --git a/apps/participation/urls.py b/apps/participation/urls.py index a241c97..f2fbf6f 100644 --- a/apps/participation/urls.py +++ b/apps/participation/urls.py @@ -2,8 +2,9 @@ from django.urls import path from django.views.generic import TemplateView from .views import CalendarView, CreateTeamView, JoinTeamView, MyParticipationDetailView, MyTeamDetailView, \ - ParticipationDetailView, PhaseUpdateView, SetParticipationReceiveParticipationView, TeamAuthorizationsView, \ - TeamDetailView, TeamLeaveView, TeamUpdateView, UploadVideoView + ParticipationDetailView, PhaseUpdateView, SetParticipationReceiveParticipationView, \ + SetParticipationSendParticipationView, TeamAuthorizationsView, TeamDetailView, TeamLeaveView, TeamUpdateView, \ + UploadVideoView app_name = "participation" @@ -21,6 +22,8 @@ urlpatterns = [ path("detail/upload-video//", UploadVideoView.as_view(), name="upload_video"), path("detail//receive-participation/", SetParticipationReceiveParticipationView.as_view(), name="participation_receive_participation"), + path("detail//send-participation/", SetParticipationSendParticipationView.as_view(), + name="participation_send_participation"), path("calendar/", CalendarView.as_view(), name="calendar"), path("calendar//", PhaseUpdateView.as_view(), name="update_phase"), path("chat/", TemplateView.as_view(template_name="participation/chat.html"), name="chat") diff --git a/apps/participation/views.py b/apps/participation/views.py index d32c3d4..8b5abf1 100644 --- a/apps/participation/views.py +++ b/apps/participation/views.py @@ -20,8 +20,8 @@ from django_tables2 import SingleTableView from magic import Magic from registration.models import AdminRegistration -from .forms import JoinTeamForm, ParticipationForm, PhaseForm, ReceiveParticipationForm, RequestValidationForm,\ - TeamForm, UploadVideoForm, ValidateParticipationForm +from .forms import JoinTeamForm, ParticipationForm, PhaseForm, ReceiveParticipationForm, RequestValidationForm, \ + SendParticipationForm, TeamForm, UploadVideoForm, ValidateParticipationForm from .models import Participation, Phase, Team, Video from .tables import CalendarTable @@ -370,6 +370,18 @@ class SetParticipationReceiveParticipationView(AdminMixin, UpdateView): return reverse_lazy("participation:participation_detail", args=(self.object.pk,)) +class SetParticipationSendParticipationView(AdminMixin, UpdateView): + """ + Define the team where the solution will be sent. + """ + model = Participation + form_class = SendParticipationForm + template_name = "participation/send_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. diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index 53c29a3..c6f385c 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: Corres2math\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2020-10-31 12:36+0100\n" +"POT-Creation-Date: 2020-10-31 13:32+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: Yohann D'ANELLO \n" "Language-Team: LANGUAGE \n" @@ -99,35 +99,39 @@ msgstr "changelogs" msgid "Changelog of type \"{action}\" for model {model} at {timestamp}" msgstr "Changelog de type \"{action}\" pour le modèle {model} le {timestamp}" -#: apps/participation/forms.py:19 apps/participation/models.py:33 +#: apps/participation/forms.py:20 apps/participation/models.py:33 msgid "The trigram must be composed of three uppercase letters." msgstr "Le trigramme doit être composé de trois lettres majuscules." -#: apps/participation/forms.py:34 +#: apps/participation/forms.py:35 msgid "No team was found with this access code." msgstr "Aucune équipe n'a été trouvée avec ce code d'accès." -#: apps/participation/forms.py:68 +#: apps/participation/forms.py:69 msgid "I engage myself to participate to the whole \"Correspondances\"." msgstr "Je m'engage à participer à l'intégralité des Correspondances." -#: apps/participation/forms.py:83 +#: apps/participation/forms.py:84 msgid "Message to address to the team:" msgstr "Message à adresser à l'équipe :" -#: apps/participation/forms.py:98 +#: apps/participation/forms.py:99 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:127 +#: apps/participation/forms.py:124 +msgid "Send to team" +msgstr "Envoyer à l'équipe" + +#: apps/participation/forms.py:162 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:129 +#: apps/participation/forms.py:164 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:131 +#: apps/participation/forms.py:166 msgid "This phase must end after the next phases." msgstr "Cette phase doit finir avant les phases suivantes." @@ -312,7 +316,7 @@ msgid "Proposed solution:" msgstr "Solution proposée :" #: apps/participation/templates/participation/participation_detail.html:27 -#: apps/participation/templates/participation/participation_detail.html:131 +#: apps/participation/templates/participation/participation_detail.html:136 #: 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 @@ -397,9 +401,11 @@ msgid "Define received video" msgstr "Définir la vidéo reçue" #: apps/participation/templates/participation/participation_detail.html:125 +#: apps/participation/templates/participation/participation_detail.html:130 #: 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/send_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 @@ -409,15 +415,19 @@ msgstr "Définir la vidéo reçue" msgid "Update" msgstr "Modifier" -#: apps/participation/templates/participation/participation_detail.html:130 +#: apps/participation/templates/participation/participation_detail.html:129 +msgid "Define team that receives your video" +msgstr "Définir l'équipe qui recevra votre vidéo" + +#: apps/participation/templates/participation/participation_detail.html:135 msgid "Upload video" msgstr "Envoyer la vidéo" -#: apps/participation/templates/participation/participation_detail.html:134 +#: apps/participation/templates/participation/participation_detail.html:139 msgid "Display solution" msgstr "Afficher la solution" -#: apps/participation/templates/participation/participation_detail.html:135 +#: apps/participation/templates/participation/participation_detail.html:140 msgid "This video platform is not supported yet." msgstr "La plateforme de cette vidéo n'est pas encore supportée."