Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 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)]
Exemplo n.º 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)]
Exemplo n.º 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)
Exemplo n.º 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
Exemplo n.º 11
0
 def __set__(self, obj, value):
     obj_info = get_obj_info(obj)
     obj_info.variables[self] = self.from_python(value)
Exemplo n.º 12
0
 def __set__(self, obj, value):
     obj_info = get_obj_info(obj)
     obj_info.variables[self] = self.from_python(value)