Explorar el Código

Introducing a datasource attribute by em_class

Yann Weber hace 8 años
padre
commit
a7c69629e7

BIN
examples/em_test.pickle Ver fichero


+ 1
- 1
install/conf.d/datasources.ini Ver fichero

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

+ 3
- 1
lodel/editorial_model/components.py Ver fichero

@@ -53,10 +53,12 @@ class EmClass(EmComponent):
53 53
     # @param pure_abstract bool : if True the EmClass will not be represented in leapi dyncode
54 54
     # @param parents list: parent EmClass list or uid list
55 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 58
         super().__init__(uid, display_name, help_text, group)
58 59
         self.abstract = bool(abstract)
59 60
         self.pure_abstract = bool(pure_abstract)
61
+        self.datasource = datasource
60 62
         if self.pure_abstract:
61 63
             self.abtract = True
62 64
         if parents is not None:

+ 7
- 0
lodel/leapi/lefactory.py Ver fichero

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

+ 2
- 0
lodel/leapi/leobject.py Ver fichero

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

BIN
tests/editorial_model.pickle Ver fichero


+ 1
- 1
tests/tests_conf.d/lodel2.ini Ver fichero

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

Loading…
Cancelar
Guardar