From 10f6a64517ca10992d087a8b2931d8a42635e6b9 Mon Sep 17 00:00:00 2001 From: Michael Bauer <michael-bauer@posteo.de> Date: Mon, 28 Oct 2024 16:13:49 +0100 Subject: [PATCH] Prepare the documentations for the coursebook-template --- aleksis/apps/alsijil/model_extensions.py | 17 +++++++++++------ aleksis/apps/alsijil/tasks.py | 14 +++++++++++++- .../alsijil/partials/register_coursebook.html | 2 +- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/aleksis/apps/alsijil/model_extensions.py b/aleksis/apps/alsijil/model_extensions.py index d28f5bb41..820770d63 100644 --- a/aleksis/apps/alsijil/model_extensions.py +++ b/aleksis/apps/alsijil/model_extensions.py @@ -93,6 +93,16 @@ def annotate_person_statistics( return persons +def annotate_person_statistics_from_documentations(docs: QuerySet[Documentation]) -> QuerySet[Person]: + """Annotate a queryset of persons with class register statistics from queryset of documentations.""" + docs = list(documentations.values_list("pk", flat=True)) + return annotate_person_statistics( + persons, + Q(participations__related_documentation__in=docs), + Q(new_personal_notes__documentation__in=docs), + ) + + def annotate_person_statistics_for_school_term( persons: QuerySet[Person], school_term: SchoolTerm, group: Group | None = None ) -> QuerySet[Person]: @@ -103,9 +113,4 @@ def annotate_person_statistics_for_school_term( ) if group: documentations.filter(Q(course__groups=group) | Q(course__groups__parent_groups=group)) - docs = list(documentations.values_list("pk", flat=True)) - return annotate_person_statistics( - persons, - Q(participations__related_documentation__in=docs), - Q(new_personal_notes__documentation__in=docs), - ) + return annotate_person_statistics_from_documentations(documentations) diff --git a/aleksis/apps/alsijil/tasks.py b/aleksis/apps/alsijil/tasks.py index e8cab0065..882bbc1ae 100644 --- a/aleksis/apps/alsijil/tasks.py +++ b/aleksis/apps/alsijil/tasks.py @@ -185,8 +185,15 @@ def generate_full_register_printout( group = group[0] context["group"] = group + if include_members_table or include_person_overviews or include_coursebook: + documentations = Documentation.objects.filter( + Q(datetime_start__date__gte=group.school_term.date_start) + & Q(datetime_end__date__lte=group.school_term.date_end) + & (Q(course__groups=group) | Q(course__groups__parent_groups=group)) + ) + if include_members_table or include_person_overviews: - context["members"] = annotate_person_statistics_for_school_term(group.members.all(), group.school_term, group) + context["members"] = annotate_person_statistics_from_documentations(documentations) if include_person_overviews: doc_query_set = Documentation.objects.select_related("subject").prefetch_related("teachers"), @@ -223,6 +230,11 @@ def generate_full_register_printout( ), ) + if include_coursebook: + context["documentations_by_day"] = {} + for day in documentations.dates("datetime_start", "day"): + context["documentations_by_day"][day] = documentations.filter(datetime_start__date=day) + # OLD context["school_term"] = group.school_term diff --git a/aleksis/apps/alsijil/templates/alsijil/partials/register_coursebook.html b/aleksis/apps/alsijil/templates/alsijil/partials/register_coursebook.html index 122eedc75..7931a9675 100644 --- a/aleksis/apps/alsijil/templates/alsijil/partials/register_coursebook.html +++ b/aleksis/apps/alsijil/templates/alsijil/partials/register_coursebook.html @@ -1,4 +1,4 @@ -{% for week in weeks %} +{% for day, documentations in documentations_by_day %} <h4>{% trans 'Week' %} {{ week.week }}: {{ week.0 }}–{{ week.6 }}</h4> <table class="small-print"> -- GitLab