Parcourir la source

Add a class attribute to LeObject that maps EditorialModel uid with LeType and LeClass python class

Yann Weber il y a 9 ans
Parent
révision
250aa9e0ff
2 fichiers modifiés avec 10 ajouts et 14 suppressions
  1. 8
    3
      leobject/lefactory.py
  2. 2
    11
      leobject/leobject.py

+ 8
- 3
leobject/lefactory.py Voir le fichier

@@ -50,6 +50,8 @@ class LeFactory(object):
50 50
     # @return A string representing python code
51 51
     @staticmethod
52 52
     def generate_python(backend_cls, backend_args, datasource_cls, datasource_args):
53
+        model = Model(backend=backend_cls(**backend_args))
54
+
53 55
         result = ""
54 56
         result += "#-*- coding: utf-8 -*-\n"
55 57
         #Putting import directives in result
@@ -68,14 +70,17 @@ import %s\n\
68 70
 
69 71
         #Generating the code for LeObject class
70 72
         backend_constructor = '%s.%s(**%s)'%(backend_cls.__module__, backend_cls.__name__, backend_args.__repr__())
73
+        leobj_me_uid = dict()
74
+        for comp in model.components('EmType') + model.components('EmClass'):
75
+            leobj_me_uid[comp.uid] = LeFactory.name2classname(comp.name)
76
+
71 77
         result += "\n\
72 78
 class LeObject(_LeObject):\n\
73 79
     _model = Model(backend=%s)\n\
74 80
     _datasource = %s(**%s)\n\
81
+    _me_uid = %s\n\
75 82
 \n\
76
-"%(backend_constructor, datasource_cls.__name__, datasource_args.__repr__())
77
-
78
-        model = Model(backend=backend_cls(**backend_args))
83
+"%(backend_constructor, datasource_cls.__name__, datasource_args.__repr__(), leobj_me_uid.__repr__())
79 84
         
80 85
         for emclass in model.components(EditorialModel.classes.EmClass):
81 86
             cls_fields = dict()

+ 2
- 11
leobject/leobject.py Voir le fichier

@@ -13,6 +13,8 @@ class _LeObject(object):
13 13
     _model = None
14 14
     ## @brief The datasource
15 15
     _datasource = None
16
+    ## @brief maps em uid with LeType or LeClass keys are uid values are LeObject childs classes
17
+    _me_uid = dict()
16 18
 
17 19
     _query_re = None
18 20
     _query_operators = ['=', '<=', '>=', '!=', '<', '>', ' in ', ' not in ']
@@ -22,17 +24,6 @@ class _LeObject(object):
22 24
     def __init__(self, **kwargs):
23 25
         raise NotImplementedError("Abstract constructor")
24 26
 
25
-    ## @brief create a new LeObject
26
-    # @param data dict: a dictionnary of field:value to save
27
-    # @return lodel_id int: new lodel_id of the newly created LeObject
28
-    def insert(self, data):
29
-        try:
30
-            checked_data = self._check_data(data)
31
-            lodel_id = self.datasource.insert(checked_data)
32
-        except:
33
-            raise
34
-        return lodel_id
35
-
36 27
     ## @brief update an existing LeObject
37 28
     # @param lodel_id int | (int): lodel_id of the object(s) where to apply changes
38 29
     # @param data dict: dictionnary of field:value to save

Loading…
Annuler
Enregistrer