Browse Source

Bugfixes on EmGroups handling

Yann Weber 8 years ago
parent
commit
91fff4ca1c
4 changed files with 25 additions and 11 deletions
  1. 3
    0
      em_test.py
  2. BIN
      examples/em_test.pickle
  3. 21
    10
      lodel/editorial_model/components.py
  4. 1
    1
      lodel/editorial_model/model.py

+ 3
- 0
em_test.py View File

@@ -87,6 +87,7 @@ person.new_field(   'firstname',
87 87
                         'fre': 'Prénom',
88 88
                     },
89 89
                     data_handler = 'varchar',
90
+                    group = base_group,
90 91
 )
91 92
 person.new_field(   'lastname',
92 93
                     display_name = {
@@ -94,6 +95,7 @@ person.new_field(   'lastname',
94 95
                         'fre': 'Nom de famille',
95 96
                     },
96 97
                     data_handler = 'varchar',
98
+                    group = base_group,
97 99
 )
98 100
 person.new_field(   'fullname',
99 101
                     display_name = {
@@ -115,6 +117,7 @@ person.new_field(   'alias',
115 117
                     allowed_classes = [person],
116 118
                     default = None,
117 119
                     nullable = True,
120
+                    group = base_group,
118 121
 )
119 122
 
120 123
 

BIN
examples/em_test.pickle View File


+ 21
- 10
lodel/editorial_model/components.py View File

@@ -7,6 +7,7 @@ import hashlib
7 7
 
8 8
 from lodel.utils.mlstring import MlString
9 9
 
10
+from lodel.settings import Settings
10 11
 from lodel.editorial_model.exceptions import *
11 12
 from lodel.leapi.leobject import CLASS_ID_FIELDNAME
12 13
 
@@ -84,6 +85,12 @@ class EmClass(EmComponent):
84 85
         ##@brief Stores EmFields instances indexed by field uid
85 86
         self.__fields = dict() 
86 87
         
88
+        self.group = group
89
+        if group is None:
90
+            warnings.warn("NO GROUP FOR EMCLASS %s" % uid)
91
+        else:
92
+            group.add_components([self])
93
+    
87 94
         #Adding common field
88 95
         if not self.abstract:
89 96
             self.new_field(
@@ -95,10 +102,9 @@ class EmClass(EmComponent):
95 102
                     'eng': "Allow to create instance of the good class when\
96 103
  fetching arbitrary datas from DB"},
97 104
                 data_handler = 'LeobjectSubclassIdentifier',
98
-                internal = True)
99
-        if group is not None:
100
-            group.add_components([self])
101
-    
105
+                internal = True,
106
+                group = group)
107
+
102 108
     ##@brief Property that represent a dict of all fields (the EmField defined in this class and all its parents)
103 109
     # @todo use Settings.editorialmodel.groups to determine wich fields should be returned
104 110
     @property
@@ -141,12 +147,13 @@ class EmClass(EmComponent):
141 147
     
142 148
     ##@brief Keep in __fields only fields contained in active groups
143 149
     def _set_active_fields(self, active_groups):
144
-        active_fields = []
145
-        for grp_name, agrp in active_groups.items():
146
-            active_fields += [ emc for emc in agrp.components()
147
-                if isinstance(emc, EmField)]
148
-        self.__fields = { fname:fdh for fname, fdh in self.__fields.items()
149
-            if fdh in active_fields }
150
+        if not Settings.editorialmodel.editormode:
151
+            active_fields = []
152
+            for grp_name, agrp in active_groups.items():
153
+                active_fields += [ emc for emc in agrp.components()
154
+                    if isinstance(emc, EmField)]
155
+            self.__fields = { fname:fdh for fname, fdh in self.__fields.items()
156
+                if fdh in active_fields }
150 157
 
151 158
     ##@brief Add a field to the EmClass
152 159
     # @param emfield EmField : an EmField instance
@@ -222,6 +229,10 @@ class EmField(EmComponent):
222 229
         self.data_handler_options = handler_kwargs
223 230
         ##@brief Stores the emclass that contains this field (set by EmClass.add_field() method)
224 231
         self._emclass = None
232
+        if group is None:
233
+            warnings.warn("NO GROUP FOR FIELD %s" % uid)
234
+        else:
235
+            group.add_components([self])
225 236
 
226 237
     ##@brief Returns data_handler_name attribute
227 238
     def get_data_handler_name(self):

+ 1
- 1
lodel/editorial_model/model.py View File

@@ -142,7 +142,7 @@ class EditorialModel(object):
142 142
                 logger.debug("Set group '%s' as active" % agrp)
143 143
                 grp = self.__groups[agrp]
144 144
                 self.__active_groups[grp.uid] = grp
145
-                for acls in grp.components():
145
+                for acls in [cls for cls in grp.components() if isinstance(cls, EmClass)]:
146 146
                     self.__active_classes[acls.uid] = acls
147 147
             if len(self.__active_groups) == 0:
148 148
                 raise RuntimeError("No groups activated, abording...")

Loading…
Cancel
Save