Beispiel #1
0
 def rest_create_object(self, obj_type, obj_data):
     if not self.controller:
         print "No controller specified. Set using 'controller <server:port>'."
         return
     url_cache.clear_cached_urls()
     url = self.entry_post_url % (self.controller, obj_type)
     data = self.rest_post_request(url, obj_data)
     # LOOK! successful stuff should be returned in json too.
     if data != "saved":
         result = json.loads(data)
         return result
     url_cache.clear_cached_urls()
 def rest_update_object(self, obj_type, obj_key_name, obj_key_val, obj_data):
     if not self.controller:
         print "No controller specified. Set using 'controller <server:port>'."
         return
     url = self.entry_post_url % (self.controller, obj_type)
     url += "?%s=%s" % (obj_key_name, urllib.quote_plus(obj_key_val)) # add a query string
     data = self.rest_post_request(url, obj_data)
     # LOOK! successful stuff should be returned in json too.
     result = json.loads(data)
     if result.get('description', '') != "saved":
         return result
     url_cache.clear_cached_urls()
 def rest_create_object(self, obj_type, obj_data):
     if not self.controller:
         print "No controller specified. Set using 'controller <server:port>'."
         return
     url_cache.clear_cached_urls()
     url = self.entry_post_url % (self.controller, obj_type)
     data = self.rest_post_request(url, obj_data)
     # LOOK! successful stuff should be returned in json too.
     if data != "saved":
         result = json.loads(data)
         return result
     url_cache.clear_cached_urls()
Beispiel #4
0
 def rest_update_object(self, obj_type, obj_key_name, obj_key_val,
                        obj_data):
     if not self.controller:
         print "No controller specified. Set using 'controller <server:port>'."
         return
     url = self.entry_post_url % (self.controller, obj_type)
     url += "?%s=%s" % (obj_key_name, urllib.quote_plus(obj_key_val)
                        )  # add a query string
     data = self.rest_post_request(url, obj_data)
     # LOOK! successful stuff should be returned in json too.
     result = json.loads(data)
     if result.get('description', '') != "saved":
         return result
     url_cache.clear_cached_urls()
    def rest_delete_objects(self, obj_type, query_params):
        url = self.entry_post_url % (self.controller, obj_type)
        if query_params:
            url += '?'
            # Convert any data:None fields to <id>__isnull=True
            non_null_query_params = dict([[n,v] if v != None else [n + '__isnull', True]
                                          for (n,v) in query_params.items()])
            url += urllib.urlencode(non_null_query_params)

        data = self.rest_post_request(url, {}, 'DELETE')
        # LOOK! successful stuff should be returned in json too.
        if data != "deleted":
            result = json.loads(data)
            return result
        url_cache.clear_cached_urls()
Beispiel #6
0
    def rest_delete_objects(self, obj_type, query_params):
        url = self.entry_post_url % (self.controller, obj_type)
        if query_params:
            url += '?'
            # Convert any data:None fields to <id>__isnull=True
            non_null_query_params = dict(
                [[n, v] if v != None else [n + '__isnull', True]
                 for (n, v) in query_params.items()])
            url += urllib.urlencode(non_null_query_params)

        data = self.rest_post_request(url, {}, 'DELETE')
        # LOOK! successful stuff should be returned in json too.
        if data != "deleted":
            result = json.loads(data)
            return result
        url_cache.clear_cached_urls()
Beispiel #7
0
    def rest_delete_object(self, obj_type, key, val=None):
        dict_ = {}
        url = self.entry_post_url % (self.controller, obj_type)
        if val == None:
            if not type(key) == type(dict_):
                return None
            dict_ = key
        else:
            url += "?%s__exact=%s" % (key, urllib.quote_plus(val))

        # LOOK! I'm not sure this works the way it seems to me it's
        # designed to work. I think the intent is that you can specify
        # query parameters in the key argument which controls which
        # instance(s) should be deleted. But when I try it it seems to
        # always delete all instances, so it seems like the parameters
        # don't filter properly when passed via the POST data as opposed
        # to being specified as query parameters in the URL. The latter
        # way does work -- see rest_delete_objects that follows this.
        data = self.rest_post_request(url, dict_, 'DELETE')
        # LOOK! successful stuff should be returned in json too.
        if data != "deleted":
            dict_ = json.loads(data)
            return dict_
        url_cache.clear_cached_urls()
    def rest_delete_object(self, obj_type, key, val = None):
        dict_ = {}
        url = self.entry_post_url % (self.controller, obj_type)
        if val == None:
            if not type(key) == type(dict_):
                return None
            dict_ = key
        else:
            url += "?%s__exact=%s" % (key, urllib.quote_plus(val))

        # LOOK! I'm not sure this works the way it seems to me it's
        # designed to work. I think the intent is that you can specify
        # query parameters in the key argument which controls which
        # instance(s) should be deleted. But when I try it it seems to
        # always delete all instances, so it seems like the parameters
        # don't filter properly when passed via the POST data as opposed
        # to being specified as query parameters in the URL. The latter
        # way does work -- see rest_delete_objects that follows this.
        data = self.rest_post_request(url, dict_, 'DELETE')
        # LOOK! successful stuff should be returned in json too.
        if data != "deleted":
            dict_ = json.loads(data)
            return dict_
        url_cache.clear_cached_urls()