|
@@ -39,12 +39,6 @@ class GenericFieldType(object):
|
39
|
39
|
def _check_data_value(self, value):
|
40
|
40
|
return (value, None)
|
41
|
41
|
|
42
|
|
- ## @brief Wrapper for _construct_data() method
|
43
|
|
- #
|
44
|
|
- # Now useless
|
45
|
|
- def construct_data(self, lec, fname, datas, cur_value):
|
46
|
|
- return self._construct_data(lec, fname, datas, cur_value)
|
47
|
|
-
|
48
|
42
|
## @brief Build field value
|
49
|
43
|
# @param lec LeCrud : A LeCrud child class
|
50
|
44
|
# @param fname str : The field name
|
|
@@ -52,7 +46,7 @@ class GenericFieldType(object):
|
52
|
46
|
# @param cur_value : the value for the current field (identified by fieldname)
|
53
|
47
|
# @return constructed datas (for the fname field)
|
54
|
48
|
# @throw RuntimeError if unable to construct data
|
55
|
|
- def _construct_data(self, lec, fname, datas, cur_value):
|
|
49
|
+ def construct_data(self, lec, fname, datas, cur_value):
|
56
|
50
|
if fname in datas.keys():
|
57
|
51
|
return cur_value
|
58
|
52
|
elif hasattr(lec.fieldtypes()[fname], 'default'):
|
|
@@ -91,6 +85,7 @@ class GenericFieldType(object):
|
91
|
85
|
hash_dats.append((kdic, getattr(self, kdic)))
|
92
|
86
|
return hash(tuple(hash_dats))
|
93
|
87
|
|
|
88
|
+## @brief Represent fieldtypes handling a single value
|
94
|
89
|
class SingleValueFieldType(GenericFieldType):
|
95
|
90
|
|
96
|
91
|
## @brief Instanciate a new fieldtype
|
|
@@ -121,6 +116,9 @@ class SingleValueFieldType(GenericFieldType):
|
121
|
116
|
return (None, None)
|
122
|
117
|
return super().check_data_value(value)
|
123
|
118
|
|
|
119
|
+## @brief Abstract class for fieldtype representing references
|
|
120
|
+#
|
|
121
|
+# In MySQL its foreign keys (for example leo fieldtypes)
|
124
|
122
|
class ReferenceFieldType(SingleValueFieldType):
|
125
|
123
|
|
126
|
124
|
## @brief Instanciate a new fieldtype
|
|
@@ -145,6 +143,9 @@ class ReferenceFieldType(SingleValueFieldType):
|
145
|
143
|
);
|
146
|
144
|
pass
|
147
|
145
|
|
|
146
|
+## @brief Abstract class for fieldtypes handling multiple values identified by a key
|
|
147
|
+#
|
|
148
|
+# For example i18n fieldtype
|
148
|
149
|
class MultiValueFieldType(GenericFieldType):
|
149
|
150
|
|
150
|
151
|
## @brief Instanciate a new multivalue fieldtype
|
|
@@ -164,6 +165,12 @@ class MultiValueFieldType(GenericFieldType):
|
164
|
165
|
self.value_fieldtype = value_fieldtype
|
165
|
166
|
|
166
|
167
|
## @brief Class designed to handle datas access will fieldtypes are constructing datas
|
|
168
|
+#
|
|
169
|
+# This class is designed to allow automatic scheduling of construct_data calls.
|
|
170
|
+#
|
|
171
|
+# In theory it's able to detect circular dependencies
|
|
172
|
+# @todo test circular deps detection
|
|
173
|
+# @todo test circulat deps false positiv
|
167
|
174
|
class DatasConstructor(object):
|
168
|
175
|
|
169
|
176
|
## @brief Init a DatasConstructor
|
|
@@ -181,10 +188,12 @@ class DatasConstructor(object):
|
181
|
188
|
self._constructed = []
|
182
|
189
|
## Stores construct calls list
|
183
|
190
|
self._construct_calls = []
|
184
|
|
-
|
|
191
|
+
|
|
192
|
+ ## @brief Implements the dict.keys() method on instance
|
185
|
193
|
def keys(self):
|
186
|
194
|
return self._datas.keys()
|
187
|
|
-
|
|
195
|
+
|
|
196
|
+ ## @brief Allows to access the instance like a dict
|
188
|
197
|
def __getitem__(self, fname):
|
189
|
198
|
if fname not in self._constructed:
|
190
|
199
|
if fname in self._construct_calls:
|
|
@@ -193,9 +202,12 @@ class DatasConstructor(object):
|
193
|
202
|
self._datas[fname] = self._fieldtypes[fname].construct_data(self._lec, fname, self, cur_value)
|
194
|
203
|
self._constructed.append(fname)
|
195
|
204
|
return self._datas[fname]
|
196
|
|
-
|
|
205
|
+
|
|
206
|
+ ## @brief Allows to set instance values like a dict
|
|
207
|
+ # @warning Should not append in theory
|
197
|
208
|
def __setitem__(self, fname, value):
|
198
|
209
|
self._datas[fname] = value
|
|
210
|
+ warnings.warn("Setting value of an DatasConstructor instance")
|
199
|
211
|
|
200
|
212
|
|
201
|
213
|
#
|