Browse Source

Introducing a datasource attribute by em_class

Yann Weber 8 years ago
parent
commit
a7c69629e7

BIN
examples/em_test.pickle View File


+ 1
- 1
install/conf.d/datasources.ini View File

1
-[lodel2.datasources.main]
1
+[lodel2.datasources.default]
2
 identifier = dummy.example
2
 identifier = dummy.example
3
 
3
 
4
 [lodel2.datasource.dummy.example]
4
 [lodel2.datasource.dummy.example]

+ 3
- 1
lodel/editorial_model/components.py View File

53
     # @param pure_abstract bool : if True the EmClass will not be represented in leapi dyncode
53
     # @param pure_abstract bool : if True the EmClass will not be represented in leapi dyncode
54
     # @param parents list: parent EmClass list or uid list
54
     # @param parents list: parent EmClass list or uid list
55
     # @param help_text MlString|str|dict : help_text
55
     # @param help_text MlString|str|dict : help_text
56
-    def __init__(self, uid, display_name = None, help_text = None, abstract = False, parents = None, group = None, pure_abstract = False):
56
+    # @param datasource str : The datasource name ( see @ref lodel2_datasources )
57
+    def __init__(self, uid, display_name = None, help_text = None, abstract = False, parents = None, group = None, pure_abstract = False, datasource = 'default'):
57
         super().__init__(uid, display_name, help_text, group)
58
         super().__init__(uid, display_name, help_text, group)
58
         self.abstract = bool(abstract)
59
         self.abstract = bool(abstract)
59
         self.pure_abstract = bool(pure_abstract)
60
         self.pure_abstract = bool(pure_abstract)
61
+        self.datasource = datasource
60
         if self.pure_abstract:
62
         if self.pure_abstract:
61
             self.abtract = True
63
             self.abtract = True
62
         if parents is not None:
64
         if parents is not None:

+ 7
- 0
lodel/leapi/lefactory.py View File

19
     for module in modules:
19
     for module in modules:
20
         imports += "import %s\n" % module
20
         imports += "import %s\n" % module
21
     
21
     
22
+    class_list = [ LeObject.name2objname(cls.uid) for cls in get_classes(model) ]
23
+
22
     # formating all components of output
24
     # formating all components of output
23
     res_code = """#-*- coding: utf-8 -*-
25
     res_code = """#-*- coding: utf-8 -*-
24
 {imports}
26
 {imports}
25
 {classes}
27
 {classes}
26
 {bootstrap_instr}
28
 {bootstrap_instr}
29
+dynclasses = {class_list}
27
 """.format(
30
 """.format(
28
             imports = imports,
31
             imports = imports,
29
             classes = cls_code,
32
             classes = cls_code,
30
             bootstrap_instr = bootstrap_instr,
33
             bootstrap_instr = bootstrap_instr,
34
+            class_list = '[' + (', '.join([cls for cls in class_list]))+']',
31
     )
35
     )
32
     return res_code
36
     return res_code
33
 
37
 
103
                parents.append(LeObject.name2objname(parent.uid))
107
                parents.append(LeObject.name2objname(parent.uid))
104
         else:
108
         else:
105
             parents.append('LeObject')
109
             parents.append('LeObject')
110
+        datasource_name = em_class.datasource
106
         
111
         
107
         # Dynamic code generation for LeObject childs classes
112
         # Dynamic code generation for LeObject childs classes
108
         em_cls_code = """
113
         em_cls_code = """
110
     _abstract = {abstract}
115
     _abstract = {abstract}
111
     _fields = None
116
     _fields = None
112
     _uid = {uid_list}
117
     _uid = {uid_list}
118
+    _datasource = {datasource_name}
113
 
119
 
114
 """.format(
120
 """.format(
115
     clsname = LeObject.name2objname(em_class.uid),
121
     clsname = LeObject.name2objname(em_class.uid),
116
     parents = ', '.join(parents),
122
     parents = ', '.join(parents),
117
     abstract = 'True' if em_class.abstract else 'False',
123
     abstract = 'True' if em_class.abstract else 'False',
118
     uid_list = repr(uid),
124
     uid_list = repr(uid),
125
+    datasource_name = repr(datasource_name),
119
 )
126
 )
120
         res += em_cls_code
127
         res += em_cls_code
121
         # Dyncode bootstrap instructions
128
         # Dyncode bootstrap instructions

+ 2
- 0
lodel/leapi/leobject.py View File

71
     _fields = None
71
     _fields = None
72
     ##@brief A tuple of fieldname (or a uniq fieldname) representing uid
72
     ##@brief A tuple of fieldname (or a uniq fieldname) representing uid
73
     _uid = None 
73
     _uid = None 
74
+    ##@brief The datasource name ( see @ref lodel2_datasources )
75
+    _datasource = None
74
 
76
 
75
     ##@brief Construct an object representing an Editorial component
77
     ##@brief Construct an object representing an Editorial component
76
     # @note Can be considered as EmClass instance
78
     # @note Can be considered as EmClass instance

BIN
tests/editorial_model.pickle View File


+ 1
- 1
tests/tests_conf.d/lodel2.ini View File

15
 dyncode = leapi_dyncode.py
15
 dyncode = leapi_dyncode.py
16
 editormode = True
16
 editormode = True
17
 
17
 
18
-[lodel2.datasources.main]
18
+[lodel2.datasources.default]
19
 identifier = dummy.example
19
 identifier = dummy.example
20
 
20
 
21
 [lodel2.datasource.dummy.example]
21
 [lodel2.datasource.dummy.example]

Loading…
Cancel
Save