|
@@ -1,6 +1,7 @@
|
1
|
1
|
# -*- coding: utf-8 -*-
|
2
|
2
|
import importlib
|
3
|
3
|
|
|
4
|
+
|
4
|
5
|
class FieldDataHandler(object):
|
5
|
6
|
|
6
|
7
|
help_text = 'Generic Field Data Handler'
|
|
@@ -12,7 +13,11 @@ class FieldDataHandler(object):
|
12
|
13
|
# @param internal False | str : define whether or not a field is internal
|
13
|
14
|
# @param immutable bool : indicates if the fieldtype has to be defined in child classes of LeObject or if it is designed globally and immutable
|
14
|
15
|
# @param **args
|
|
16
|
+ # @throw NotImplementedError if it is instanciated directly
|
15
|
17
|
def __init__(self, internal=False, immutable=False, **args):
|
|
18
|
+ if self.__class__ == GenericFieldType:
|
|
19
|
+ raise NotImplementedError("Abstract class")
|
|
20
|
+
|
16
|
21
|
self.internal = internal # Check this value ?
|
17
|
22
|
self.immutable = bool(immutable)
|
18
|
23
|
|
|
@@ -28,7 +33,7 @@ class FieldDataHandler(object):
|
28
|
33
|
## @brief checks if a fieldtype is internal
|
29
|
34
|
# @return bool
|
30
|
35
|
def is_internal(self):
|
31
|
|
- return self.internal != False
|
|
36
|
+ return self.internal is not False
|
32
|
37
|
|
33
|
38
|
## @brief calls the data_field defined _check_data_value() method
|
34
|
39
|
# @return tuple (value, error|None)
|
|
@@ -38,6 +43,35 @@ class FieldDataHandler(object):
|
38
|
43
|
def _check_data_value(self, value):
|
39
|
44
|
return (value, None)
|
40
|
45
|
|
|
46
|
+ ## @brief Build field value
|
|
47
|
+ # @param emcomponent EmComponent : An EmComponent child class instance
|
|
48
|
+ # @param fname str : The field name
|
|
49
|
+ # @param datas dict : dict storing fields values (from the component)
|
|
50
|
+ # @param cur_value : the value from the current field (identified by fieldname)
|
|
51
|
+ def construct_data(self, emcomponent, fname, datas, cur_value):
|
|
52
|
+ emcomponent_fields = emcomponent.fields()
|
|
53
|
+ fname_data_handler = None
|
|
54
|
+ if fname in emcomponent_fields:
|
|
55
|
+ fname_data_handler = FieldDataHandler.from_name(emcomponent_fields[fname])
|
|
56
|
+
|
|
57
|
+ if fname in datas.keys():
|
|
58
|
+ return cur_value
|
|
59
|
+ elif fname_data_handler is not None and hasattr(fname_data_handler, 'default'):
|
|
60
|
+ return fname_data_handler.default
|
|
61
|
+ elif fname_data_handler is not None and fname_data_handler.nullable:
|
|
62
|
+ return None
|
|
63
|
+
|
|
64
|
+ raise RuntimeError("Unable to construct data for field %s", fname)
|
|
65
|
+
|
|
66
|
+ ## @brief Check datas consistency
|
|
67
|
+ # @param emcomponent EmComponent : An EmComponent child class instance
|
|
68
|
+ # @param fname : the field name
|
|
69
|
+ # @param datas dict : dict storing fields values
|
|
70
|
+ # @return an Exception instance if fails else True
|
|
71
|
+ # @todo A implémenter
|
|
72
|
+ def check_data_consistency(self, emcomponent, fname, datas):
|
|
73
|
+ return True
|
|
74
|
+
|
41
|
75
|
## @brief given a field type name, returns the associated python class
|
42
|
76
|
# @param fieldtype_name str : A field type name
|
43
|
77
|
# @return DataField child class
|