slicetabinfo: delete slice clears creds
[unfold.git] / rest / create.py
1 from django.views.generic.base      import TemplateView
2 from django.shortcuts               import render_to_response
3
4 from unfold.loginrequired           import LoginRequiredView
5 from django.http                    import HttpResponse
6
7 from manifold.core.query            import Query, AnalyzedQuery
8 from manifoldapi.manifoldapi        import execute_query
9
10 from rest import ObjectRequest, error, success
11
12 from string import join
13
14 import json
15
16
17 def dispatch(request, object_type, object_name):
18     
19     o = ObjectRequest(request, object_type, object_name)    
20     
21     if request.method == 'POST':
22         req_items = request.POST
23     elif request.method == 'GET':
24         #return error('only post request is supported')
25         req_items = request.GET
26     for el in list(req_items.items()):
27         # Filters not used for create
28         if el[0].startswith('filters'):
29             o.filters[el[0][8:-1]] = el[1]
30         elif el[0].startswith('params'):
31             #o.params[el[0][7:-1]] = el[1]
32             o.params.append({el[0][7:-1]:el[1]})
33         elif el[0].startswith('fields'):
34             o.fields=req_items.getlist('fields[]')
35         elif el[0].startswith('options'):
36             o.options = req_items.getlist('options[]')
37
38     try:
39         response = o.create()
40
41         if response :
42             return success('record created')
43         else :
44             return error('an error has occurred')
45  
46     except Exception as e:
47         return error(str(e))
48