示例#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
示例#2
0
文件: store.py 项目: jdahlin/thunder
    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
示例#3
0
文件: store.py 项目: jdahlin/thunder
    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
示例#4
0
文件: fields.py 项目: jdahlin/thunder
 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)
示例#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)
示例#6
0
文件: store.py 项目: jdahlin/thunder
    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)
示例#7
0
文件: store.py 项目: jdahlin/thunder
    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)]
示例#8
0
文件: store.py 项目: jdahlin/thunder
    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)]
示例#9
0
文件: store.py 项目: jdahlin/thunder
    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)
示例#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
示例#11
0
文件: fields.py 项目: jdahlin/thunder
 def __set__(self, obj, value):
     obj_info = get_obj_info(obj)
     obj_info.variables[self] = self.from_python(value)
示例#12
0
 def __set__(self, obj, value):
     obj_info = get_obj_info(obj)
     obj_info.variables[self] = self.from_python(value)