|
@@ -49,6 +49,32 @@ class LeFactory(object):
|
49
|
49
|
with open(self._code_filename, "w+") as dynfp:
|
50
|
50
|
dynfp.write(self.generate_python(model, datasource_cls, datasource_args))
|
51
|
51
|
|
|
52
|
+ ## @brief Generate fieldtypes for concret classes
|
|
53
|
+ # @param ft_dict dict : key = fieldname value = fieldtype __init__ args
|
|
54
|
+ # @return (uid_fieldtypes, fieldtypes) designed to be printed in generated code
|
|
55
|
+ def concret_fieldtypes(self, ft_dict):
|
|
56
|
+ res_ft_l = list()
|
|
57
|
+ res_uid_ft = None
|
|
58
|
+ for fname, ftargs in ft_dict.items():
|
|
59
|
+ ftargs = copy.copy(ftargs)
|
|
60
|
+ fieldtype = ftargs['fieldtype']
|
|
61
|
+ self.needed_fieldtypes |= set([fieldtype])
|
|
62
|
+ del(ftargs['fieldtype'])
|
|
63
|
+
|
|
64
|
+ constructor = '{ftname}.EmFieldType(**{ftargs})'.format(
|
|
65
|
+ ftname = GenericFieldType.module_name(fieldtype),
|
|
66
|
+ ftargs = ftargs,
|
|
67
|
+ )
|
|
68
|
+
|
|
69
|
+ if fieldtype == 'pk':
|
|
70
|
+ #
|
|
71
|
+ # WARNING multiple PK not supported
|
|
72
|
+ #
|
|
73
|
+ res_uid_ft = "{ %s: %s }"%(repr(fname),constructor)
|
|
74
|
+ else:
|
|
75
|
+ res_ft_l.append( '%s: %s'%(repr(fname), constructor) )
|
|
76
|
+ return (res_uid_ft, res_ft_l)
|
|
77
|
+
|
52
|
78
|
## @brief Given a Model and an EmClass instances generate python code for corresponding LeClass
|
53
|
79
|
# @param model Model : A Model instance
|
54
|
80
|
# @param emclass EmClass : An EmClass instance from model
|
|
@@ -140,6 +166,7 @@ from EditorialModel.fieldtypes import {needed_fieldtypes_list}
|
140
|
166
|
import leapi
|
141
|
167
|
import leapi.lecrud
|
142
|
168
|
import leapi.leobject
|
|
169
|
+import leapi.lerelation
|
143
|
170
|
from leapi.leclass import _LeClass
|
144
|
171
|
from leapi.letype import _LeType
|
145
|
172
|
"""
|
|
@@ -155,6 +182,8 @@ import %s
|
155
|
182
|
leobj_me_uid[comp.uid] = LeFactory.name2classname(comp.name)
|
156
|
183
|
|
157
|
184
|
#Building the fieldtypes dict of LeObject
|
|
185
|
+ (leobj_uid_fieldtype, leobj_fieldtypes) = self.concret_fieldtypes(EditorialModel.classtypes.common_fields)
|
|
186
|
+ """
|
158
|
187
|
leobj_fieldtypes = list()
|
159
|
188
|
leobj_uid_fieldtype = None
|
160
|
189
|
for fname, ftargs in EditorialModel.classtypes.common_fields.items():
|
|
@@ -171,10 +200,23 @@ import %s
|
171
|
200
|
#
|
172
|
201
|
# WARNING multiple PK not supported
|
173
|
202
|
#
|
174
|
|
- leobj_uid_fieldtype = "{ 'lodel_id': %s }"%constructor
|
|
203
|
+ leobj_uid_fieldtype = "{ %s: %s }"%(repr(fname),constructor)
|
175
|
204
|
else:
|
176
|
205
|
leobj_fieldtypes.append( '%s: %s'%(repr(fname), constructor) )
|
177
|
|
-
|
|
206
|
+ """
|
|
207
|
+ #Building the fieldtypes dict for LeRelation
|
|
208
|
+ (lerel_uid_fieldtype, lerel_fieldtypes) = self.concret_fieldtypes(EditorialModel.classtypes.relations_common_fields)
|
|
209
|
+ """
|
|
210
|
+ lerel_fieldtypes = list()
|
|
211
|
+ lerel_uid_fieldtype = None
|
|
212
|
+ for fname, ftargs in EditorialModel.classtypes.relations_common_fields.items():
|
|
213
|
+ ftargs = copy.copy(ftargs)
|
|
214
|
+ fieldtype = ftargs['fieldtype']
|
|
215
|
+ self.needed_fieldtypes |= set([fieldtype])
|
|
216
|
+ del(ftargs['fieldtype'])
|
|
217
|
+
|
|
218
|
+ constructor
|
|
219
|
+ """
|
178
|
220
|
|
179
|
221
|
result += """
|
180
|
222
|
## @brief _LeCrud concret class
|
|
@@ -190,10 +232,21 @@ class LeObject(LeCrud, leapi.leobject._LeObject):
|
190
|
232
|
_uid_fieldtype = {leo_uid_fieldtype}
|
191
|
233
|
_leo_fieldtypes = {leo_fieldtypes}
|
192
|
234
|
|
|
235
|
+## @brief _LeRelation concret class
|
|
236
|
+# @see leapi.lerelation._LeRelation
|
|
237
|
+class LeRelation(LeCrud, leapi.lerelation._LeRelation):
|
|
238
|
+ _uid_fieldtype = {lerel_uid_fieldtype}
|
|
239
|
+ _rel_fieldtypes = {lerel_fieldtypes}
|
|
240
|
+ _rel_attr_fieldtypes = dict()
|
193
|
241
|
|
194
|
|
-class LeClass(LeObject, _LeClass):
|
|
242
|
+class LeHierarch(LeRelation, leapi.lerelation._LeHierarch):
|
|
243
|
+ _rel_attr_fieldtypes = dict()
|
|
244
|
+
|
|
245
|
+class LeRel2Type(LeRelation, leapi.lerelation._LeRel2Type):
|
195
|
246
|
pass
|
196
|
247
|
|
|
248
|
+class LeClass(LeObject, _LeClass):
|
|
249
|
+ pass
|
197
|
250
|
|
198
|
251
|
class LeType(LeClass, _LeType):
|
199
|
252
|
pass
|
|
@@ -203,6 +256,8 @@ class LeType(LeClass, _LeType):
|
203
|
256
|
me_uid_l = repr(leobj_me_uid),
|
204
|
257
|
leo_uid_fieldtype = leobj_uid_fieldtype,
|
205
|
258
|
leo_fieldtypes = '{\n\t' + (',\n\t'.join(leobj_fieldtypes))+ '\n\t}',
|
|
259
|
+ lerel_fieldtypes = '{\n\t' + (',\n\t'.join(lerel_fieldtypes))+ '\n\t}',
|
|
260
|
+ lerel_uid_fieldtype = lerel_uid_fieldtype,
|
206
|
261
|
)
|
207
|
262
|
|
208
|
263
|
emclass_l = model.components(EditorialModel.classes.EmClass)
|