diff --git a/common/urls.py b/common/urls.py index 2c2b1bb..fb54f0f 100644 --- a/common/urls.py +++ b/common/urls.py @@ -15,6 +15,8 @@ urlpatterns = [ url(r'^institutions/$', views.CorporationListView.as_view(), name='corporations'), url(r'^institutions/(?P\d+)/$', views.CorporationView.as_view(), name='corporation'), + url(r'^classes/$', views.KlassListView.as_view(), name='classes'), + url(r'^classes/(?P\d+)/$', views.KlassView.as_view(), name='class'), # AJAX/JSON urls url(r'^section/(?P\d+)/periods/', views.section_periods), diff --git a/stages/models.py b/stages/models.py index aa9092e..db6fe85 100644 --- a/stages/models.py +++ b/stages/models.py @@ -245,6 +245,7 @@ class Training(models.Model): class Meta: verbose_name = "Stage" + ordering = ("-availability__period",) def __str__(self): return '%s chez %s (%s)' % (self.student, self.availability.corporation, self.availability.period) diff --git a/stages/views.py b/stages/views.py index 23066c4..618c886 100644 --- a/stages/views.py +++ b/stages/views.py @@ -7,14 +7,14 @@ from tabimport import FileFactory from django.conf import settings from django.contrib import messages from django.core.urlresolvers import reverse -from django.db.models import Count +from django.db.models import Case, Count, When from django.http import HttpResponse, HttpResponseNotAllowed, HttpResponseRedirect from django.shortcuts import get_object_or_404 from django.utils.translation import ugettext as _ from django.views.generic import DetailView, FormView, TemplateView, ListView from .forms import PeriodForm, StudentImportForm -from .models import (Section, Student, Corporation, CorpContact, Period, +from .models import (Klass, Section, Student, Corporation, CorpContact, Period, Training, Referent, Availability) @@ -62,6 +62,24 @@ class CorporationView(DetailView): return context +class KlassListView(ListView): + queryset = Klass.objects.all().annotate(num_students=Count(Case(When(student__archived=False, then=1))) + ).filter(num_students__gt=0).order_by('section', 'name') + template_name = 'classes.html' + + +class KlassView(DetailView): + model = Klass + template_name = 'class.html' + context_object_name = 'klass' + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['students'] = self.object.student_set.filter(archived=False + ).prefetch_related('training_set').order_by('last_name', 'first_name') + return context + + class AttributionView(TemplateView): """ Base view for the attribution screen. Populate sections and referents. diff --git a/templates/admin/index.html b/templates/admin/index.html index d30e9ca..46fd726 100644 --- a/templates/admin/index.html +++ b/templates/admin/index.html @@ -20,6 +20,7 @@ {% if app_list %} diff --git a/templates/class.html b/templates/class.html new file mode 100644 index 0000000..be2af17 --- /dev/null +++ b/templates/class.html @@ -0,0 +1,27 @@ +{% extends "admin/base_site.html" %} +{% load i18n %} + +{% block breadcrumbs %} + +{% endblock %} + +{% block content %} +

{{ klass.name }}

+

Récapitulatif des stages

+ +{% for student in students %} + + + + {% for train in student.training_set.all %} + + {% endfor %} + +{% endfor %} +
{{ student }}{{ student.birth_date }}{{ train.availability.period }}
{{ train.availability.corporation }}
+ {% if train.comment %}
{% endif %} + {{ train.availability.domain }}
+{% endblock %} diff --git a/templates/classes.html b/templates/classes.html new file mode 100644 index 0000000..09b70d9 --- /dev/null +++ b/templates/classes.html @@ -0,0 +1,27 @@ +{% extends "admin/base_site.html" %} + +{% block extrastyle %} + +{% endblock %} + +{% block content %} +

Liste des classes

+ +{% regroup object_list by section as classes %} + +{% for section in classes %} +
+ + + {% for class in section.list %} + + + + + {% endfor %} +
{{ section.grouper }}
{{ class.name }}{{ class.num_students }} étudiants
+
+{% endfor %} +{% endblock %}