Exemplo n.º 1
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()]))
Exemplo n.º 2
0
def from_json_data(base_url, json):
    """Convert a JSON representation of some data to the right types within
    the client.
    """
    if json['kind'] == 'object':
        if json['data'] is None:
            return None
        else:
            # It's a remote object
            from slumber.connector.instance import get_instance
            from slumber.connector.model import get_model
            model_url = urljoin(base_url, json['data']['type'])
            data_url = urljoin(base_url, json['data']['data'])
            display = json['data']['display']
            return get_instance(get_model(model_url), data_url, display)
    else:
        return json['data']