Skip to content

service

django_spire.knowledge.collection.services.service

CollectionService

Bases: BaseDjangoModelService['Collection']

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

    if obj is None:
        return

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

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

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

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

    self.obj: TypeAny = obj

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

    self.__post_init__()

obj instance-attribute

ordering = CollectionOrderingService() class-attribute instance-attribute

processor = CollectionProcessorService() class-attribute instance-attribute

transformation = CollectionTransformationService() class-attribute instance-attribute

save_model_obj

Source code in django_spire/knowledge/collection/services/service.py
def save_model_obj(self, **field_data) -> tuple[Collection, bool]:
    self.obj, created = super().save_model_obj(**field_data)

    if self.obj.parent_id is None:
        destination_objects = self.obj_class.objects.parentless().active()
    else:
        destination_objects = (
            self.obj_class.objects
            .by_parent_id(parent_id=self.obj.parent_id)
            .active()
        )

    self.obj.ordering_services.processor.move_to_position(
        destination_objects=destination_objects,
        position=0 if created else self.obj.order,
    )

    return self.obj, created

CollectionGroupService

Bases: BaseDjangoModelService['CollectionGroup']

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

    if obj is None:
        return

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

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

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

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

    self.obj: TypeAny = obj

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

    self.__post_init__()

obj instance-attribute

factory = CollectionGroupFactoryService() class-attribute instance-attribute