コード例 #1
0
ファイル: instance.py プロジェクト: sunbit/guillotina
    def __init__(self, context):
        self.__dict__["schema"] = [x for x in self.__implemented__][0]
        self.__dict__["prefix"] = self.__dict__["schema"].__identifier__ + "."
        self.__dict__["data"] = {}
        self.__dict__["context"] = context

        # see if annotations are preloaded...
        annotations_container = IAnnotations(self.__dict__["context"])
        data = annotations_container.get(self.__annotations_data_key__, _default)
        if data is not _default:
            self.__dict__["data"] = data
コード例 #2
0
ファイル: annotation.py プロジェクト: sunfirescm/guillotina
 async def iter_buckets(self, context):
     for index in sorted(self.annotations_metadata.keys()):
         annotation_name = self.get_annotation_name(index)
         annotations_container = IAnnotations(context)
         annotation = annotations_container.get(annotation_name, _default)
         if annotation is _default:
             annotation = await annotations_container.async_get(
                 annotation_name, _default)
             if annotation is _default:
                 continue
         yield annotation
コード例 #3
0
ファイル: instance.py プロジェクト: worasit/guillotina
    def __init__(self, context):
        self.__dict__['schema'] = [x for x in self.__implemented__][0]
        self.__dict__['prefix'] = self.__dict__['schema'].__identifier__ + '.'
        self.__dict__['data'] = {}
        self.__dict__['context'] = context

        # see if annotations are preloaded...
        annotations_container = IAnnotations(self.__dict__['context'])
        data = annotations_container.get(self.__annotations_data_key__, _default)
        if data is not _default:
            self.__dict__['data'] = data
コード例 #4
0
 async def iter_buckets(self, context) -> AsyncIterator[AnnotationData]:
     annotations_container = IAnnotations(context)
     for index in sorted(self.annotations_metadata.keys()):
         annotation_name = self.get_annotation_name(index)
         annotation = annotations_container.get(annotation_name, _default)
         if annotation is _default:  # pragma: no cover
             annotation = await annotations_container.async_get(
                 annotation_name, _default)
             if annotation is _default:
                 continue
         yield annotation
コード例 #5
0
ファイル: annotation.py プロジェクト: nazrulworld/guillotina
 async def iter_buckets(self, context):
     for index in sorted(self.annotations_metadata.keys()):
         annotation_name = self.get_annotation_name(index)
         annotations_container = IAnnotations(context)
         annotation = annotations_container.get(annotation_name, _default)
         if annotation is _default:
             annotation = await annotations_container.async_get(
                 annotation_name, _default)
             if annotation is _default:
                 continue
         yield annotation
コード例 #6
0
 async def get(self, context, create=True):
     annotations_container = IAnnotations(context)
     numpy_object = annotations_container.get(self.prefix, _default)
     if numpy_object is _default:
         # needs to be loaded
         numpy_object = await annotations_container.async_get(self.prefix,
                                                              _default,
                                                              reader=reader)
     if numpy_object is _default:
         return None
     return numpy_object
コード例 #7
0
 async def iter_buckets(self, context) -> AsyncIterator[AnnotationData]:
     try:
         annotations_container = IAnnotations(context)
     except TypeError:
         return
     for bucket in self.buckets:
         annotation_name: str = self.get_annotation_name(bucket["id"])
         annotation: AnnotationData = annotations_container.get(
             annotation_name, _default)
         if annotation is _default:
             annotation = await annotations_container.async_get(
                 annotation_name, _default)
             if annotation is _default:
                 continue
         yield annotation
コード例 #8
0
ファイル: instance.py プロジェクト: sunbit/guillotina
    async def load(self, create=False):
        annotations_container = IAnnotations(self.__dict__["context"])
        data = annotations_container.get(self.__annotations_data_key__, _default)
        if data is not _default:
            # data is already preloaded, we do not need to get from db again...
            self.__dict__["data"] = data
            return

        annotations = await annotations_container.async_get(self.__annotations_data_key__)
        if annotations is None:
            if create:
                annotations = AnnotationData()
                await annotations_container.async_set(self.__annotations_data_key__, annotations)
            else:
                annotations = {}  # fallback, assumed only for reading here...
        self.__dict__["data"] = annotations
コード例 #9
0
ファイル: instance.py プロジェクト: nazrulworld/guillotina
    async def load(self, create=False):
        annotations_container = IAnnotations(self.__dict__['context'])
        data = annotations_container.get(self.__annotations_data_key__, _default)
        if data is not _default:
            # data is already preloaded, we do not need to get from db again...
            self.__dict__['data'] = data
            return

        annotations = await annotations_container.async_get(self.__annotations_data_key__)
        if annotations is None:
            if create:
                annotations = AnnotationData()
                await annotations_container.async_set(self.__annotations_data_key__, annotations)
            else:
                annotations = {}  # fallback, assumed only for reading here...
        self.__dict__['data'] = annotations
コード例 #10
0
ファイル: annotation.py プロジェクト: sunfirescm/guillotina
 async def get_annotation(self, context, annotation_index, create=True):
     annotation_name = self.get_annotation_name(annotation_index)
     annotations_container = IAnnotations(context)
     annotation = annotations_container.get(annotation_name, _default)
     if annotation is _default:
         annotation = await annotations_container.async_get(
             annotation_name, _default)
     if annotation is _default:
         if not create:
             return
         # create
         annotation = AnnotationData()
         annotation.update({'items': []})
         await annotations_container.async_set(annotation_name, annotation)
     if annotation_index not in self.annotations_metadata:
         self.annotations_metadata[annotation_index] = {}
     return annotation
コード例 #11
0
ファイル: annotation.py プロジェクト: nazrulworld/guillotina
 async def get_annotation(self, context, annotation_index, create=True):
     annotation_name = self.get_annotation_name(annotation_index)
     annotations_container = IAnnotations(context)
     annotation = annotations_container.get(annotation_name, _default)
     if annotation is _default:
         annotation = await annotations_container.async_get(
             annotation_name, _default)
     if annotation is _default:
         if not create:
             return
         # create
         annotation = AnnotationData()
         annotation.update({
             'items': []
         })
         await annotations_container.async_set(annotation_name, annotation)
     if annotation_index not in self.annotations_metadata:
         self.annotations_metadata[annotation_index] = {}
     return annotation
コード例 #12
0
ファイル: annotation.py プロジェクト: sunbit/guillotina
 async def get_annotation(self,
                          context: IBaseObject,
                          annotation_index: int,
                          create: bool = True) -> Optional[IAnnotationData]:
     annotation_name = self.get_annotation_name(annotation_index)
     annotations_container = IAnnotations(context)
     annotation = annotations_container.get(annotation_name, _default)
     if annotation is _default:
         annotation = await annotations_container.async_get(
             annotation_name, _default)
     if annotation is _default:
         if not create:
             return None
         # create
         annotation = AnnotationData()
         annotation.update({"items": []})
         await annotations_container.async_set(annotation_name, annotation)
     if annotation_index not in self.annotations_metadata:
         self.annotations_metadata[annotation_index] = {}
     return annotation
コード例 #13
0
    async def get_annotation(self,
                             context,
                             key=None,
                             anno_id=None,
                             create=True) -> typing.Optional[AnnotationData]:
        if anno_id is None:
            bidx, bucket = self._find_bucket(key)
            annotation_name = self.get_annotation_name(bucket["id"])
        else:
            annotation_name = self.get_annotation_name(anno_id)

        annotations_container = IAnnotations(context)
        annotation = annotations_container.get(annotation_name, _default)
        if annotation is _default:
            annotation = await annotations_container.async_get(
                annotation_name, _default)
        if annotation is _default:
            if not create:
                return None
            annotation = AnnotationData({"keys": [], "values": []})
            await annotations_container.async_set(annotation_name, annotation)
        return annotation