Browse Source

Bugfix about pickle translator & LodelContext

The is_instance test on classes loaded from a pickle file is not
relevant :
lodel.editorial_model.components.EmClass != lodelsites.__loader__.editorial_model.components.EmClass
Yann Weber 7 years ago
parent
commit
ee6db4f895
2 changed files with 37 additions and 1 deletions
  1. 36
    0
      lodel/editorial_model/components.py
  2. 1
    1
      lodel/editorial_model/model.py

+ 36
- 0
lodel/editorial_model/components.py View File

@@ -52,6 +52,27 @@ class EmComponent(MlNamedObject):
52 52
             m.update(bytes(data, 'utf-8'))
53 53
         return int.from_bytes(m.digest(), byteorder='big')
54 54
 
55
+    ##@brief Type test method
56
+    #@return bool
57
+    #@note Those methodes are implemented because we use picklefile to store
58
+    #EM -> the classes that are stored are not the same than the one loaded
59
+    #by LodelContext : lodel.editorial_model.components.EmClass !=
60
+    #lodelsites.INSTANCE_NAME.editorial_model.components.EmClass
61
+    @classmethod
62
+    def is_emclass(cls):
63
+        return False
64
+
65
+    ##@brief Type test method
66
+    #@return bool
67
+    @classmethod
68
+    def is_emgroup(cls):
69
+        return False
70
+
71
+    ##@brief Type test method
72
+    #@return bool
73
+    @classmethod
74
+    def is_emfield(cls):
75
+        return False
55 76
 
56 77
 # @brief Handles editorial model objects classes
57 78
 #@ingroup lodel2_em
@@ -114,6 +135,11 @@ class EmClass(EmComponent):
114 135
                 data_handler='LeobjectSubclassIdentifier',
115 136
                 internal=True,
116 137
                 group=group)
138
+    
139
+    ##@todo delete me when support for pickle translator is dropped
140
+    @classmethod
141
+    def is_emclass(cls):
142
+        return True
117 143
 
118 144
     # @brief Property that represent a dict of all fields (the EmField defined in this class and all its parents)
119 145
     # @todo use Settings.editorialmodel.groups to determine wich fields should be returned
@@ -248,6 +274,11 @@ class EmField(EmComponent):
248 274
         else:
249 275
             group.add_components([self])
250 276
 
277
+    ##@todo delete me when support for pickle translator is dropped
278
+    @classmethod
279
+    def is_emfield(cls):
280
+        return True
281
+
251 282
     # @brief Returns data_handler_name attribute
252 283
     def get_data_handler_name(self):
253 284
         return copy.copy(self.data_handler_name)
@@ -299,6 +330,11 @@ class EmGroup(MlNamedObject):
299 330
                     raise ValueError("EmGroup expected in depends argument but %s found" % grp)
300 331
                 self.add_dependencie(grp)
301 332
 
333
+    ##@todo delete me when support for pickle translator is dropped
334
+    @classmethod
335
+    def is_emgroup(cls):
336
+        return True
337
+
302 338
     # @brief Returns EmGroup dependencie
303 339
     # @param recursive bool : if True return all dependencies and their dependencies
304 340
     # @return a dict of EmGroup identified by uid

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

@@ -174,7 +174,7 @@ context this is a REALLY BAD idea !")
174 174
                 logger.debug("Set group '%s' as active" % agrp)
175 175
                 grp = self.__groups[agrp]
176 176
                 self.__active_groups[grp.uid] = grp
177
-                for acls in [cls for cls in grp.components() if isinstance(cls, EmClass)]:
177
+                for acls in [cls for cls in grp.components() if cls.is_emclass()]:
178 178
                     self.__active_classes[acls.uid] = acls
179 179
             if len(self.__active_groups) == 0:
180 180
                 raise RuntimeError("No groups activated, abording...")

Loading…
Cancel
Save