コード例 #1
0
    def tree(self) -> CategoryTree:
        # Currently only a work around until the other managers were converted to the new format - MH
        types = CmdbObjectManager(
            database_manager=self._database_manager).get_all_types()
        categories = [
            CategoryModel.from_data(category)
            for category in super(CategoryManager, self).get_many({})
        ]

        return CategoryTree(categories=categories, types=types)
コード例 #2
0
    def get(self, public_id: Union[PublicID, int]) -> CategoryModel:
        """
        Get a single type by its id.

        Args:
            public_id (int): ID of the type.

        Returns:
            CategoryModel: Instance of CategoryModel with data.
        """
        cursor_result = self._get(self.collection, filter={'public_id': public_id}, limit=1)
        for resource_result in cursor_result.limit(-1):
            return CategoryModel.from_data(resource_result)
        raise ManagerGetError(f'Category with ID: {public_id} not found!')
コード例 #3
0
    def __convert_category_to_new_structure(self, old_raw_category: dict,
                                            index: int) -> CategoryModel:
        """Converts a category from old < 20200512 structure to new format """
        old_raw_category['meta'] = {
            'icon': old_raw_category.get('icon', None),
            'order': index
        }
        parent = old_raw_category.get('parent_id', None)
        if parent == 0:
            parent = None

        old_raw_category['parent'] = parent
        category = CategoryModel.from_data(old_raw_category)
        category.types = self.__get_types_in_category(
            old_raw_category.get('public_id'))
        return category
コード例 #4
0
 def get(self, public_id: Union[PublicID, int]) -> CategoryModel:
     result = super(CategoryManager, self).get(public_id=public_id)
     return CategoryModel.from_data(result)