Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
[unfold.git] / rest / delete.py
1 from unfold.loginrequired           import LoginRequiredView
2
3 from string import join
4
5 from rest import ObjectRequest, error, success
6
7
8 def dispatch(request, object_type, object_name):
9     
10     o = objectRequest(request, object_type, object_name)    
11     
12     object_filters = {}
13     object_params = {}
14     result = {}
15     
16     if request.method == 'POST':
17         req_items = request.POST
18     elif request.method == 'GET':
19         #return error('only post request is supported')
20         req_items = request.GET
21
22     for el in req_items.items():
23         if el[0].startswith('filters'):
24             o.filters[el[0][8:-1]] = el[1]
25         elif el[0].startswith('options'):
26             o.options = req_items.getlist('options[]')
27
28     try:
29         response = o.execute()
30
31         if response :
32             return success('record deleted')
33         else :
34             return error('an error has occurred')
35  
36     except Exception, e:
37         return error(str(e))
38