From 02c3f72de78fcb01acdfda057cae0dde82cd81d0 Mon Sep 17 00:00:00 2001 From: Jonathan Weth <git@jonathanweth.de> Date: Fri, 5 Nov 2021 21:23:04 +0100 Subject: [PATCH] [AutomaticPlan] Use all versions between the relevant revisions --- aleksis/apps/chronos/models.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/aleksis/apps/chronos/models.py b/aleksis/apps/chronos/models.py index bafc1af8..eeabc470 100644 --- a/aleksis/apps/chronos/models.py +++ b/aleksis/apps/chronos/models.py @@ -7,6 +7,7 @@ from datetime import date, datetime, time, timedelta from itertools import chain from typing import Any, Dict, Iterable, Iterator, List, Optional, Tuple, Union +from django.contrib.contenttypes.models import ContentType from django.core.exceptions import ValidationError from django.core.files.base import ContentFile, File from django.core.files.storage import default_storage @@ -55,7 +56,7 @@ from aleksis.apps.chronos.mixins import ( WeekAnnotationMixin, WeekRelatedMixin, ) -from aleksis.apps.chronos.util.change_tracker import substitutions_changed +from aleksis.apps.chronos.util.change_tracker import _get_substitution_models, substitutions_changed from aleksis.apps.chronos.util.date import get_current_year from aleksis.apps.chronos.util.format import format_m2m from aleksis.apps.resint.models import LiveDocument @@ -1206,12 +1207,18 @@ class AutomaticPlan(LiveDocument): return context - def check_update(self, revision: Revision, versions: Iterable[Version]): + def check_update(self, revision: Revision): """Check if the PDF file has to be updated and do the update then.""" if not self.last_substitutions_revision or ( self.last_substitutions_revision != revision and revision.date_created > self.last_substitutions_revision.date_created ): + content_types = ContentType.objects.get_for_models(*_get_substitution_models()).values() + versions = Version.objects.filter(content_type__in=content_types) + if self.last_substitutions_revision: + versions = versions.filter( + revision__date_created__gt=self.last_substitutions_revision.date_created + ) update = False for version in versions: # Check if the changed object is relevant for the time period of the PDF file @@ -1251,7 +1258,7 @@ class AutomaticPlan(LiveDocument): def automatic_plan_signal_receiver(sender: Revision, versions: Iterable[Version], **kwargs): """Check all automatic plans for updates after substitutions changed.""" for automatic_plan in AutomaticPlan.objects.all(): - automatic_plan.check_update(sender, versions) + automatic_plan.check_update(sender) class ChronosGlobalPermissions(GlobalPermissionModel): -- GitLab