Skip to content

service

django_spire.metric.visual.signage.services.service

SignageService

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

intelligence = SignageIntelligenceService() class-attribute instance-attribute

processor = SignageProcessorService() class-attribute instance-attribute

factory = SignageFactoryService() class-attribute instance-attribute

transformation = SignageTransformationService() class-attribute instance-attribute

SignagePresentationService

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

intelligence = SignagePresentationIntelligenceService() class-attribute instance-attribute

processor = SignagePresentationProcessorService() class-attribute instance-attribute

factory = SignagePresentationFactoryService() class-attribute instance-attribute

transformation = SignagePresentationTransformationService() class-attribute instance-attribute

save_model_obj

Source code in django_spire/metric/visual/signage/services/service.py
def save_model_obj(self, **field_data: dict | None) -> tuple[SignagePresentation, bool]:
    if self.obj.pk is None and self.obj.signage_id:
        with transaction.atomic():
            locked_signage = self._locked_signage()
            field_data = self._next_available_order(
                locked_signage.signage_presentations, field_data
            )

            return super().save_model_obj(**field_data)

    return super().save_model_obj(**field_data)