mirror of
https://gitlab.com/animath/si/plateforme-corres2math.git
synced 2025-06-21 21:58:23 +02:00
Define the team which receives our video
This commit is contained in:
@ -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.
|
||||
|
@ -50,7 +50,7 @@
|
||||
<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>
|
||||
<button class="btn btn-primary" data-toggle="modal" data-target="#defineSentParticipationModal">{% trans "Change" %}</button>
|
||||
</dd>
|
||||
{% endif %}
|
||||
</dl>
|
||||
@ -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");
|
||||
|
@ -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 %}
|
||||
|
@ -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/<int:pk>/", UploadVideoView.as_view(), name="upload_video"),
|
||||
path("detail/<int:pk>/receive-participation/", SetParticipationReceiveParticipationView.as_view(),
|
||||
name="participation_receive_participation"),
|
||||
path("detail/<int:pk>/send-participation/", SetParticipationSendParticipationView.as_view(),
|
||||
name="participation_send_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")
|
||||
|
@ -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.
|
||||
|
Reference in New Issue
Block a user