Просмотр исходного кода

Replace the term lodel_id in the interface by LeObject class method

prieto 8 лет назад
Родитель
Сommit
e3826c1750

+ 1
- 1
lodel/leapi/datahandlers/base_classes.py Просмотреть файл

@@ -193,6 +193,7 @@ class Reference(DataHandler):
193 193
     # @param **kwargs : other arguments
194 194
     def __init__(self, allowed_classes = None, back_reference = None, internal=False, **kwargs):
195 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 197
         if back_reference is not None:
197 198
             if len(back_reference) != 2:
198 199
                 raise ValueError("A tuple (classname, fieldname) expected but got '%s'" % back_reference)
@@ -213,7 +214,6 @@ class Reference(DataHandler):
213 214
     ##@brief Set the back reference for this field.
214 215
     def _set_back_reference(self, back_reference):
215 216
         self.__back_reference = back_reference
216
-        
217 217
 
218 218
     ##@brief Check value
219 219
     # @param value *

+ 32
- 20
plugins/webui/interface/controllers/admin.py Просмотреть файл

@@ -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
         

+ 24
- 17
plugins/webui/interface/controllers/listing.py Просмотреть файл

@@ -1,6 +1,7 @@
1 1
 # -*- coding: utf-8 -*-
2 2
 from .base import get_response
3 3
 from ...exceptions import *
4
+from lodel import logger
4 5
 import leapi_dyncode as dyncode
5 6
 
6 7
 def list_classes(request):
@@ -25,31 +26,37 @@ def show_class(request):
25 26
     return get_response('listing/show_class.html', classname=classname)
26 27
 
27 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 47
     if test_valid:
35 48
         try:
36
-            lodel_id = int(request.GET['lodel_id'][0])
49
+            lodel_id = int(request.GET[uid_field][0])
37 50
         except (ValueError, TypeError):
38 51
             test_valid = False
39 52
 
40 53
     if not test_valid:
41 54
         raise HttpException(400)
42 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 59
         if len(obj) == 0:
45 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 Просмотреть файл

@@ -13,9 +13,9 @@ from .client import WebUiClient
13 13
 from lodel.utils.datetime import get_utc_timestamp
14 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 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 Просмотреть файл

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

+ 1
- 1
plugins/webui/templates/admin/editable_component.html Просмотреть файл

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

+ 1
- 1
plugins/webui/templates/listing/show_object.html Просмотреть файл

@@ -1,7 +1,7 @@
1 1
 {% extends "base.html" %}
2 2
 {% import 'components/components.html' as components %}
3 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 5
 {% set obj = objects.pop() %}
6 6
 {% if my_class.is_abstract() %}
7 7
 {% set classname = obj.data('classname') %}

Загрузка…
Отмена
Сохранить