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

Factor out the notable_participations and personal_notes prefetch

Is used in person_overview & coursebook.
parent 53245fb5
No related branches found
No related tags found
1 merge request!422Resolve "Add export functionality to course book"
......@@ -157,6 +157,29 @@ def generate_full_register_printout(
prefetched_persons.append(person)
# NEXT begins here:
def prefetch_notable_participations(*prefetch_related):
return Prefetch(
"participations",
to_attr="notable_participations",
queryset=ParticipationStatus.objects
.exclude(
Q(absence_reason__isnull=True)
| Q(tardiness__isnull=True)
)
.select_related("absence_reason")
.prefetch_related(*prefetch_related),
)
def prefetch_personal_notes(*prefetch_related):
return Prefetch(
"new_personal_notes",
queryset=NewPersonalNote.objects
.exclude(
Q(note="")
| Q(extra_mark=None))
.select_related("extra_mark")
.prefetch_related(*prefetch_related),
)
# build the query-set
group = Group.objects.filter(pk=group)
......@@ -198,40 +221,23 @@ def generate_full_register_printout(
if include_person_overviews:
doc_query_set = Documentation.objects.select_related("subject").prefetch_related("teachers"),
context["members"] = context["members"].prefetch_related(
Prefetch(
"participations",
queryset=ParticipationStatus.objects
.exclude(
Q(absence_reason__isnull=True)
| Q(tardiness__isnull=True)
prefetch_notable_participations(
Prefetch(
"related_documentation",
queryset=doc_query_set,
)
.select_related("absence_reason")
.prefetch_related(
Prefetch(
"related_documentation",
queryset=doc_query_set,
),
),
to_attr="notable_participations",
),
Prefetch(
"new_personal_notes",
queryset=NewPersonalNote.objects
.exclude(
Q(note="")
| Q(extra_marks=None))
.prefetch_related(
Prefetch(
"documentation",
queryset=doc_query_set,
),
"extra_mark",
prefetch_personal_notes(
Prefetch(
"documentation",
queryset=doc_query_set,
)
),
)
if include_coursebook:
context["documentations_by_day"] = {}
documentations.prefetch_related("participations", "personal_notes")
for day in documentations.dates("datetime_start", "day"):
context["documentations_by_day"][day] = documentations.filter(datetime_start__date=day)
......
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