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
             m.update(bytes(data, 'utf-8'))
52
             m.update(bytes(data, 'utf-8'))
53
         return int.from_bytes(m.digest(), byteorder='big')
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
 # @brief Handles editorial model objects classes
77
 # @brief Handles editorial model objects classes
57
 #@ingroup lodel2_em
78
 #@ingroup lodel2_em
114
                 data_handler='LeobjectSubclassIdentifier',
135
                 data_handler='LeobjectSubclassIdentifier',
115
                 internal=True,
136
                 internal=True,
116
                 group=group)
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
     # @brief Property that represent a dict of all fields (the EmField defined in this class and all its parents)
144
     # @brief Property that represent a dict of all fields (the EmField defined in this class and all its parents)
119
     # @todo use Settings.editorialmodel.groups to determine wich fields should be returned
145
     # @todo use Settings.editorialmodel.groups to determine wich fields should be returned
248
         else:
274
         else:
249
             group.add_components([self])
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
     # @brief Returns data_handler_name attribute
282
     # @brief Returns data_handler_name attribute
252
     def get_data_handler_name(self):
283
     def get_data_handler_name(self):
253
         return copy.copy(self.data_handler_name)
284
         return copy.copy(self.data_handler_name)
299
                     raise ValueError("EmGroup expected in depends argument but %s found" % grp)
330
                     raise ValueError("EmGroup expected in depends argument but %s found" % grp)
300
                 self.add_dependencie(grp)
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
     # @brief Returns EmGroup dependencie
338
     # @brief Returns EmGroup dependencie
303
     # @param recursive bool : if True return all dependencies and their dependencies
339
     # @param recursive bool : if True return all dependencies and their dependencies
304
     # @return a dict of EmGroup identified by uid
340
     # @return a dict of EmGroup identified by uid

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

174
                 logger.debug("Set group '%s' as active" % agrp)
174
                 logger.debug("Set group '%s' as active" % agrp)
175
                 grp = self.__groups[agrp]
175
                 grp = self.__groups[agrp]
176
                 self.__active_groups[grp.uid] = grp
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
                     self.__active_classes[acls.uid] = acls
178
                     self.__active_classes[acls.uid] = acls
179
             if len(self.__active_groups) == 0:
179
             if len(self.__active_groups) == 0:
180
                 raise RuntimeError("No groups activated, abording...")
180
                 raise RuntimeError("No groups activated, abording...")

Loading…
Cancel
Save