Verified Commit 99093fbf authored by Jakob Moser's avatar Jakob Moser
Browse files

Use medium-large hack to make loading templates work again

parent d0ef03e6
Loading
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
from dataclasses import dataclass

from babel import Locale
from pdf_generator.commitment_certification.Certification import Certification
from pdf_generator.jinja.templates import fill_template

from coliverter.resources.templates.get_template import get_template


@dataclass(frozen=True)
class ColiCertification(Certification):
    def html(self, locale: Locale) -> str:
        # This override here is a bit unlucky, technically, we only need to replace the get_template method.
        # This should be modeled in a smarter way, but it isn't.
        template_name = self.__class__.get_template_name(
            self.office_name, self.office_kind_name
        )
        assert template_name is not None, "The constructor should have caught this"

        return fill_template(
            get_template(template_name, locale), locale, certification=self
        )

    @classmethod
    def get_template_name(cls, office_name: str, office_kind_name: str) -> str | None:
        match office_kind_name: