diff --git a/aleksis/apps/chronos/apps.py b/aleksis/apps/chronos/apps.py index 116dc0e8346f1b4535200b64def23957283953ea..01ad4f24878b9dffe4942b95fdefacf36561d134 100644 --- a/aleksis/apps/chronos/apps.py +++ b/aleksis/apps/chronos/apps.py @@ -32,4 +32,4 @@ class ChronosConfig(AppConfig): """Handle a new post revision commit signal in background.""" transaction.on_commit(lambda: handle_new_revision.delay(revision.pk)) - post_revision_commit.connect(_handle_post_revision_commit) + post_revision_commit.connect(_handle_post_revision_commit, weak=False) diff --git a/aleksis/apps/chronos/models.py b/aleksis/apps/chronos/models.py index bafc1af866282368416671b842b5eaa568f70e91..eeabc470e58e7c42bf31755991826d41ae0c0515 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):