Browse Source

Interface

prieto 8 years ago
parent
commit
7a321018a0

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

@@ -264,7 +264,8 @@ class MultipleRef(Reference):
264 264
         
265 265
     def _check_data_value(self, value):
266 266
         expt = None
267
-        if isinstance(str, value):
267
+     
268
+        if isinstance(value, str):
268 269
             value, expt = super()._check_data_value(value)
269 270
         elif not hasattr(value, '__iter__'):
270 271
             return None, FieldValidationError("MultipleRef has to be an iterable or a string")

+ 75
- 14
lodel/leapi/datahandlers/references.py View File

@@ -21,34 +21,39 @@ class List(MultipleRef):
21 21
     # @param value *
22 22
     # @return tuple(value, exception)
23 23
     def _check_data_value(self, value):
24
-        if isinstance(value, list) or isintance(value, str):
24
+        if isinstance(value, list) or isinstance(value, str):
25 25
             val, expt = super()._check_data_value(value)
26 26
         else:
27 27
             return None, FieldValidationError("List or string expected for a list field")
28
-        if not isinstance(expt, Exception):
29
-            val = list(val)
28
+        #if not isinstance(expt, Exception):
29
+        #    val = list(val)
30
+
30 31
         return val, expt
31 32
 
32 33
     def construct_data(self, emcomponent, fname, datas, cur_value):
34
+        if cur_value == 'None' or cur_value is None or cur_value == '':
35
+            return None
33 36
         emcomponent_fields = emcomponent.fields()
34 37
         data_handler = None
35 38
         if fname in emcomponent_fields:
36 39
             data_handler = emcomponent_fields[fname]
37 40
         u_fname = emcomponent.uid_fieldname()
38
-        uidtype = u_fname[0] if isinstance(u_fname, tuple) else u_fname 
39
-        
41
+        uidtype = emcomponent.field(u_fname[0]) if isinstance(u_fname, list) else emcomponent.field(u_fname)
42
+
40 43
         if isinstance(cur_value, str):
41 44
             value = cur_value.split(',')
42
-            l_value = [uidtype(uid) for uid in value]
45
+            l_value = [int(uid) for uid in value] ## à remplacer par uidtype
46
+            logger.debug(l_value)
43 47
             return l_value
44 48
         elif isinstance(cur_value, list):
45 49
             type_list = str if isinstance(cur_value[0], str) else uidtype
46 50
             l_value = list()
51
+            
47 52
             for value in cur_value:
48 53
                 if isinstance(value,uidtype):
49 54
                     l_value.append(value)
50 55
                 else:
51
-                    raise ValueError("The items must be of the same type, string or %s" % (target.__name__))
56
+                    raise ValueError("The items must be of the same type, string or %s" % (ecomponent.__name__))
52 57
             return l_value
53 58
         else:
54 59
             return None
@@ -67,10 +72,38 @@ class Set(MultipleRef):
67 72
     # @param value *
68 73
     # @return tuple(value, exception)
69 74
     def _check_data_value(self, value):
70
-        val, expt = super()._check_data_value(value)
71
-        if not isinstance(expt, Exception):
72
-            val = tuple(set(val))
75
+        if isinstance(value, set) or isinstance(value, str):
76
+            val, expt = super()._check_data_value(value)
77
+        else:
78
+            return None, FieldValidationError("Set or string expected for a set field")
73 79
         return val, expt
80
+    
81
+    def construct_data(self, emcomponent, fname, datas, cur_value):
82
+        if cur_value == 'None' or cur_value is None or cur_value == '':
83
+            return None
84
+        emcomponent_fields = emcomponent.fields()
85
+        data_handler = None
86
+        if fname in emcomponent_fields:
87
+            data_handler = emcomponent_fields[fname]
88
+        u_fname = emcomponent.uid_fieldname()
89
+        uidtype = emcomponent.field(u_fname[0]) if isinstance(u_fname, list) else emcomponent.field(u_fname)
90
+        if isinstance(cur_value, str):
91
+            value = cur_value.split(',')
92
+            l_value = [int(uid) for uid in value] ## à remplacer par uidtype
93
+            return list(l_value)
94
+        elif isinstance(cur_value, set):
95
+            type_list = str if isinstance(cur_value[0], str) else uidtype
96
+            l_value = list()
97
+            
98
+            for value in cur_value:
99
+                if isinstance(value,uidtype):
100
+                    l_value.append(value)
101
+                else:
102
+                    raise ValueError("The items must be of the same type, string or %s" % (ecomponent.__name__))
103
+            return l_value
104
+            logger.debug(l_value)
105
+        else:
106
+            return None
74 107
 
75 108
 
76 109
 ##@brief Child class of MultipleRef where references are represented in the form of a python dict
@@ -108,7 +141,35 @@ class Hierarch(MultipleRef):
108 141
                             **kwargs)
109 142
 
110 143
     def _check_data_value(self, value):
111
-        value, expt = super()._check_data_value(value)
112
-        if isinstance(expt, Exception):
113
-            return None, expt
114
-        # determine depth with datasource
144
+        if isinstance(value, list) or isinstance(value, str):
145
+            val, expt = super()._check_data_value(value)
146
+        else:
147
+            return None, FieldValidationError("Set or string expected for a set field")
148
+        return val, expt
149
+    
150
+    def construct_data(self, emcomponent, fname, datas, cur_value):
151
+        if cur_value == 'None' or cur_value is None or cur_value == '':
152
+            return None
153
+        emcomponent_fields = emcomponent.fields()
154
+        data_handler = None
155
+        if fname in emcomponent_fields:
156
+            data_handler = emcomponent_fields[fname]
157
+        u_fname = emcomponent.uid_fieldname()
158
+        uidtype = emcomponent.field(u_fname[0]) if isinstance(u_fname, list) else emcomponent.field(u_fname)
159
+        if isinstance(cur_value, str):
160
+            value = cur_value.split(',')
161
+            l_value = [int(uid) for uid in value] ## à remplacer par uidtype
162
+            return list(l_value)
163
+        elif isinstance(cur_value, list):
164
+            type_list = str if isinstance(cur_value[0], str) else uidtype
165
+            l_value = list()
166
+            
167
+            for value in cur_value:
168
+                if isinstance(value,uidtype):
169
+                    l_value.append(value)
170
+                else:
171
+                    raise ValueError("The items must be of the same type, string or %s" % (ecomponent.__name__))
172
+            return l_value
173
+            logger.debug(l_value)
174
+        else:
175
+            return None

+ 3
- 0
lodel/leapi/leobject.py View File

@@ -517,6 +517,9 @@ DS_PLUGIN_NAME.DS_INSTANCE_NAME. But got %s" % ds_identifier)
517 517
         for name, value in [ (name, value) for name, value in datas.items() if name in correct ]:
518 518
             dh = cls._fields[name]
519 519
             res = dh.check_data_value(value)
520
+            logger.debug(name)
521
+            logger.debug(value)
522
+            logger.debug(res)
520 523
             checked_datas[name], err = res
521 524
             if err:
522 525
                 err_l[name] = err

+ 5
- 0
plugins/webui/interface/controllers/admin.py View File

@@ -31,6 +31,8 @@ def admin_update(request):
31 31
         for in_put, in_value in request.form.items():
32 32
             if in_put != 'classname' and  in_put != 'uid':
33 33
                 fields[in_put[12:]] = in_value
34
+            elif in_put == 'classname':
35
+                fields['classname'] = in_value
34 36
         obj = (target_leo.get(('lodel_id = %s' % (uid))))[0]
35 37
         inserted = obj.update(fields)
36 38
         
@@ -116,6 +118,9 @@ def admin_create(request):
116 118
 def admin_classes(request):
117 119
     return get_response('admin/list_classes_admin.html', my_classes = dyncode.dynclasses)
118 120
 
121
+def create_object(request):
122
+    return get_response('admin/list_classes_create.html', my_classes = dyncode.dynclasses)
123
+    
119 124
 def admin_class(request):
120 125
     if 'classname' in request.GET:
121 126
         classname = request.GET['classname']

+ 1
- 0
plugins/webui/interface/urls.py View File

@@ -7,6 +7,7 @@ urls = (
7 7
     (r'^/admin/create$', admin_create),
8 8
     (r'^/admin/update$', admin_update),
9 9
     (r'^/admin/classes_admin$', admin_classes),
10
+    (r'^/admin/object_create', create_object),
10 11
     (r'^/admin/class_admin$', admin_class),
11 12
     (r'/test/(?P<id>.*)$', test),
12 13
     (r'^/test/?$', test),

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

@@ -4,7 +4,8 @@
4 4
 <h1>{{settings.sitename}} administration</h1>
5 5
 {{url('admin')}}
6 6
 <ul>
7
-    <li><a href="classes_admin">List of Classes</a></li>
7
+    <li><a href="classes_admin">Edit object</a></li>
8
+    <li><a href="object_create">Create object</a></li>
8 9
 </ul>
9 10
 
10 11
 {% endblock %}

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

@@ -7,9 +7,9 @@
7 7
 {% if msg is not none %}
8 8
 {% block msg %} <p style="color:red; font-size:20pt; font-weight:bold">{{ msg }}</p> {% endblock %}
9 9
 {% endif %}
10
-<h1>Lodel 2 - Edit Object {{ lodel_id }} of {{ target.__name__ }}</h1>
10
+<h1>Lodel 2 - Edit {{ target.__name__ }} with uid {{ lodel_id }} </h1>
11 11
     <form action="" method ="post">
12
-    <input type="hidden" name="uid" value="{{ lodel_id}}" >
12
+    <input type="hidden" name="uid" value="{{ lodel_id}}" />
13 13
     <input type="hidden" name="classname" value={{ target.__name__ }} />
14 14
     {% for fieldname, fieldvalue in obj.fields().items() %}
15 15
        <div style="padding-bottom:15px;"> {{edit.input(fieldname, fieldvalue, obj.data(fieldname)) }} </div>

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

@@ -4,8 +4,15 @@
4 4
 		<input id="field_input_{{fieldname}}" name="field_input_{{fieldname}}" type="checkbox" checked="{% if value %}checked{% endif %}" />
5 5
 	{% elif field.base_type == 'char' or field.base_type == 'int' %}
6 6
 		<input id="{{fieldname}}" name="field_input_{{fieldname}}" type="text" value="{{value}}" />
7
-        
8
-        
7
+    {% elif field.base_type == 'ref' %}
8
+        {% if value is iterable %}
9
+        {% set sval=value|join(',') %}
10
+        {% else %}
11
+        {% set sval = value %}
12
+        {% endif %}
13
+        <input id="{{fieldname}}" name="field_input_{{fieldname}}" type="text" value="{{sval}}" />
14
+        {% set l_classe = field.allowed_classes %}
15
+        <p> Please enter uids to instances of {{ l_classe.__name__ }} separated by comma </p>
9 16
 	{% else %}
10 17
 		Unsupported base type "{{field.base_type}}" </br>
11 18
 	{% endif %}

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

@@ -4,14 +4,13 @@
4 4
 {% set objects = my_class.get(('lodel_id = %s') % (lodel_id)) %}
5 5
 {% set obj = objects.pop() %}
6 6
 {% if my_class.is_abstract() %}
7
-{{ obj.classname}}
8
-{% set classname = obj.classname %}
7
+{% set classname = obj.data('classname') %}
9 8
 {% set my_class = my_class.name2class(classname) %}
10 9
 {% endif %}
11 10
 {% block title %}Lodel 2 - Object {{ lodel_id }} {% endblock %}
12 11
 {% import "components/components.html" as components %}
13 12
 {% block content %}
14
-<h1>Lodel 2 - Object {{ lodel_id }} of the class {{ classname }}</h1>
13
+<h1>Lodel 2 - {{ classname }} with uid {{ lodel_id }}</h1>
15 14
     
16 15
 <ul>
17 16
     <!-- To get a component HTML code, it is necessary to call : components.<macro_name>(args) -->

Loading…
Cancel
Save