Browse Source

A lot of small bugfixes

Yann Weber 8 years ago
parent
commit
dd2f93faea

BIN
examples/em_test.pickle View File


+ 6
- 3
lodel/leapi/datahandlers/base_classes.py View File

@@ -110,8 +110,7 @@ class DataHandler(object):
110 110
                 return data_handler.default
111 111
         elif data_handler is not None and data_handler.nullable:
112 112
                 return None
113
-
114
-        return RuntimeError("Unable to construct data for field %s", fname)
113
+        return cur_value
115 114
 
116 115
     ##@brief Check datas consistency
117 116
     # @param emcomponent EmComponent : An EmComponent child class instance
@@ -184,6 +183,7 @@ class DataField(DataHandler):
184 183
 # References are fields that stores a reference to another
185 184
 # editorial object
186 185
 class Reference(DataHandler):
186
+    base_type="ref"
187 187
 
188 188
     ##@brief Instanciation
189 189
     # @param allowed_classes list | None : list of allowed em classes if None no restriction
@@ -249,19 +249,22 @@ class SingleRef(Reference):
249 249
 ##@brief This class represent a data_handler for multiple references to another object
250 250
 #
251 251
 # The fields using this data handlers are like SingleRef but can store multiple references in one field
252
-# @note SQL implementation could be tricky
252
+# @note for the moment split on ',' chars
253 253
 class MultipleRef(Reference):
254 254
     
255 255
     ##
256 256
     # @param max_item int | None : indicate the maximum number of item referenced by this field, None mean no limit
257 257
     def __init__(self, max_item = None, **kwargs):
258
+        self.max_item = max_item
258 259
         super().__init__(**kwargs)
259 260
 
260 261
         
261 262
     def _check_data_value(self, value):
263
+        value = value.split(',')
262 264
         if self.max_item is not None:
263 265
             if self.max_item < len(value):
264 266
                 return None, FieldValidationError("To many items")
267
+        return value, None
265 268
 
266 269
 ## @brief Class designed to handle datas access will fieldtypes are constructing datas
267 270
 #

+ 4
- 6
lodel/leapi/datahandlers/references.py View File

@@ -20,10 +20,9 @@ class List(MultipleRef):
20 20
     # @param value *
21 21
     # @return tuple(value, exception)
22 22
     def _check_data_value(self, value):
23
-        val, expt = super()._check_data_value()
23
+        val, expt = super()._check_data_value(value)
24 24
         if not isinstance(expt, Exception):
25 25
             val = list(val)
26
-        val, expt = super()._check_data_value(value.values())
27 26
         return val, expt
28 27
 
29 28
 
@@ -41,10 +40,9 @@ class Set(MultipleRef):
41 40
     # @param value *
42 41
     # @return tuple(value, exception)
43 42
     def _check_data_value(self, value):
44
-        val, expt = super()._check_data_value()
43
+        val, expt = super()._check_data_value(value)
45 44
         if not isinstance(expt, Exception):
46
-            val = set(val)
47
-        val, expt = super()._check_data_value(value.values())
45
+            val = tuple(set(val))
48 46
         return val, expt
49 47
 
50 48
 
@@ -62,9 +60,9 @@ class Map(MultipleRef):
62 60
     # @param value *
63 61
     # @return tuple(value, exception)
64 62
     def _check_data_value(self, value):
63
+        val, expt = super()._check_data_value(value)
65 64
         if not isinstance(value, dict):
66 65
             return None, FieldValidationError("Values for dict fields should be dict")
67
-        val, expt = super()._check_data_value(value.values())
68 66
         return (
69 67
                 None if isinstance(expt, Exception) else value,
70 68
                 expt)

+ 5
- 2
lodel/leapi/leobject.py View File

@@ -180,8 +180,11 @@ class LeObject(object):
180 180
                                                             cls.__name__))
181 181
     ##@return A dict with fieldname as key and datahandler as instance
182 182
     @classmethod
183
-    def fields(cls):
184
-        return copy.copy(cls._fields)
183
+    def fields(cls, include_ro = False):
184
+        if include_ro:
185
+            return copy.copy(cls._fields)
186
+        else:
187
+            return {fname:cls._fields[fname] for fname in cls._fields if not cls._fields[fname].is_internal()}
185 188
     
186 189
     ##@brief Return the list of parents classes
187 190
     #

+ 6
- 4
lodel/leapi/query.py View File

@@ -188,7 +188,9 @@ class LeFilteredQuery(LeQuery):
188 188
                 other_ds_filters[cur_ds].append(
189 189
                     ((rfield, ref_dict), op, value))
190 190
         #deduplication of std filters
191
-        filters_orig = list(set(filters_orig))
191
+        if not isinstance(filters_orig, set):
192
+            filters_orig = set(filters_orig)
193
+        filters_orig = list(filters_orig)
192 194
         # Sets _query_filter attribute of self query
193 195
         self._query_filter = (filters_orig, result_rel_filters)
194 196
 
@@ -290,9 +292,7 @@ field name" % fieldname)
290 292
                 err_l[field] = ret
291 293
                 continue
292 294
             field_datahandler = self._target_class.field(field)
293
-            # Casting value given datahandler
294
-            value, error = field_datahandler._check_data_value(value)
295
-            if isinstance(error, Exception):
295
+            if isinstance(field_datahandler, Exception):
296 296
                 err_l[field] = error
297 297
                 continue
298 298
             if ref_field is not None and not field_datahandler.is_reference():
@@ -335,6 +335,8 @@ field to use for the relational filter"
335 335
                 else:
336 336
                     rel_filters.append((ret, operator, value))
337 337
             else:
338
+                # Casting value given datahandler
339
+                value, error = field_datahandler._check_data_value(value)
338 340
                 res_filters.append((field,operator, value))
339 341
         
340 342
         if len(err_l) > 0:

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

@@ -25,9 +25,6 @@ def admin_update(request):
25 25
         obj = dyncode.Object.get(['lodel_id = %d' % lodel_id])
26 26
         if len(obj) == 0:
27 27
             raise HttpException(404)
28
-    print("WHAT WE GOT AS RESPONSE : ")
29
-    for n,o in enumerate(obj):
30
-        print("\t",n,o.datas(True))
31 28
     return get_response('admin/admin_edit.html', obj = obj)
32 29
 
33 30
 def admin_create(request):

+ 4
- 0
plugins/webui/templates/admin/admin_create.html View File

@@ -1,4 +1,8 @@
1 1
 {% extends "base_backend.html" %}
2
+{% import "admin/editable_component.html" as edit %}
2 3
 {% block title %}- Creating a new {{target.__name__}}{% endblock %}
3 4
 {% block body %}
5
+	{% for fieldname, field in target.fields().items() %}
6
+		{{edit.input(fieldname, field) }}
7
+	{% endfor %}
4 8
 {% endblock %}

BIN
tests/editorial_model.pickle View File


+ 2
- 2
tests/leapi/query/test_datasource.py View File

@@ -71,7 +71,7 @@ class LeQueryDatasourceTestCase(unittest.TestCase):
71 71
         self.assertEqual(call_args[0], cls)
72 72
         self.assertEqual(
73 73
             sorted(call_args[1]),
74
-            sorted([('lodel_id', '=', '1'), ('alias', '=', '2')]))
74
+            sorted([('lodel_id', '=', 1), ('alias', '=', '2')]))
75 75
         self.assertEqual(call_args[2], [])
76 76
         self.check_nocall(read = False, exclude = ['delete'])
77 77
         self.check_nocall(read = True)
@@ -87,7 +87,7 @@ class LeQueryDatasourceTestCase(unittest.TestCase):
87 87
         query.execute()
88 88
         self.mockwrite.delete.assert_called_once_with(
89 89
             cls,
90
-            [('lodel_id', '=', '1')],
90
+            [('lodel_id', '=', 1)],
91 91
             [(('alias', {cls: 'firstname'}), '=', 'foo')])
92 92
         self.check_nocall(read = False, exclude = ['delete'])
93 93
         self.check_nocall(read = True)

+ 7
- 7
tests/leapi/query/test_filtered.py View File

@@ -13,20 +13,20 @@ class LeFilteredQueryTestCase(unittest.TestCase):
13 13
     def test_filters(self):
14 14
         """ Testing FilteredQuery filters handling """
15 15
         test_datas = [  (   'lodel_id = 42',
16
-                            (   [('lodel_id','=','42')],
16
+                            (   [('lodel_id','=',42)],
17 17
                                 [])),
18 18
                         (   'lodel_id <= 42',
19
-                            (   [('lodel_id','<=','42')],
19
+                            (   [('lodel_id','<=',42)],
20 20
                                 [])),
21 21
                         (   ['lodel_id <= 42'],
22
-                            (   [('lodel_id','<=','42')],
22
+                            (   [('lodel_id','<=',42)],
23 23
                                 [])),
24 24
                         (   ('lodel_id <= 42',),
25
-                            (   [('lodel_id','<=','42')],
25
+                            (   [('lodel_id','<=',42)],
26 26
                                 [])),
27 27
                         (   ['lodel_id <= 42','lodel_id >= 33'],
28
-                            (   [   ('lodel_id','<=','42'),
29
-                                    ('lodel_id', '>=','33')],
28
+                            (   [   ('lodel_id','<=',42),
29
+                                    ('lodel_id', '>=',33)],
30 30
                                 [])),
31 31
         ]
32 32
         for q_class in self.q_classes:
@@ -70,7 +70,7 @@ class LeFilteredQueryTestCase(unittest.TestCase):
70 70
                         'not in',
71 71
                         'like',
72 72
                         'not like']
73
-        values = (  '42',
73
+        values = (  42,
74 74
                     'not in',
75 75
                     'in',
76 76
                     'like',

Loading…
Cancel
Save