def __getattr__(self, name):
     _, json = get(self._url)
     for k, v in json['fields'].items():
         setattr(self, k, from_json_data(self._url, v))
     if name in json['fields'].keys():
         return getattr(self, name)
     return _return_data_array(self._url, json['data_arrays'], self, name)
Exemple #2
0
def get_instance_from_data(base_url, json):
    """Return a local instance proxy for the object described by the provided
    JSON like Python datastructure.
    """
    model = get_model(urljoin(base_url, json['type']))
    instance_url = urljoin(base_url, json['operations']['data'])
    return get_instance(model, instance_url, json['display'],
        dict([(k, from_json_data(base_url, j))
            for k, j in json['fields'].items()]))
Exemple #3
0
def get_instance_from_data(base_url, json):
    """Return a local instance proxy for the object described by the provided
    JSON like Python datastructure.
    """
    model = get_model(urljoin(base_url, json['type']))
    instance_url = urljoin(base_url, json['operations']['data'])
    return get_instance(
        model, instance_url, json['display'],
        dict([(k, from_json_data(base_url, j))
              for k, j in json['fields'].items()]))
Exemple #4
0
 def get(self, **kwargs):
     """Implements the client side for the model 'get' operator.
     """
     assert len(kwargs), \
         "You must supply kwargs to filter on to fetch the instance"
     url = urljoin(self._url, 'get/')
     _, json = get(url + '?' + urlencode(kwargs))
     return get_instance(self,
         urljoin(self._url, json['identity']), json['display'],
         **dict([(k, from_json_data(self._url, j))
             for k, j in json['fields'].items()]))
Exemple #5
0
 def _fetch_data(self):
     """Force fetching the data for this instance.
     """
     _, json = get(self._url, self._CACHE_TTL)
     # We need to set this outside of __init__ for it to work correctly
     # pylint: disable = W0201
     self._operations = dict([(o, urljoin(self._url, u))
         for o, u in json['operations'].items()])
     for k, v in json['fields'].items():
         setattr(self, k, from_json_data(self._url, v))
     self._display = json['display']
     return json
Exemple #6
0
 def _fetch_data(self):
     """Force fetching the data for this instance.
     """
     _, json = get(self._url, self._CACHE_TTL)
     # We need to set this outside of __init__ for it to work correctly
     # pylint: disable = W0201
     self._operations = dict([(o, urljoin(self._url, u))
                              for o, u in json['operations'].items()])
     for k, v in json['fields'].items():
         setattr(self, k, from_json_data(self._url, v))
     self._display = json['display']
     return json