Adapter liste élèves en fonction des sections
This commit is contained in:
parent
a7efd0cd0e
commit
29d5f6e310
2 changed files with 43 additions and 13 deletions
|
|
@ -99,8 +99,13 @@ class KlassView(DetailView):
|
|||
|
||||
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')
|
||||
context.update({
|
||||
'students': self.object.student_set.filter(archived=False
|
||||
).prefetch_related('training_set').order_by('last_name', 'first_name'),
|
||||
'show_option_ase': self.object.section.name.endswith('ASE'),
|
||||
'show_pp': self.object.section.is_ESTER,
|
||||
'show_employeur': not self.object.section.is_ESTER,
|
||||
})
|
||||
return context
|
||||
|
||||
def render_to_response(self, context, **response_kwargs):
|
||||
|
|
@ -108,22 +113,37 @@ class KlassView(DetailView):
|
|||
return super().render_to_response(context, **response_kwargs)
|
||||
|
||||
export = OpenXMLExport(self.object.name)
|
||||
# Headers
|
||||
export.write_line([
|
||||
'Nom', 'Prénom', 'Domicile', 'Date de naissance',
|
||||
'Stage 1', 'Domaine 1', 'Stage 2', 'Domaine 2', 'Stage 3', 'Domaine 3',
|
||||
], bold=True, col_widths=[18, 15, 20, 14, 25, 12, 25, 12, 25, 12])
|
||||
headers = ['Nom', 'Prénom', 'Domicile', 'Date de naissance']
|
||||
col_widths = [18, 15, 20, 14]
|
||||
if context['show_option_ase']:
|
||||
headers.append('Orientation')
|
||||
col_widths.append(20)
|
||||
if context['show_employeur']:
|
||||
headers.append('Employeur')
|
||||
col_widths.append(24)
|
||||
if context['show_pp']:
|
||||
headers.extend(['Stage 1', 'Domaine 1', 'Stage 2', 'Domaine 2', 'Stage 3', 'Domaine 3'])
|
||||
col_widths.extend([25, 12, 25, 12, 25, 12])
|
||||
export.write_line(headers, bold=True, col_widths=col_widths)
|
||||
# Data
|
||||
for student in context['students']:
|
||||
values = [
|
||||
student.last_name, student.first_name,
|
||||
" ".join([student.pcode, student.city]), student.birth_date,
|
||||
]
|
||||
for training in student.training_set.select_related(
|
||||
'availability', 'availability__corporation', 'availability__domain'
|
||||
).all():
|
||||
values.append(training.availability.corporation.name)
|
||||
values.append(training.availability.domain.name)
|
||||
if context['show_option_ase']:
|
||||
values.append(str(student.option_ase))
|
||||
if context['show_employeur']:
|
||||
values.append(
|
||||
", ".join([student.corporation.name, student.corporation.city])
|
||||
if student.corporation else ''
|
||||
)
|
||||
if context['show_pp']:
|
||||
for training in student.training_set.select_related(
|
||||
'availability', 'availability__corporation', 'availability__domain'
|
||||
).all():
|
||||
values.append(training.availability.corporation.name)
|
||||
values.append(training.availability.domain.name)
|
||||
export.write_line(values)
|
||||
|
||||
return export.get_http_response('%s_export' % self.object.name.replace(' ', '_'))
|
||||
|
|
|
|||
|
|
@ -17,17 +17,27 @@
|
|||
<h3>Liste des éléves</h3>
|
||||
<table>
|
||||
<thead>
|
||||
<th>Nom, prénom</th><th>Date naiss.</th><th>Récapitulatif des PP</th>
|
||||
<th>Nom, prénom</th>
|
||||
<th>Date naiss.</th>
|
||||
{% if show_option_ase %}<th>Orientation</th>{% endif %}
|
||||
{% if show_pp %}<th>Récapitulatif des PP</th>{% endif %}
|
||||
{% if show_employeur %}<th>Employeur</th>{% endif %}
|
||||
</thead>
|
||||
{% 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>
|
||||
{% if show_option_ase %}
|
||||
<td>{{ student.option_ase|default_if_none:'-' }}</td>
|
||||
{% endif %}
|
||||
{% if show_pp %}
|
||||
{% 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 'admin/img/icon-unknown.svg' %}" title="{{ train.comment }}"></div>{% endif %}
|
||||
<i>{{ train.availability.domain }}</i></td>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
{% if show_employeur %}<td>{{ student.corporation.name }}, {{ student.corporation.city }}</td>{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue