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

[AutomaticPlan] Use all versions between the relevant revisions

parent b2956a80
No related branches found
No related tags found
1 merge request!214Resolve "AutomaticPlan doesn't look at versions between the last revision and the current revision"
Pipeline #39194 passed
......@@ -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):
......
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