Add class listings with training summary
This commit is contained in:
parent
6c9ab66ae7
commit
538db63679
6 changed files with 78 additions and 2 deletions
|
|
@ -15,6 +15,8 @@ urlpatterns = [
|
|||
|
||||
url(r'^institutions/$', views.CorporationListView.as_view(), name='corporations'),
|
||||
url(r'^institutions/(?P<pk>\d+)/$', views.CorporationView.as_view(), name='corporation'),
|
||||
url(r'^classes/$', views.KlassListView.as_view(), name='classes'),
|
||||
url(r'^classes/(?P<pk>\d+)/$', views.KlassView.as_view(), name='class'),
|
||||
|
||||
# AJAX/JSON urls
|
||||
url(r'^section/(?P<pk>\d+)/periods/', views.section_periods),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
<ul id="main">
|
||||
<li><b><a href="{% url 'corporations' %}">Liste des institutions</a></b></li>
|
||||
<li><b><a href="{% url 'classes' %}">Liste des classes</a></b></li>
|
||||
</ul>
|
||||
|
||||
{% if app_list %}
|
||||
|
|
|
|||
27
templates/class.html
Normal file
27
templates/class.html
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{% extends "admin/base_site.html" %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block breadcrumbs %}
|
||||
<div class="breadcrumbs">
|
||||
<a href="{% url 'admin:index' %}">{% trans 'Home' %}</a>
|
||||
› <a href="{% url 'classes' %}">Liste des classes</a>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>{{ klass.name }}</h2>
|
||||
<h3>Récapitulatif des stages</h3>
|
||||
<table>
|
||||
{% for student in students %}
|
||||
<tr class="{% cycle 'row1' 'row2' %}">
|
||||
<td><a href="{% url 'admin:stages_student_change' student.pk %}">{{ student }}</a></td>
|
||||
<td>{{ student.birth_date }}</td>
|
||||
{% for train in student.training_set.all %}
|
||||
<td>{{ train.availability.period }}<br>{{ train.availability.corporation }}<br>
|
||||
{% if train.comment %}<div style="float: right;"><img src="{{ STATIC_URL}}admin/img/icon-unknown.svg" title="{{ train.comment }}"></div>{% endif %}
|
||||
<i>{{ train.availability.domain }}</i></td>
|
||||
{% endfor %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endblock %}
|
||||
27
templates/classes.html
Normal file
27
templates/classes.html
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{% extends "admin/base_site.html" %}
|
||||
|
||||
{% block extrastyle %}
|
||||
<style>
|
||||
div.section {border: 1px solid #ccc; float: left; margin-right: 5em;}
|
||||
</style>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<h2>Liste des classes</h2>
|
||||
|
||||
{% regroup object_list by section as classes %}
|
||||
|
||||
{% for section in classes %}
|
||||
<div class="section">
|
||||
<table>
|
||||
<tr><td><b>{{ section.grouper }}</b></td></tr>
|
||||
{% for class in section.list %}
|
||||
<tr class="{% cycle 'row1' 'row2' %}">
|
||||
<td><a href="{% url 'class' class.pk %}">{{ class.name }}</a></td>
|
||||
<td>{{ class.num_students }} étudiants</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endblock %}
|
||||
Loading…
Add table
Add a link
Reference in a new issue