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

Move last_update_triggered_manually to LiveDocument and rename last_revision to clarify the name

parent 504e4e74
No related branches found
No related tags found
1 merge request!191Resolve "Automatically create a PDF file of the substitution plan"
......@@ -20,8 +20,7 @@ class Migration(migrations.Migration):
('livedocument_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='resint.livedocument')),
('number_of_days', models.PositiveIntegerField(default=1, validators=[django.core.validators.MinValueValidator(1)], verbose_name='Number of days shown in the plan')),
('show_header_box', models.BooleanField(default=True, help_text='The header box shows affected teachers/groups.', verbose_name='Show header box')),
('last_update_triggered_manually', models.BooleanField(default=False, verbose_name='Was the last update triggered manually?', editable=False)),
('last_revision', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='reversion.revision', verbose_name='Revision which triggered the last update', editable=False)),
('last_substitutions_revision', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='reversion.revision', verbose_name='Revision which triggered the last update', editable=False)),
],
options={
'verbose_name': 'Automatic plan',
......
......@@ -1136,7 +1136,7 @@ class AutomaticPlan(LiveDocument):
verbose_name=_("Show header box"),
help_text=_("The header box shows affected teachers/groups."),
)
last_revision = models.ForeignKey(
last_substitutions_revision = models.ForeignKey(
to=Revision,
on_delete=models.SET_NULL,
blank=True,
......@@ -1145,10 +1145,6 @@ class AutomaticPlan(LiveDocument):
editable=False,
)
last_update_triggered_manually = models.BooleanField(
default=False, verbose_name=_("Was the last update triggered manually?"), editable=False
)
@property
def current_start_day(self) -> date:
"""Get first day which should be shown in the PDF."""
......@@ -1174,9 +1170,9 @@ class AutomaticPlan(LiveDocument):
def check_update(self, revision: Revision, versions: Iterable[Version]):
"""Check if the PDF file has to be updated and do the update then."""
if not self.last_revision or (
self.last_revision != revision
and revision.date_created > self.last_revision.date_created
if not self.last_substitutions_revision or (
self.last_substitutions_revision != revision
and revision.date_created > self.last_substitutions_revision.date_created
):
update = False
for version in versions:
......@@ -1192,7 +1188,7 @@ class AutomaticPlan(LiveDocument):
if update:
self.update(triggered_manually=False)
self.last_revision = revision
self.last_substitutions_revision = revision
self.save()
def update(self, triggered_manually: bool = True):
......
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