Browse Source

Replace the term lodel_id in the interface by LeObject class method

prieto 8 years ago
parent
commit
e3826c1750

+ 1
- 1
lodel/leapi/datahandlers/base_classes.py View File

193
     # @param **kwargs : other arguments
193
     # @param **kwargs : other arguments
194
     def __init__(self, allowed_classes = None, back_reference = None, internal=False, **kwargs):
194
     def __init__(self, allowed_classes = None, back_reference = None, internal=False, **kwargs):
195
         self.__allowed_classes = set() if allowed_classes is None else set(allowed_classes)
195
         self.__allowed_classes = set() if allowed_classes is None else set(allowed_classes)
196
+        self._linked_classes = list() if allowed_classes is None else allowed_classes
196
         if back_reference is not None:
197
         if back_reference is not None:
197
             if len(back_reference) != 2:
198
             if len(back_reference) != 2:
198
                 raise ValueError("A tuple (classname, fieldname) expected but got '%s'" % back_reference)
199
                 raise ValueError("A tuple (classname, fieldname) expected but got '%s'" % back_reference)
213
     ##@brief Set the back reference for this field.
214
     ##@brief Set the back reference for this field.
214
     def _set_back_reference(self, back_reference):
215
     def _set_back_reference(self, back_reference):
215
         self.__back_reference = back_reference
216
         self.__back_reference = back_reference
216
-        
217
 
217
 
218
     ##@brief Check value
218
     ##@brief Check value
219
     # @param value *
219
     # @param value *

+ 32
- 20
plugins/webui/interface/controllers/admin.py View File

18
         error = None
18
         error = None
19
         datas = list()
19
         datas = list()
20
         classname = request.form['classname']
20
         classname = request.form['classname']
21
+        logger.warning('Composed uids broken here')
21
         uid = request.form['uid']
22
         uid = request.form['uid']
22
         try:
23
         try:
23
             target_leo = dyncode.Object.name2class(classname)
24
             target_leo = dyncode.Object.name2class(classname)
26
         if classname is None or target_leo.is_abstract():
27
         if classname is None or target_leo.is_abstract():
27
             raise HttpException(400)
28
             raise HttpException(400)
28
         fieldnames = target_leo.fieldnames()
29
         fieldnames = target_leo.fieldnames()
30
+
31
+        uid_field = target_leo.uid_fieldname()[0]
29
         fields = dict()
32
         fields = dict()
30
 
33
 
31
         for in_put, in_value in request.form.items():
34
         for in_put, in_value in request.form.items():
32
             if in_put != 'classname' and  in_put != 'uid':
35
             if in_put != 'classname' and  in_put != 'uid':
33
                 fields[in_put[12:]] = in_value
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
         inserted = obj.update(fields)
43
         inserted = obj.update(fields)
38
         
44
         
39
         if inserted==1:
45
         if inserted==1:
40
             msg = 'Successfully updated';
46
             msg = 'Successfully updated';
41
         else:
47
         else:
42
             msg = 'Oops something wrong happened...object not saved'
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
     if test_valid:
67
     if test_valid:
49
         try:
68
         try:
50
-            lodel_id = int(request.GET['lodel_id'][0])
69
+            lodel_id = request.GET[uid_field][0]
51
         except (ValueError, TypeError):
70
         except (ValueError, TypeError):
52
             test_valid = False
71
             test_valid = False
53
 
72
 
54
     if not test_valid:
73
     if not test_valid:
55
         raise HttpException(400)
74
         raise HttpException(400)
56
     else:
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
         if len(obj) == 0:
79
         if len(obj) == 0:
59
             raise HttpException(404)
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
 def admin_create(request):
84
 def admin_create(request):
73
     classname = None
85
     classname = None
88
         for in_put, in_value in request.form.items():
100
         for in_put, in_value in request.form.items():
89
             if in_put != 'classname':
101
             if in_put != 'classname':
90
                 fields[in_put[12:]] = in_value
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
         new_uid = target_leo.insert(fields)
106
         new_uid = target_leo.insert(fields)
95
         
107
         

+ 24
- 17
plugins/webui/interface/controllers/listing.py View File

1
 # -*- coding: utf-8 -*-
1
 # -*- coding: utf-8 -*-
2
 from .base import get_response
2
 from .base import get_response
3
 from ...exceptions import *
3
 from ...exceptions import *
4
+from lodel import logger
4
 import leapi_dyncode as dyncode
5
 import leapi_dyncode as dyncode
5
 
6
 
6
 def list_classes(request):
7
 def list_classes(request):
25
     return get_response('listing/show_class.html', classname=classname)
26
     return get_response('listing/show_class.html', classname=classname)
26
 
27
 
27
 def show_object(request):
28
 def show_object(request):
28
-    template_vars = {
29
-        'params': request.GET
30
-    }
31
-    test_valid = 'lodel_id' in request.GET \
32
-        and len(request.GET['lodel_id']) == 1
29
+    if 'classname' in request.GET:
30
+        classname = request.GET['classname']
31
+        if len(classname) > 1:
32
+            raise HttpException(400)
33
+        classname = classname[0]
34
+        try:
35
+            target_leo = dyncode.Object.name2class(classname)
36
+        except LeApiError:
37
+            classname = None
38
+    else:
39
+        raise HttpException(400)
40
+    
41
+    logger.warning('Composed uids broken here')
42
+    uid_field = target_leo.uid_fieldname()[0]
43
+    
44
+    test_valid = uid_field in request.GET \
45
+        and len(request.GET[uid_field]) == 1
33
 
46
 
34
     if test_valid:
47
     if test_valid:
35
         try:
48
         try:
36
-            lodel_id = int(request.GET['lodel_id'][0])
49
+            lodel_id = int(request.GET[uid_field][0])
37
         except (ValueError, TypeError):
50
         except (ValueError, TypeError):
38
             test_valid = False
51
             test_valid = False
39
 
52
 
40
     if not test_valid:
53
     if not test_valid:
41
         raise HttpException(400)
54
         raise HttpException(400)
42
     else:
55
     else:
43
-        obj = dyncode.Object.get(['lodel_id = %d' % lodel_id])
56
+        query_filters = list()
57
+        query_filters.append((uid_field,'=',lodel_id))
58
+        obj = dyncode.Object.get(query_filters)
44
         if len(obj) == 0:
59
         if len(obj) == 0:
45
             raise HttpException(404)
60
             raise HttpException(404)
46
-    if 'classname' in request.GET:
47
-        classname = request.GET['classname']
48
-        if len(classname) > 1:
49
-            raise HttpException(400)
50
-        classname = classname[0]
51
-        try:
52
-            target_leo = dyncode.Object.name2class(classname)
53
-        except LeApiError:
54
-            classname = None
55
-    return get_response('listing/show_object.html', lodel_id=lodel_id, classname=classname)
61
+
62
+    return get_response('listing/show_object.html', lodel_id=lodel_id, uidfield = uid_field, classname=classname)

+ 3
- 3
plugins/webui/run.py View File

13
 from lodel.utils.datetime import get_utc_timestamp
13
 from lodel.utils.datetime import get_utc_timestamp
14
 from lodel.plugin.hooks import LodelHook
14
 from lodel.plugin.hooks import LodelHook
15
 
15
 
16
-SESSION_FILES_BASE_DIR = Settings.sessions.directory
17
-SESSION_FILES_TEMPLATE = Settings.sessions.file_template
18
-SESSION_EXPIRATION_LIMIT = Settings.sessions.expiration
16
+SESSION_FILES_BASE_DIR = Settings.webui.sessions.directory
17
+SESSION_FILES_TEMPLATE = Settings.webui.sessions.file_template
18
+SESSION_EXPIRATION_LIMIT = Settings.webui.sessions.expiration
19
 
19
 
20
 session_store = FilesystemSessionStore(path=SESSION_FILES_BASE_DIR, filename_template=SESSION_FILES_TEMPLATE)
20
 session_store = FilesystemSessionStore(path=SESSION_FILES_BASE_DIR, filename_template=SESSION_FILES_TEMPLATE)
21
 
21
 

+ 1
- 0
plugins/webui/templates/admin/admin_edit.html View File

1
 {% extends "base_backend.html" %}
1
 {% extends "base_backend.html" %}
2
 {% import "admin/editable_component.html" as edit %}
2
 {% import "admin/editable_component.html" as edit %}
3
 {% set objects = target.get(('lodel_id = %s') % (lodel_id)) %}
3
 {% set objects = target.get(('lodel_id = %s') % (lodel_id)) %}
4
+{% set objects = target.get(('%s = %s') % (uidfield, lodel_id)) %}
4
 {% set obj = objects.pop() %}
5
 {% set obj = objects.pop() %}
5
 {% block title %}- Edit Object{% endblock %}
6
 {% block title %}- Edit Object{% endblock %}
6
 {% block body %}
7
 {% block body %}

+ 1
- 1
plugins/webui/templates/admin/editable_component.html View File

12
         {% endif %}
12
         {% endif %}
13
         {% if field.directly_editable %}
13
         {% if field.directly_editable %}
14
             <input id="{{fieldname}}" name="field_input_{{fieldname}}" type="text" value="{{sval}}" >
14
             <input id="{{fieldname}}" name="field_input_{{fieldname}}" type="text" value="{{sval}}" >
15
-            {% set l_classe = field.allowed_classes %}
15
+            {% set l_classe = field._linked_classes %}
16
             <p> Please enter uids to instances of {{ l_classe.__name__ }} separated by commas </p>
16
             <p> Please enter uids to instances of {{ l_classe.__name__ }} separated by commas </p>
17
         {% else %}
17
         {% else %}
18
             <input id="{{fieldname}}" name="field_input_{{fieldname}}" type="text" value="{{sval}}" readonly >
18
             <input id="{{fieldname}}" name="field_input_{{fieldname}}" type="text" value="{{sval}}" readonly >

+ 1
- 1
plugins/webui/templates/listing/show_object.html View File

1
 {% extends "base.html" %}
1
 {% extends "base.html" %}
2
 {% import 'components/components.html' as components %}
2
 {% import 'components/components.html' as components %}
3
 {% set my_class = leapi.name2class(classname) %}
3
 {% set my_class = leapi.name2class(classname) %}
4
-{% set objects = my_class.get(('lodel_id = %s') % (lodel_id)) %}
4
+{% set objects = my_class.get(('%s = %s') % (uidfield, lodel_id)) %}
5
 {% set obj = objects.pop() %}
5
 {% set obj = objects.pop() %}
6
 {% if my_class.is_abstract() %}
6
 {% if my_class.is_abstract() %}
7
 {% set classname = obj.data('classname') %}
7
 {% set classname = obj.data('classname') %}

Loading…
Cancel
Save