|
@@ -49,23 +49,26 @@ class LeFactory(object):
|
49
|
49
|
res_ft_l = list()
|
50
|
50
|
res_uid_ft = None
|
51
|
51
|
for fname, ftargs in ft_dict.items():
|
52
|
|
- ftargs = copy.copy(ftargs)
|
53
|
|
- fieldtype = ftargs['fieldtype']
|
54
|
|
- self.needed_fieldtypes |= set([fieldtype])
|
55
|
|
- del(ftargs['fieldtype'])
|
56
|
|
-
|
57
|
|
- constructor = '{ftname}.EmFieldType(**{ftargs})'.format(
|
58
|
|
- ftname = GenericFieldType.module_name(fieldtype),
|
59
|
|
- ftargs = ftargs,
|
60
|
|
- )
|
61
|
|
-
|
62
|
|
- if fieldtype == 'pk':
|
63
|
|
- #
|
64
|
|
- # WARNING multiple PK not supported
|
65
|
|
- #
|
66
|
|
- res_uid_ft = "{ %s: %s }"%(repr(fname),constructor)
|
|
52
|
+ if ftargs is None:
|
|
53
|
+ res_ft_l.append('%s: None' % repr(fname))
|
67
|
54
|
else:
|
68
|
|
- res_ft_l.append( '%s: %s'%(repr(fname), constructor) )
|
|
55
|
+ ftargs = copy.copy(ftargs)
|
|
56
|
+ fieldtype = ftargs['fieldtype']
|
|
57
|
+ self.needed_fieldtypes |= set([fieldtype])
|
|
58
|
+ del(ftargs['fieldtype'])
|
|
59
|
+
|
|
60
|
+ constructor = '{ftname}.EmFieldType(**{ftargs})'.format(
|
|
61
|
+ ftname = GenericFieldType.module_name(fieldtype),
|
|
62
|
+ ftargs = ftargs,
|
|
63
|
+ )
|
|
64
|
+
|
|
65
|
+ if fieldtype == 'pk':
|
|
66
|
+ #
|
|
67
|
+ # WARNING multiple PK not supported
|
|
68
|
+ #
|
|
69
|
+ res_uid_ft = "{ %s: %s }"%(repr(fname),constructor)
|
|
70
|
+ else:
|
|
71
|
+ res_ft_l.append( '%s: %s'%(repr(fname), constructor) )
|
69
|
72
|
return (res_uid_ft, res_ft_l)
|
70
|
73
|
|
71
|
74
|
## @brief Given a Model generate concrete instances of LeRel2Type classes to represent relations
|
|
@@ -112,23 +115,30 @@ class {classname}(LeRel2Type):
|
112
|
115
|
for rfield in [ f for f in emclass.fields() if f.fieldtype == 'rel2type']:
|
113
|
116
|
fti = rfield.fieldtype_instance()
|
114
|
117
|
cls_linked_types[rfield.name] = _LeCrud.name2classname(model.component(fti.rel_to_type_id).name)
|
|
118
|
+ ml_fieldnames = dict()
|
115
|
119
|
# Populating fieldtype attr
|
116
|
120
|
for field in emclass.fields(relational = False):
|
117
|
|
- self.needed_fieldtypes |= set([field.fieldtype])
|
118
|
|
- cls_fields[field.name] = LeFactory.fieldtype_construct_from_field(field)
|
119
|
|
- fti = field.fieldtype_instance()
|
|
121
|
+ if field.name not in EditorialModel.classtypes.common_fields.keys() or not ( hasattr(field, 'immutable') and field.immutable):
|
|
122
|
+ self.needed_fieldtypes |= set([field.fieldtype])
|
|
123
|
+ cls_fields[field.name] = LeFactory.fieldtype_construct_from_field(field)
|
|
124
|
+ fti = field.fieldtype_instance()
|
|
125
|
+ if field.string.get() == '':
|
|
126
|
+ field.string.set_default(field.name)
|
|
127
|
+ ml_fieldnames[field.name] = field.string.__str__()
|
120
|
128
|
|
121
|
129
|
return """
|
122
|
130
|
#Initialisation of {name} class attributes
|
123
|
131
|
{name}._fieldtypes = {ftypes}
|
|
132
|
+{name}.ml_fields_strings = {fieldnames}
|
124
|
133
|
{name}._linked_types = {ltypes}
|
125
|
134
|
{name}._classtype = {classtype}
|
126
|
135
|
""".format(
|
127
|
136
|
name = _LeCrud.name2classname(emclass.name),
|
128
|
137
|
ftypes = "{" + (','.join(['\n %s: %s' % (repr(f), v) for f, v in cls_fields.items()])) + "\n}",
|
|
138
|
+ fieldnames = '{' + (','.join(['\n %s: MlString(%s)' % (repr(f), v) for f,v in ml_fieldnames.items()])) + '\n}',
|
129
|
139
|
ltypes = "{" + (','.join(['\n %s: %s' % (repr(f), v) for f, v in cls_linked_types.items()])) + "\n}",
|
130
|
140
|
|
131
|
|
- classtype = repr(emclass.classtype)
|
|
141
|
+ classtype = repr(emclass.classtype),
|
132
|
142
|
)
|
133
|
143
|
|
134
|
144
|
## @brief Given a Model and an EmType instances generate python code for corresponding LeType
|
|
@@ -177,6 +187,7 @@ class {classname}(LeRel2Type):
|
177
|
187
|
import EditorialModel
|
178
|
188
|
from EditorialModel import fieldtypes
|
179
|
189
|
from EditorialModel.fieldtypes import {needed_fieldtypes_list}
|
|
190
|
+from Lodel.utils.mlstring import MlString
|
180
|
191
|
|
181
|
192
|
import leapi
|
182
|
193
|
import leapi.lecrud
|
|
@@ -197,9 +208,15 @@ import %s
|
197
|
208
|
leobj_me_uid[comp.uid] = _LeCrud.name2classname(comp.name)
|
198
|
209
|
|
199
|
210
|
#Building the fieldtypes dict of LeObject
|
200
|
|
- (leobj_uid_fieldtype, leobj_fieldtypes) = self.concret_fieldtypes(EditorialModel.classtypes.common_fields)
|
|
211
|
+ common_fieldtypes = dict()
|
|
212
|
+ for ftname, ftdef in EditorialModel.classtypes.common_fields.items():
|
|
213
|
+ common_fieldtypes[ftname] = ftdef if 'immutable' in ftdef and ftdef['immutable'] else None
|
|
214
|
+ (leobj_uid_fieldtype, leobj_fieldtypes) = self.concret_fieldtypes(common_fieldtypes)
|
201
|
215
|
#Building the fieldtypes dict for LeRelation
|
202
|
|
- (lerel_uid_fieldtype, lerel_fieldtypes) = self.concret_fieldtypes(EditorialModel.classtypes.relations_common_fields)
|
|
216
|
+ common_fieldtypes = dict()
|
|
217
|
+ for ftname, ftdef in EditorialModel.classtypes.relations_common_fields.items():
|
|
218
|
+ common_fieldtypes[ftname] = ftdef if 'immutable' in ftdef and ftdef['immutable'] else None
|
|
219
|
+ (lerel_uid_fieldtype, lerel_fieldtypes) = self.concret_fieldtypes(common_fieldtypes)
|
203
|
220
|
|
204
|
221
|
result += """
|
205
|
222
|
## @brief _LeCrud concret class
|
|
@@ -256,28 +273,36 @@ class LeType(LeClass, _LeType):
|
256
|
273
|
|
257
|
274
|
#LeClass child classes definition
|
258
|
275
|
for emclass in emclass_l:
|
|
276
|
+ if emclass.string.get() == '':
|
|
277
|
+ emclass.string.set_default(emclass.name)
|
259
|
278
|
result += """
|
260
|
279
|
## @brief EmClass {name} LeClass child class
|
261
|
280
|
# @see leapi.leclass.LeClass
|
262
|
281
|
class {name}(LeClass, LeObject):
|
263
|
282
|
_class_id = {uid}
|
|
283
|
+ ml_string = MlString({name_translations})
|
264
|
284
|
|
265
|
285
|
""".format(
|
266
|
286
|
name=_LeCrud.name2classname(emclass.name),
|
267
|
|
- uid=emclass.uid
|
|
287
|
+ uid=emclass.uid,
|
|
288
|
+ name_translations = repr(emclass.string.__str__()),
|
268
|
289
|
)
|
269
|
290
|
#LeType child classes definition
|
270
|
291
|
for emtype in emtype_l:
|
|
292
|
+ if emtype.string.get() == '':
|
|
293
|
+ emtype.string.set_default(emtype.name)
|
271
|
294
|
result += """
|
272
|
295
|
## @brief EmType {name} LeType child class
|
273
|
296
|
# @see leobject::letype::LeType
|
274
|
297
|
class {name}(LeType, {leclass}):
|
275
|
298
|
_type_id = {uid}
|
|
299
|
+ ml_string = MlString({name_translations})
|
276
|
300
|
|
277
|
301
|
""".format(
|
278
|
302
|
name=_LeCrud.name2classname(emtype.name),
|
279
|
303
|
leclass=_LeCrud.name2classname(emtype.em_class.name),
|
280
|
|
- uid=emtype.uid
|
|
304
|
+ uid=emtype.uid,
|
|
305
|
+ name_translations = repr(emtype.string.__str__()),
|
281
|
306
|
)
|
282
|
307
|
|
283
|
308
|
#Generating concret class of LeRel2Type
|