def add_data(self, obj): """Takes an object that we've loaded and ships all its data up to the cache""" for propname, prop in self.metas[obj.type_].iteritems(): if isinstance(prop, PropertyStatement): #this represents a property if _has_and_not_none(obj, propname): self.parser.add_data(exists(obj.value_, obj.type_, propname, getattr(obj, propname))) else: self.parser.add_data(exists(obj.value_, obj.type_, propname, []))
def _remove_half(self, obj, value, type, property, target): if _has_and_not_none(obj, property) and target in getattr(obj, property): getattr(obj, property).remove(target) if getattr(obj, property) == []: delattr(obj, property) self.parser.add_data(exists(value, type, property, [])) else: self.parser.add_data(exists(value, type, property, getattr(obj, property)))
def _remove_half(self, obj, value, type, property, target): if _has_and_not_none(obj, property) and target in getattr( obj, property): getattr(obj, property).remove(target) if getattr(obj, property) == []: delattr(obj, property) self.parser.add_data(exists(value, type, property, [])) else: self.parser.add_data( exists(value, type, property, getattr(obj, property)))
def add_data(self, obj): """Takes an object that we've loaded and ships all its data up to the cache""" for propname, prop in self.metas[obj.type_].iteritems(): if isinstance(prop, PropertyStatement): #this represents a property if _has_and_not_none(obj, propname): self.parser.add_data( exists(obj.value_, obj.type_, propname, getattr(obj, propname))) else: self.parser.add_data( exists(obj.value_, obj.type_, propname, []))
def _add_half(self, value, type, property, target): obj = lookup_obj(type, value) if obj is None: obj = new_obj(type, value) if not _has_and_not_none(obj, property): setattr(obj, property, [target]) else: if target not in getattr(obj, property): getattr(obj, property).append(target) self.parser.add_data(exists(value, type, property, getattr(obj, property))) obj.put()
def _add_half(self, value, type, property, target): obj = lookup_obj(type, value) if obj is None: obj = new_obj(type, value) if not _has_and_not_none(obj, property): setattr(obj, property, [target]) else: if target not in getattr(obj, property): getattr(obj, property).append(target) self.parser.add_data( exists(value, type, property, getattr(obj, property))) obj.put()
def _replace(self, value, type, property, newvalues): #tricky thing here is I want to do a bulk replace, but then I need to add each other half individually #iteratively add this object to its components if appropriate prop = self.metas[type][property] if prop.b.kind in (KINDS.SINGLE, KINDS.PLURAL): for v in newvalues: self._add_half(v, prop.b.typename, prop.b.name, value) #then, do the bulk replace on the current object obj = lookup_obj(type, value) if obj is None: obj = new_obj(type, value) if newvalues == []: if hasattr(obj, property): delattr(obj, property) else: setattr(obj, property, newvalues) self.parser.add_data(exists(value, type, property, newvalues)) obj.put()
def _replace( self, value, type, property, newvalues ): #tricky thing here is I want to do a bulk replace, but then I need to add each other half individually #iteratively add this object to its components if appropriate prop = self.metas[type][property] if prop.b.kind in (KINDS.SINGLE, KINDS.PLURAL): for v in newvalues: self._add_half(v, prop.b.typename, prop.b.name, value) #then, do the bulk replace on the current object obj = lookup_obj(type, value) if obj is None: obj = new_obj(type, value) if newvalues == []: if hasattr(obj, property): delattr(obj, property) else: setattr(obj, property, newvalues) self.parser.add_data(exists(value, type, property, newvalues)) obj.put()