Exemple #1
0
    def __get__(self, obj, cls):
        if obj is None:
            return obj

        obj_info = get_obj_info(obj)
        if self in obj_info.variables:
            remote_value, remote_id = obj_info.variables[self]
            store = get_obj_info(remote_value).get('store')
            remote = store.get(self.remote_cls, remote_id)
        else:
            remote_id = obj_info.variables[self.local_field]
            store = obj_info.get('store')
            remote = store.get(self.remote_cls, remote_id)
        return remote
Exemple #2
0
    def _build_doc(self, cls_info, doc):
        obj_id = doc["_id"]

        obj = self._cache.get((cls_info, obj_id))
        if obj is not None:
            return obj
        cls = cls_info.cls
        obj = cls.__new__(cls)

        obj_info = get_obj_info(obj)
        obj_info.set("store", self)

        for attr, value in doc.items():
            if attr == '_id':
                continue
            else:
                field = cls_info.attributes[attr]
            obj_info.variables[field] = value

        obj._id = obj_id
        self._cache[(cls_info, obj_id)] = obj
        func = getattr(obj, '__thunder_loaded__', None)
        if func:
            func()
        return obj
Exemple #3
0
    def _build_doc(self, cls_info, doc):
        obj_id = doc["_id"]

        obj = self._cache.get((cls_info, obj_id))
        if obj is not None:
            return obj
        cls = cls_info.cls
        obj = cls.__new__(cls)

        obj_info = get_obj_info(obj)
        obj_info.set("store", self)

        for attr, value in doc.items():
            if attr == '_id':
                continue
            else:
                field = cls_info.attributes[attr]
            obj_info.variables[field] = value

        obj._id = obj_id
        self._cache[(cls_info, obj_id)] = obj
        func = getattr(obj, '__thunder_loaded__', None)
        if func:
            func()
        return obj
Exemple #4
0
 def __get__(self, obj, cls=None):
     if obj is None:
         return self
     obj_info = get_obj_info(obj)
     value = obj_info.variables.get(self, Undef)
     if value is Undef:
         return None
     return self.to_python(value)
Exemple #5
0
 def __get__(self, obj, cls=None):
     if obj is None:
         return self
     obj_info = get_obj_info(obj)
     value = obj_info.variables.get(self, Undef)
     if value is Undef:
         return None
     return self.to_python(value)
Exemple #6
0
    def add(self, obj):
        obj_info = get_obj_info(obj)

        if obj_info.get('store') is not None:  # pragma: nocoverage
            raise TypeError("Document %s is already in a store" % (obj, ))

        obj_info.set('store', self)
        obj_info.flush_pending = True
        self.obj_infos.add(obj_info)
Exemple #7
0
    def remove(self, obj):
        obj_info = get_obj_info(obj)
        store = obj_info.get('store')
        if store != self:
            raise Exception("This object does not belong to this store")

        obj_info.set('action', 'remove')
        obj_info.flush_pending = True
        self.obj_infos.add(obj_info)
        del self._cache[(obj_info.cls_info, obj._id)]
Exemple #8
0
    def remove(self, obj):
        obj_info = get_obj_info(obj)
        store = obj_info.get('store')
        if store != self:
            raise Exception("This object does not belong to this store")

        obj_info.set('action', 'remove')
        obj_info.flush_pending = True
        self.obj_infos.add(obj_info)
        del self._cache[(obj_info.cls_info, obj._id)]
Exemple #9
0
    def add(self, obj):
        obj_info = get_obj_info(obj)

        if obj_info.get('store') is not None:  # pragma: nocoverage
            raise TypeError(
                "Document %s is already in a store" % (obj, ))

        obj_info.set('store', self)
        obj_info.flush_pending = True
        self.obj_infos.add(obj_info)
Exemple #10
0
    def __set__(self, obj, value):
        if (value is not None and
            not isinstance(value, self.remote_cls)):
            raise TypeError("Must be a %s, not a %r" % (
                self.remote_cls.__name__,
                value.__class__.__name__))
        if value is None:
            remote_value = None
        else:
            remote_value = getattr(value, self.remote_attr)

        obj_info = get_obj_info(obj)
        obj_info.variables[self] = value, remote_value
        obj_info.variables[self.local_field] = remote_value
Exemple #11
0
 def __set__(self, obj, value):
     obj_info = get_obj_info(obj)
     obj_info.variables[self] = self.from_python(value)
Exemple #12
0
 def __set__(self, obj, value):
     obj_info = get_obj_info(obj)
     obj_info.variables[self] = self.from_python(value)