Example #1
0
 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, []))
Example #2
0
 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)))
Example #3
0
 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)))
Example #4
0
 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, []))
Example #5
0
 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()
Example #6
0
 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()
Example #7
0
 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()
Example #8
0
    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()