|
@@ -18,6 +18,7 @@ def admin_update(request):
|
18
|
18
|
error = None
|
19
|
19
|
datas = list()
|
20
|
20
|
classname = request.form['classname']
|
|
21
|
+ logger.warning('Composed uids broken here')
|
21
|
22
|
uid = request.form['uid']
|
22
|
23
|
try:
|
23
|
24
|
target_leo = dyncode.Object.name2class(classname)
|
|
@@ -26,48 +27,59 @@ def admin_update(request):
|
26
|
27
|
if classname is None or target_leo.is_abstract():
|
27
|
28
|
raise HttpException(400)
|
28
|
29
|
fieldnames = target_leo.fieldnames()
|
|
30
|
+
|
|
31
|
+ uid_field = target_leo.uid_fieldname()[0]
|
29
|
32
|
fields = dict()
|
30
|
33
|
|
31
|
34
|
for in_put, in_value in request.form.items():
|
32
|
35
|
if in_put != 'classname' and in_put != 'uid':
|
33
|
36
|
fields[in_put[12:]] = in_value
|
34
|
|
- elif in_put == 'classname':
|
35
|
|
- fields['classname'] = in_value
|
36
|
|
- obj = (target_leo.get(('lodel_id = %s' % (uid))))[0]
|
|
37
|
+ #elif in_put == 'classname':
|
|
38
|
+ # fields['classname'] = in_value
|
|
39
|
+
|
|
40
|
+ filter_q = '%s = %s' % (uid_field, uid)
|
|
41
|
+ obj = (target_leo.get((filter_q)))[0]
|
|
42
|
+
|
37
|
43
|
inserted = obj.update(fields)
|
38
|
44
|
|
39
|
45
|
if inserted==1:
|
40
|
46
|
msg = 'Successfully updated';
|
41
|
47
|
else:
|
42
|
48
|
msg = 'Oops something wrong happened...object not saved'
|
43
|
|
- return get_response('admin/admin_edit.html', target=target_leo, lodel_id = uid, msg = msg)
|
|
49
|
+ return get_response('admin/admin_edit.html', target=target_leo, uidfield = uid_field, lodel_id = uid, msg = msg)
|
|
50
|
+
|
|
51
|
+ if 'classname' in request.GET:
|
|
52
|
+ classname = request.GET['classname']
|
|
53
|
+ if len(classname) > 1:
|
|
54
|
+ raise HttpException(400)
|
|
55
|
+ classname = classname[0]
|
|
56
|
+ try:
|
|
57
|
+ target_leo = dyncode.Object.name2class(classname)
|
|
58
|
+ except LeApiError:
|
|
59
|
+ # classname = None
|
|
60
|
+ raise HttpException(400)
|
|
61
|
+ logger.warning('Composed uids broken here')
|
|
62
|
+ uid_field = target_leo.uid_fieldname()[0]
|
44
|
63
|
|
45
|
|
- test_valid = 'lodel_id' in request.GET \
|
46
|
|
- and len(request.GET['lodel_id']) == 1
|
|
64
|
+ test_valid = uid_field in request.GET \
|
|
65
|
+ and len(request.GET[uid_field]) == 1
|
47
|
66
|
|
48
|
67
|
if test_valid:
|
49
|
68
|
try:
|
50
|
|
- lodel_id = int(request.GET['lodel_id'][0])
|
|
69
|
+ lodel_id = request.GET[uid_field][0]
|
51
|
70
|
except (ValueError, TypeError):
|
52
|
71
|
test_valid = False
|
53
|
72
|
|
54
|
73
|
if not test_valid:
|
55
|
74
|
raise HttpException(400)
|
56
|
75
|
else:
|
57
|
|
- obj = dyncode.Object.get(['lodel_id = %d' % lodel_id])
|
|
76
|
+ query_filters = list()
|
|
77
|
+ query_filters.append((uid_field,'=',lodel_id))
|
|
78
|
+ obj = dyncode.Object.get(query_filters)
|
58
|
79
|
if len(obj) == 0:
|
59
|
80
|
raise HttpException(404)
|
60
|
|
- if 'classname' in request.GET:
|
61
|
|
- classname = request.GET['classname']
|
62
|
|
- if len(classname) > 1:
|
63
|
|
- raise HttpException(400)
|
64
|
|
- classname = classname[0]
|
65
|
|
- try:
|
66
|
|
- target_leo = dyncode.Object.name2class(classname)
|
67
|
|
- except LeApiError:
|
68
|
|
- classname = None
|
69
|
81
|
|
70
|
|
- return get_response('admin/admin_edit.html', target=target_leo, lodel_id =lodel_id)
|
|
82
|
+ return get_response('admin/admin_edit.html', target=target_leo, uidfield = uid_field, lodel_id =lodel_id)
|
71
|
83
|
|
72
|
84
|
def admin_create(request):
|
73
|
85
|
classname = None
|
|
@@ -88,8 +100,8 @@ def admin_create(request):
|
88
|
100
|
for in_put, in_value in request.form.items():
|
89
|
101
|
if in_put != 'classname':
|
90
|
102
|
fields[in_put[12:]] = in_value
|
91
|
|
- else:
|
92
|
|
- fields[in_put] = in_value
|
|
103
|
+ #else:
|
|
104
|
+ # fields[in_put] = in_value
|
93
|
105
|
|
94
|
106
|
new_uid = target_leo.insert(fields)
|
95
|
107
|
|