From 7b15103add9497286706ec5c79616614be43aeef Mon Sep 17 00:00:00 2001 From: Yoan Le Clanche Date: Wed, 6 Oct 2021 15:26:20 +0200 Subject: [PATCH] Add quotas list page : https://trackers.pilotsystems.net/prebarreau/0250 --- teleforma/exam/templates/exam/quotas.html | 33 +++++++++++++++- teleforma/exam/urls.py | 7 +++- teleforma/exam/views.py | 46 +++++++++++++++++++++-- teleforma/templates/teleforma/base.html | 13 +++++++ 4 files changed, 92 insertions(+), 7 deletions(-) diff --git a/teleforma/exam/templates/exam/quotas.html b/teleforma/exam/templates/exam/quotas.html index dedc3e16..46f740e7 100644 --- a/teleforma/exam/templates/exam/quotas.html +++ b/teleforma/exam/templates/exam/quotas.html @@ -12,31 +12,60 @@
+
+ + + + + + + +
+
+ + - + {% for quota in object_list %} + + - + {% endfor %} diff --git a/teleforma/exam/urls.py b/teleforma/exam/urls.py index d8977f19..ddf3aab6 100644 --- a/teleforma/exam/urls.py +++ b/teleforma/exam/urls.py @@ -32,7 +32,7 @@ # # Authors: Guillaume Pellerin -from teleforma.exam.views import MassScoreCreateView, ScoreCreateView, ScriptCreateView, ScriptView, ScriptsPendingView, ScriptsRejectedView, ScriptsScoreAllView, ScriptsScoreCourseView, ScriptsTreatedView, ScriptsView, get_correctors, get_mass_students +from teleforma.exam.views import MassScoreCreateView, ScoreCreateView, ScriptCreateView, ScriptView, ScriptsPendingView, ScriptsRejectedView, ScriptsScoreAllView, ScriptsScoreCourseView, ScriptsTreatedView, ScriptsView, get_correctors, get_mass_students, QuotasView from django.conf.urls import url @@ -51,4 +51,9 @@ urlpatterns = [ url(r'^scripts/get-correctors/$', get_correctors, name="teleforma-exam-get-correctors"), url(r'^scripts/get-mass-students/$', get_mass_students, name="teleforma-exam-get-mass-students"), + + url(r'^quotas/periods/(?P.*)/list/$', + QuotasView.as_view(), + name="teleforma-exam-quotas"), + ] diff --git a/teleforma/exam/views.py b/teleforma/exam/views.py index 309927c5..8eb464f9 100755 --- a/teleforma/exam/views.py +++ b/teleforma/exam/views.py @@ -12,7 +12,7 @@ from django.contrib.auth.decorators import permission_required from django.contrib.auth.models import User from django.db.models import Q from django.http.response import HttpResponse -from django.shortcuts import redirect +from django.shortcuts import get_object_or_404, redirect from django.urls import reverse_lazy from django.utils.decorators import method_decorator from django.utils.translation import ugettext @@ -318,12 +318,50 @@ class ScriptUpdateView(UpdateView): class QuotasView(ListView): - model = Quota template_name = 'exam/quotas.html' - @method_decorator(access_required) + def setup(self, request, *args, **kwargs): + super().setup(request, *args, **kwargs) + self.professor = self.request.user.professor.get() + self.courses = self.professor.courses.all() + self.period = get_object_or_404( + Period, id=int(self.kwargs['period_id'])) + self.nb_script = self.period.nb_script or settings.TELEFORMA_EXAM_MAX_SESSIONS + self.session = self.request.GET.get('session') + self.course = self.request.GET.get('course') + self.corrector = self.request.GET.get('corrector') + + def get_base_queryset(self): + return Quota.objects.filter(period=self.period, course__in=self.courses) + + def get_queryset(self): + query = self.get_base_queryset() + if self.session: + query = query.filter(session=self.session) + if self.course: + query = query.filter(course__id=self.course) + if self.corrector: + query = query.filter(corrector__id=self.corrector) + return query.order_by('course', 'session', 'corrector', 'date_start') + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + correctors = User.objects.filter( + quotas__in=self.get_base_queryset()).order_by('last_name').distinct() + context['correctors_list'] = [ + (str(corrector.id), corrector.get_full_name()) for corrector in correctors] + context['corrector_selected'] = self.corrector + session_choices = get_n_choices(self.nb_script + 1) + context['sessions_list'] = session_choices + context['session_selected'] = self.session + context['courses_list'] = [ + (str(course.id), course.title) for course in self.courses] + context['course_selected'] = self.course + return context + + @staff_required def dispatch(self, *args, **kwargs): - return super(QuotasView, self).dispatch(*args, **kwargs) + return super().dispatch(*args, **kwargs) class ScriptsScoreAllView(ScriptsTreatedView): diff --git a/teleforma/templates/teleforma/base.html b/teleforma/templates/teleforma/base.html index 28494ba0..295aa32c 100644 --- a/teleforma/templates/teleforma/base.html +++ b/teleforma/templates/teleforma/base.html @@ -121,11 +121,24 @@ {% endif %} {% endif %} + + {% if user.professor.count %} +
  •  {% trans "Quotas" %} + +
  • + {% endif %} {% if user.professor.count or user.is_superuser %}
  • Webclass
  • {% endif %} + + {% if periods|length == 1 %}
  •  {% trans "Scores" %}
  • -- 2.39.5
    {% trans "Corrector"%}{% trans "Period"%} {% trans "Course"%}{% trans "Session"%} {% trans "date start"%} {% trans "date end"%} {% trans "Pending"%} {% trans "Marked"%} {% trans "Value"%}{% trans "Level"%} (%){% trans "Level"%}
    {{ quota.corrector.username }}{{ quota.period.name }} {{ quota.course.title }}{{ quota.session }} {{ quota.date_start }} {{ quota.date_end }} {{ quota.pending_script_count }} {{ quota.marked_script_count }} {{ quota.value }}{{ quota.level|floatformat }} 100 %}style="color:#FF5050"{% endif %}>{{ quota.level|floatformat }}%