diff --git a/aleksis/apps/alsijil/migrations/0022_documentation_participation_touched_at.py b/aleksis/apps/alsijil/migrations/0022_documentation_participation_touched_at.py new file mode 100644 index 0000000000000000000000000000000000000000..ef09ddca37a893128571818368982e29bd0c219f --- /dev/null +++ b/aleksis/apps/alsijil/migrations/0022_documentation_participation_touched_at.py @@ -0,0 +1,18 @@ +# 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'), + ), + ] diff --git a/aleksis/apps/alsijil/models.py b/aleksis/apps/alsijil/models.py index 774c1be3e6d390cfe83c494a866ec27d82b357e1..57e485d03a1edf989d313157ba9ca2360d123cf5 100644 --- a/aleksis/apps/alsijil/models.py +++ b/aleksis/apps/alsijil/models.py @@ -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