Skip to content
Snippets Groups Projects
Commit 10f6a645 authored by permcu's avatar permcu
Browse files

Prepare the documentations for the coursebook-template

parent aee8c0bd
No related branches found
No related tags found
1 merge request!422Resolve "Add export functionality to course book"
......@@ -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)
......@@ -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
......
{% 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">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment