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