From: Loic Baron Date: Mon, 3 Mar 2014 22:42:52 +0000 (+0100) Subject: Rest: fixed update with ObjectRequest X-Git-Tag: myslice-1.1~245^2^2~2 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=67bce829e2bac18b5b8703c54cbc61f1e4644772;p=myslice.git Rest: fixed update with ObjectRequest --- diff --git a/rest/__init__.py b/rest/__init__.py index 80438a22..7276d786 100644 --- a/rest/__init__.py +++ b/rest/__init__.py @@ -27,6 +27,7 @@ class ObjectRequest(object): self.type = object_type self.name = object_name self.fields = [] + self.params = {} self.filters = {} self.options = None @@ -113,8 +114,8 @@ class ObjectRequest(object): def delete(self): query = Query.delete(self.type) query = self.applyFilters(query, True) - if self.params : - query.set(self.params) + if self.filters : + query.set(self.filters) else: raise Exception, "Params are required for update" return execute_query(self.request, query) diff --git a/rest/update.py b/rest/update.py index 7b277593..e7b671a0 100644 --- a/rest/update.py +++ b/rest/update.py @@ -16,7 +16,7 @@ import json def dispatch(request, object_type, object_name): - o = objectRequest(request, object_type, object_name) + o = ObjectRequest(request, object_type, object_name) object_filters = {} object_params = {} @@ -27,19 +27,22 @@ def dispatch(request, object_type, object_name): elif request.method == 'GET': #return error('only post request is supported') req_items = request.GET - + print req_items for el in req_items.items(): if el[0].startswith('filters'): o.filters[el[0][8:-1]] = el[1] + print o.filters elif el[0].startswith('params'): - o.addParams(req_items.getlist('params[]')) - elif el[0].startswith('columns'): - o.addFilters(req_items.getlist('columns[]')) + o.params[el[0][7:-1]] = el[1] + print o.params + elif el[0].startswith('fields'): + o.fields=req_items.getlist('fields[]') elif el[0].startswith('options'): o.options = req_items.getlist('options[]') try: - response = o.execute() + print o.params + response = o.update() if response : return success('record updated')