Browse Source

Interface

prieto 8 years ago
parent
commit
7a321018a0

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

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

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

21
     # @param value *
21
     # @param value *
22
     # @return tuple(value, exception)
22
     # @return tuple(value, exception)
23
     def _check_data_value(self, value):
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
             val, expt = super()._check_data_value(value)
25
             val, expt = super()._check_data_value(value)
26
         else:
26
         else:
27
             return None, FieldValidationError("List or string expected for a list field")
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
         return val, expt
31
         return val, expt
31
 
32
 
32
     def construct_data(self, emcomponent, fname, datas, cur_value):
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
         emcomponent_fields = emcomponent.fields()
36
         emcomponent_fields = emcomponent.fields()
34
         data_handler = None
37
         data_handler = None
35
         if fname in emcomponent_fields:
38
         if fname in emcomponent_fields:
36
             data_handler = emcomponent_fields[fname]
39
             data_handler = emcomponent_fields[fname]
37
         u_fname = emcomponent.uid_fieldname()
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
         if isinstance(cur_value, str):
43
         if isinstance(cur_value, str):
41
             value = cur_value.split(',')
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
             return l_value
47
             return l_value
44
         elif isinstance(cur_value, list):
48
         elif isinstance(cur_value, list):
45
             type_list = str if isinstance(cur_value[0], str) else uidtype
49
             type_list = str if isinstance(cur_value[0], str) else uidtype
46
             l_value = list()
50
             l_value = list()
51
+            
47
             for value in cur_value:
52
             for value in cur_value:
48
                 if isinstance(value,uidtype):
53
                 if isinstance(value,uidtype):
49
                     l_value.append(value)
54
                     l_value.append(value)
50
                 else:
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
             return l_value
57
             return l_value
53
         else:
58
         else:
54
             return None
59
             return None
67
     # @param value *
72
     # @param value *
68
     # @return tuple(value, exception)
73
     # @return tuple(value, exception)
69
     def _check_data_value(self, value):
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
         return val, expt
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
 ##@brief Child class of MultipleRef where references are represented in the form of a python dict
109
 ##@brief Child class of MultipleRef where references are represented in the form of a python dict
108
                             **kwargs)
141
                             **kwargs)
109
 
142
 
110
     def _check_data_value(self, value):
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
         for name, value in [ (name, value) for name, value in datas.items() if name in correct ]:
517
         for name, value in [ (name, value) for name, value in datas.items() if name in correct ]:
518
             dh = cls._fields[name]
518
             dh = cls._fields[name]
519
             res = dh.check_data_value(value)
519
             res = dh.check_data_value(value)
520
+            logger.debug(name)
521
+            logger.debug(value)
522
+            logger.debug(res)
520
             checked_datas[name], err = res
523
             checked_datas[name], err = res
521
             if err:
524
             if err:
522
                 err_l[name] = err
525
                 err_l[name] = err

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

31
         for in_put, in_value in request.form.items():
31
         for in_put, in_value in request.form.items():
32
             if in_put != 'classname' and  in_put != 'uid':
32
             if in_put != 'classname' and  in_put != 'uid':
33
                 fields[in_put[12:]] = in_value
33
                 fields[in_put[12:]] = in_value
34
+            elif in_put == 'classname':
35
+                fields['classname'] = in_value
34
         obj = (target_leo.get(('lodel_id = %s' % (uid))))[0]
36
         obj = (target_leo.get(('lodel_id = %s' % (uid))))[0]
35
         inserted = obj.update(fields)
37
         inserted = obj.update(fields)
36
         
38
         
116
 def admin_classes(request):
118
 def admin_classes(request):
117
     return get_response('admin/list_classes_admin.html', my_classes = dyncode.dynclasses)
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
 def admin_class(request):
124
 def admin_class(request):
120
     if 'classname' in request.GET:
125
     if 'classname' in request.GET:
121
         classname = request.GET['classname']
126
         classname = request.GET['classname']

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

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

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

4
 <h1>{{settings.sitename}} administration</h1>
4
 <h1>{{settings.sitename}} administration</h1>
5
 {{url('admin')}}
5
 {{url('admin')}}
6
 <ul>
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
 </ul>
9
 </ul>
9
 
10
 
10
 {% endblock %}
11
 {% endblock %}

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

7
 {% if msg is not none %}
7
 {% if msg is not none %}
8
 {% block msg %} <p style="color:red; font-size:20pt; font-weight:bold">{{ msg }}</p> {% endblock %}
8
 {% block msg %} <p style="color:red; font-size:20pt; font-weight:bold">{{ msg }}</p> {% endblock %}
9
 {% endif %}
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
     <form action="" method ="post">
11
     <form action="" method ="post">
12
-    <input type="hidden" name="uid" value="{{ lodel_id}}" >
12
+    <input type="hidden" name="uid" value="{{ lodel_id}}" />
13
     <input type="hidden" name="classname" value={{ target.__name__ }} />
13
     <input type="hidden" name="classname" value={{ target.__name__ }} />
14
     {% for fieldname, fieldvalue in obj.fields().items() %}
14
     {% for fieldname, fieldvalue in obj.fields().items() %}
15
        <div style="padding-bottom:15px;"> {{edit.input(fieldname, fieldvalue, obj.data(fieldname)) }} </div>
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
 		<input id="field_input_{{fieldname}}" name="field_input_{{fieldname}}" type="checkbox" checked="{% if value %}checked{% endif %}" />
4
 		<input id="field_input_{{fieldname}}" name="field_input_{{fieldname}}" type="checkbox" checked="{% if value %}checked{% endif %}" />
5
 	{% elif field.base_type == 'char' or field.base_type == 'int' %}
5
 	{% elif field.base_type == 'char' or field.base_type == 'int' %}
6
 		<input id="{{fieldname}}" name="field_input_{{fieldname}}" type="text" value="{{value}}" />
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
 	{% else %}
16
 	{% else %}
10
 		Unsupported base type "{{field.base_type}}" </br>
17
 		Unsupported base type "{{field.base_type}}" </br>
11
 	{% endif %}
18
 	{% endif %}

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

4
 {% set objects = my_class.get(('lodel_id = %s') % (lodel_id)) %}
4
 {% set objects = my_class.get(('lodel_id = %s') % (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
-{{ obj.classname}}
8
-{% set classname = obj.classname %}
7
+{% set classname = obj.data('classname') %}
9
 {% set my_class = my_class.name2class(classname) %}
8
 {% set my_class = my_class.name2class(classname) %}
10
 {% endif %}
9
 {% endif %}
11
 {% block title %}Lodel 2 - Object {{ lodel_id }} {% endblock %}
10
 {% block title %}Lodel 2 - Object {{ lodel_id }} {% endblock %}
12
 {% import "components/components.html" as components %}
11
 {% import "components/components.html" as components %}
13
 {% block content %}
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
 <ul>
15
 <ul>
17
     <!-- To get a component HTML code, it is necessary to call : components.<macro_name>(args) -->
16
     <!-- To get a component HTML code, it is necessary to call : components.<macro_name>(args) -->

Loading…
Cancel
Save