Skip to content
Snippets Groups Projects
Verified Commit bcf33900 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Track whether participation has been filled already

parent 0c756e6f
No related branches found
No related tags found
1 merge request!360Resolve "Add absence management to course book student dialog"
Pipeline #188704 failed
# Generated by Django 5.0.6 on 2024-06-06 09:36
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('alsijil', '0021_remove_participationstatus_absent_and_more'),
]
operations = [
migrations.AddField(
model_name='documentation',
name='participation_touched_at',
field=models.DateTimeField(blank=True, null=True, verbose_name='Participation touched at'),
),
]
......@@ -9,6 +9,7 @@ from django.db.models import QuerySet
from django.db.models.constraints import CheckConstraint
from django.db.models.query_utils import Q
from django.urls import reverse
from django.utils import timezone
from django.utils.formats import date_format
from django.utils.timezone import localdate, localtime
from django.utils.translation import gettext_lazy as _
......@@ -489,6 +490,11 @@ class Documentation(CalendarEvent):
homework = models.CharField(verbose_name=_("Homework"), max_length=255, blank=True)
group_note = models.CharField(verbose_name=_("Group Note"), max_length=255, blank=True)
# Used to track whether participations have been filled in
participation_touched_at = models.DateTimeField(
blank=True, null=True, verbose_name=_("Participation touched at")
)
def get_subject(self) -> str:
if self.subject:
return self.subject
......@@ -698,17 +704,13 @@ class Documentation(CalendarEvent):
"""Ensure that participation statuses are created for this documentation."""
# TODO: Check for preexisting absences in kolego
if not self.amends or self.datetime_start <= localtime():
# There is no source to update from or it's to early
if self.participation_touched_at or not self.amends or self.datetime_start > localtime():
# There is no source to update from or it's too early
return
lesson_event: LessonEvent = self.amends
all_members = lesson_event.all_members
existing_participations = ParticipationStatus.objects.filter(related_documentation=self)
if existing_participations.exists():
return
new_persons = Person.objects.filter(Q(pk__in=[p.pk for p in all_members])).prefetch_related(
"member_of"
)
......@@ -730,6 +732,10 @@ class Documentation(CalendarEvent):
]
new_participations.append(participation_status)
ParticipationStatus.groups_of_person.through.objects.bulk_create(new_groups_of_person)
self.participation_touched_at = timezone.now()
self.save()
return new_participations
......
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