update stylr
[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     if request.method == 'POST':
13         req_items = request.POST
14     elif request.method == 'GET':
15         #return error('only post request is supported')
16         req_items = request.GET
17
18     for el in req_items.items():
19         if el[0].startswith('filters'):
20             o.filters[el[0][8:-1]] = el[1]
21         elif el[0].startswith('options'):
22             o.options = req_items.getlist('options[]')
23
24     try:
25         response = o.delete()
26
27         if response :
28             return success('record deleted')
29         else :
30             return error('an error has occurred')
31  
32     except Exception, e:
33         return error(str(e))
34