|
@@ -11,15 +11,6 @@ def dyncode_from_em(model):
|
11
|
11
|
|
12
|
12
|
# Generation of LeObject child classes code
|
13
|
13
|
cls_code, modules, bootstrap_instr = generate_classes(model)
|
14
|
|
- # Completing bootstrap with back_reference bootstraping
|
15
|
|
- for leoname in [ LeObject.name2objname(emcls.uid) for emcls in get_classes(model) ]:
|
16
|
|
- bootstrap_instr += """
|
17
|
|
-{leobject}._backref_init()
|
18
|
|
-""".format(leobject = leoname)
|
19
|
|
- bootstrap_instr += """
|
20
|
|
-del(LeObject._set__fields)
|
21
|
|
-del(LeObject._backref_init)
|
22
|
|
-"""
|
23
|
14
|
|
24
|
15
|
# Header
|
25
|
16
|
imports = """from lodel.leapi.leobject import LeObject
|
|
@@ -59,10 +50,20 @@ def data_handler_constructor(emfield):
|
59
|
50
|
#dh_module_name = DataHandler.module_name(emfield.data_handler_name)+'.DataHandler'
|
60
|
51
|
get_handler_class_instr = 'DataField.from_name(%s)' % repr(emfield.data_handler_name)
|
61
|
52
|
options = []
|
|
53
|
+ for name, val in emfield.data_handler_options.items():
|
|
54
|
+ if name == 'back_reference' and isinstance(val, tuple):
|
|
55
|
+ options.append('{optname}: ({leo_name}, {fieldname})'.format(
|
|
56
|
+ optname = repr(name),
|
|
57
|
+ leo_name = LeObject.name2objname(val[0]),
|
|
58
|
+ fieldname = repr(val[1]),))
|
|
59
|
+ else:
|
|
60
|
+ options.append(repr(name)+': '+forge_optval(val))
|
62
|
61
|
|
63
|
|
- return ('%s(**{' % get_handler_class_instr)+(', '.join([repr(name)+': '+forge_optval(val) for name, val in emfield.data_handler_options.items()])) + '})'
|
|
62
|
+ return '{handler_instr}(**{{ {options} }})'.format(
|
|
63
|
+ handler_instr = get_handler_class_instr,
|
|
64
|
+ options = ', '.join(options))
|
64
|
65
|
|
65
|
|
-
|
|
66
|
+## @brief Return a python repr of option values
|
66
|
67
|
def forge_optval(optval):
|
67
|
68
|
if isinstance(optval, dict):
|
68
|
69
|
return '{' + (', '.join( [ '%s: %s' % (repr(name), forge_optval(val)) for name, val in optval.items()])) + '}'
|
|
@@ -119,7 +120,6 @@ class {clsname}({parents}):
|
119
|
120
|
res += em_cls_code
|
120
|
121
|
# Dyncode bootstrap instructions
|
121
|
122
|
bootstrap += """{classname}._set__fields({fields})
|
122
|
|
-#del({classname}._set__fields)
|
123
|
123
|
""".format(
|
124
|
124
|
classname = LeObject.name2objname(em_class.uid),
|
125
|
125
|
fields = '{' + (', '.join(['\n\t%s: %s' % (repr(emfield.uid),data_handler_constructor(emfield)) for emfield in em_class.fields()])) + '}',
|