Skip to content

transformation_service

django_spire.metric.visual.signage.services.transformation_service

SignageTransformationService

Bases: BaseDjangoModelService['Signage']

Source code in django_spire/contrib/constructor/constructor.py
def __init__(self, obj: Any = None):
    self._obj_type_name: str = str(next(iter(self.__class__.__annotations__.values()))).split(
        '.'
    )[-1]

    if obj is None:
        return

    self._obj_mro_type_names = [cls.__name__ for cls in obj.__class__.__mro__]

    if self._obj_type_name not in self._obj_mro_type_names:
        message = f'{self.__class__.__name__} was instantiated with obj type "{obj.__class__.__name__}" and failed as it was expecting "{self._obj_type_name}".'
        raise ConstructorError(message)

    self._obj_type: type[TypeAny] = obj.__class__

    if self._obj_type is None or self._obj_type is ...:
        message = f'{self.__class__.__name__} top class attribute must have an annotated type.'
        raise ConstructorError(message)

    self.obj: TypeAny = obj

    if ABC not in self.__class__.__bases__:
        if not self._obj_is_valid:
            message = f'{self._obj_type_name} failed to validate on {self.__class__.__name__}'
            raise ConstructorError(message)

    self.__post_init__()

obj instance-attribute

Source code in django_spire/metric/visual/signage/services/transformation_service.py
def presentation_links(self) -> QuerySet[SignagePresentation]:
    return (
        self.obj.signage_presentations.select_related('presentation')
        .filter(is_deleted=False, presentation__is_deleted=False)
        .order_by('order')
    )

presentations

Source code in django_spire/metric/visual/signage/services/transformation_service.py
def presentations(self) -> QuerySet[Presentation]:
    return (
        Presentation.objects.filter(
            presentation_link__signage=self.obj,
            presentation_link__is_deleted=False,
            presentation_link__presentation__is_deleted=False,
        )
        .order_by('presentation_link__order')
        .with_slides()
    )

display_slides

Source code in django_spire/metric/visual/signage/services/transformation_service.py
def display_slides(self) -> list[dict]:
    slides = []

    for link in self.presentation_links():
        presentation = link.presentation

        for slide in presentation.slides.filter(is_deleted=False).order_by('order'):
            sections = [
                {'section': section, **section.services.transformation.render_context()}
                for section in slide.sections.select_related('visual')
                .filter(is_deleted=False)
                .order_by('row', 'col')
            ]
            slides.append({'presentation': presentation, 'slide': slide, 'sections': sections})

    return slides

SignagePresentationTransformationService

Bases: BaseDjangoModelService['SignagePresentation']

Source code in django_spire/contrib/constructor/constructor.py
def __init__(self, obj: Any = None):
    self._obj_type_name: str = str(next(iter(self.__class__.__annotations__.values()))).split(
        '.'
    )[-1]

    if obj is None:
        return

    self._obj_mro_type_names = [cls.__name__ for cls in obj.__class__.__mro__]

    if self._obj_type_name not in self._obj_mro_type_names:
        message = f'{self.__class__.__name__} was instantiated with obj type "{obj.__class__.__name__}" and failed as it was expecting "{self._obj_type_name}".'
        raise ConstructorError(message)

    self._obj_type: type[TypeAny] = obj.__class__

    if self._obj_type is None or self._obj_type is ...:
        message = f'{self.__class__.__name__} top class attribute must have an annotated type.'
        raise ConstructorError(message)

    self.obj: TypeAny = obj

    if ABC not in self.__class__.__bases__:
        if not self._obj_is_valid:
            message = f'{self._obj_type_name} failed to validate on {self.__class__.__name__}'
            raise ConstructorError(message)

    self.__post_init__()

obj instance-attribute