Browse Source

EmType: do not break while adding or deleting an unknown superior

ArnAud 9 years ago
parent
commit
ed48c64ab8
1 changed files with 9 additions and 4 deletions
  1. 9
    4
      EditorialModel/types.py

+ 9
- 4
EditorialModel/types.py View File

223
     # @throw ValueError when relation_nature isn't reconized or not allowed for this type
223
     # @throw ValueError when relation_nature isn't reconized or not allowed for this type
224
     # @throw ValueError when relation_nature don't allow to link this types together
224
     # @throw ValueError when relation_nature don't allow to link this types together
225
     def add_superior(self, em_type, relation_nature):
225
     def add_superior(self, em_type, relation_nature):
226
-        #Checking that this relation is allowed by the nature of the relation
226
+        # check if relation_nature is valid for this type
227
+        if relation_nature not in EmClassType.natures(self.classtype['name']):
228
+            raise ValueError("Invalid nature for add_superior : '" + relation_nature + "'. Allowed relations for this type are " + str(EmClassType.natures(self.classtype['name'])))
229
+
230
+        if relation_nature in self.superiors_list and em_type.uid in self.superiors_list[relation_nature]:
231
+            return True
232
+
227
         att = self.classtype['hierarchy'][relation_nature]['attach']
233
         att = self.classtype['hierarchy'][relation_nature]['attach']
228
         if att == 'classtype':
234
         if att == 'classtype':
229
             if self.classtype['name'] != em_type.classtype['name']:
235
             if self.classtype['name'] != em_type.classtype['name']:
239
     # @throw TypeError when em_type isn't an EmType instance
245
     # @throw TypeError when em_type isn't an EmType instance
240
     # @throw ValueError when relation_nature isn't reconized or not allowed for this type
246
     # @throw ValueError when relation_nature isn't reconized or not allowed for this type
241
     def del_superior(self, em_type, relation_nature):
247
     def del_superior(self, em_type, relation_nature):
248
+        if relation_nature not in self.superiors_list or em_type.uid not in self.superiors_list[relation_nature]:
249
+            return True
242
         self._change_superiors_list(em_type, relation_nature, False)
250
         self._change_superiors_list(em_type, relation_nature, False)
243
 
251
 
244
     ## Apply changes to the superiors_list
252
     ## Apply changes to the superiors_list
249
         # check instance of parameters
257
         # check instance of parameters
250
         if not isinstance(em_type, EmType) or not isinstance(relation_nature, str):
258
         if not isinstance(em_type, EmType) or not isinstance(relation_nature, str):
251
             raise TypeError("Excepted <class EmType> and <class str> as em_type argument. But got : " + str(type(em_type)) + " " + str(type(relation_nature)))
259
             raise TypeError("Excepted <class EmType> and <class str> as em_type argument. But got : " + str(type(em_type)) + " " + str(type(relation_nature)))
252
-        # check if relation_nature is valid for this type
253
-        if relation_nature not in EmClassType.natures(self.classtype['name']):
254
-            raise ValueError("Invalid nature for add_superior : '" + relation_nature + "'. Allowed relations for this type are " + str(EmClassType.natures(self.classtype['name'])))
255
 
260
 
256
         try:
261
         try:
257
             if add:
262
             if add:

Loading…
Cancel
Save