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

Merge branch 'implement-update' into 'master'

Port default LiveDocument.update() from Chronos

See merge request AlekSIS/official/AlekSIS-App-Resint!38
parents 54dfff3a 307dd1fb
No related branches found
No related tags found
1 merge request!38Port default LiveDocument.update() from Chronos
Pipeline #49615 passed
......@@ -13,6 +13,8 @@ Added
~~~~~
* Open poster group menu entries in new tab.
* [Dev] LiveDocument.update() now has a default implementaiton, rendering
``self.template`` using ``self.get_context_data()``
Fixed
~~~~~
......
from datetime import datetime
from typing import Optional
from typing import Any, Optional
from django.core.files import File
from django.core.validators import FileExtensionValidator, MaxValueValidator, MinValueValidator
......@@ -10,9 +10,12 @@ from django.utils.translation import gettext_lazy as _
import reversion
from calendarweek import CalendarWeek
from calendarweek.django import i18n_day_name_choices_lazy
from celery.result import allow_join_result
from celery.states import SUCCESS
from reversion.models import Revision, Version
from aleksis.core.mixins import ExtensibleModel, ExtensiblePolymorphicModel
from aleksis.core.util.pdf import generate_pdf_from_template
class PosterGroup(ExtensibleModel):
......@@ -151,6 +154,8 @@ class LiveDocument(ExtensiblePolymorphicModel):
SCOPE_PREFIX = "live_document_pdf"
template = None
slug = models.SlugField(
verbose_name=_("Slug"),
help_text=_("This will be used for the name of the current PDF file."),
......@@ -203,12 +208,26 @@ class LiveDocument(ExtensiblePolymorphicModel):
with reversion.create_revision():
super().save(*args, **kwargs)
def get_context_data(self) -> dict[str, Any]:
"""Get context to pass to the PDF template."""
return {}
def update(self, triggered_manually: bool = True):
"""Update the file with a new version.
Has to be implemented by subclasses.
"""
raise NotImplementedError("Subclasses of LiveDocument must implement update()")
if not self.template:
raise NotImplementedError("Subclasses of LiveDocument must implement update()")
file_object, result = generate_pdf_from_template(self.template, self.get_context_data())
with allow_join_result():
result.wait()
file_object.refresh_from_db()
if result.status == SUCCESS and file_object.file:
self.last_update_triggered_manually = triggered_manually
self.current_file.save(self.filename, file_object.file.file)
self.save()
def __str__(self) -> str:
return self.name
......
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