Example #1
0
 def load_obj(self, ref, asdict=False, modelattrs={}):
     """loads an object from the server.
     if asdict:
         only the json is returned.
     else:
         update the existing copy in _models if it is present
         instantiate a new one if it is not
         and make sure to convert all references into models
     in the conversion from json to objects, sometimes references
     to models need to be resolved.  If there are any json attributes
     being processed, you can pass them in as modelattrs
     """
     typename = ref["type"]
     ref_id = ref["id"]
     url = utils.urljoin(self.base_url, self.docid + "/" + ref["type"] +\
                         "/" + ref["id"] + "/")
     attr = protocol.deserialize_json(self.http_session.get(url).content)
     if not asdict:
         m = PlotObject.get_obj(typename, attr)
         self.add(m)
         m.finalize(self._models)
         m.dirty = False
         return m
     else:
         return attr
Example #2
0
 def load_attrs(self, typename, attrs):
     models = []
     for attr in attrs:
         # logger.debug('type: %s', typename)
         # logger.debug('attrs: %s', attr)
         _id = attr['id']
         if _id in self._models:
             m = self._models[_id]
             m.load_json(attr, instance=m)
         else:
             m = PlotObject.get_obj(typename, attr)
             self.add(m)
         models.append(m)
     for m in models:
         m.finalize(self._models)
     return models