Skip to content
Snippets Groups Projects
Commit 869f74cf authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Merge branch...

Merge branch '155-automaticplan-doesn-t-look-at-versions-between-the-last-revision-and-the-current-revision' into 'master'

Resolve "AutomaticPlan doesn't look at versions between the last revision and the current revision"

Closes #155

See merge request AlekSIS/official/AlekSIS-App-Chronos!214
parents c8ea5898 02c3f72d
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 #41309 failed
......@@ -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)
......@@ -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