From e47314b85c67f69f81869a617088e24feb395d7e Mon Sep 17 00:00:00 2001 From: Michael Bauer <michael-bauer@posteo.de> Date: Thu, 24 Oct 2024 20:41:35 +0200 Subject: [PATCH] Adapt the register_teachers_and_subjects_table to the new datamodel --- aleksis/apps/alsijil/tasks.py | 22 +++++++++++++++++++ .../register_teachers_and_subjects_table.html | 12 ++++------ .../alsijil/print/register_for_group.html | 6 ++--- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/aleksis/apps/alsijil/tasks.py b/aleksis/apps/alsijil/tasks.py index 72fc90353..70bf2ab45 100644 --- a/aleksis/apps/alsijil/tasks.py +++ b/aleksis/apps/alsijil/tasks.py @@ -14,6 +14,8 @@ from aleksis.core.models import Group, PDFFile from aleksis.core.util.celery_progress import ProgressRecorder, recorded_task from aleksis.core.util.pdf import generate_pdf_from_template +from aleksis.apps.cursus.models import Course + from .models import ExtraMark @@ -152,6 +154,26 @@ def generate_full_register_printout( person.filtered_notes = sorted_personal_notes["person"].get(person.pk, []) prefetched_persons.append(person) + # NEXT begins here: + + # build the query-set + group = Group.objects.filter(pk=group) + + if include_teachers_and_subjects_table: + group = group.prefetch_related( + "courses", + "courses__subject", + "courses__teachers", + "child_groups", + "child_groups__courses", + "child_groups__courses__subject", + "child_groups__courses__teachers", + ) + + context["group"] = group[0] + + # OLD + context["school_term"] = group.school_term context["persons"] = prefetched_persons context["excuse_types"] = ExcuseType.objects.filter(count_as_absent=True) diff --git a/aleksis/apps/alsijil/templates/alsijil/partials/register_teachers_and_subjects_table.html b/aleksis/apps/alsijil/templates/alsijil/partials/register_teachers_and_subjects_table.html index d3de44993..d9c3409d7 100644 --- a/aleksis/apps/alsijil/templates/alsijil/partials/register_teachers_and_subjects_table.html +++ b/aleksis/apps/alsijil/templates/alsijil/partials/register_teachers_and_subjects_table.html @@ -6,24 +6,20 @@ {% endif %} <th>{% trans 'Subject' %}</th> <th>{% trans 'Teacher' %}</th> - <th>{% trans 'Lesson start' %}</th> - <th>{% trans 'Lesson end' %}</th> <th>{% trans 'Per week' %}</th> </tr> </thead> <tbody> {% for group in groups %} - {% for lesson in group.lessons.all %} + {% for course in group.courses.all %} <tr> {% if len(groups) > 1 %} <td>{{ group.name }}</td> {% endif %} - <td>{{ lesson.subject.name }}</td> - <td>{{ lesson.teachers.all|join:', ' }}</td> - <td>{{ lesson.validity.date_start }}</td> - <td>{{ lesson.validity.date_end }}</td> - <td>{{ lesson.lesson_periods.count }}</td> + <td>{{ course.subject.name }}</td> + <td>{{ course.teachers.all|join:', ' }}</td> + <td>{{ course.lesson_quota }}</td> </tr> {% endfor %} {% endfor %} diff --git a/aleksis/apps/alsijil/templates/alsijil/print/register_for_group.html b/aleksis/apps/alsijil/templates/alsijil/print/register_for_group.html index 5d740a2a3..d42aecfa0 100644 --- a/aleksis/apps/alsijil/templates/alsijil/print/register_for_group.html +++ b/aleksis/apps/alsijil/templates/alsijil/print/register_for_group.html @@ -30,14 +30,14 @@ <div class="page-break"> </div> {% if include_teachers_and_subjects_table %} - {% if group.lessons %} + {% if group.courses %} <h4>{% trans 'Teachers and lessons in group' %} {{ group.name }}</h4> {% include "alsijil/partials/register_teachers_and_subjects_table.html" with groups=[group] only %} <div class="page-break"> </div> {% endif %} - {% if child_groups %} + {% if group.child_groups %} <h4>{% trans 'Teachers and lessons in child groups' %}</h4> - {% include "alsijil/partials/register_teachers_and_subjects_table.html" with groups=child_groups only} + {% include "alsijil/partials/register_teachers_and_subjects_table.html" with groups=group.child_groups only} <div class="page-break"> </div> {% endif %} {% endif %} -- GitLab