Browse Source

Implements _LeObject.hierarchy_del() and LeType.del_superior()

Yann Weber 9 years ago
parent
commit
64c2a865df
3 changed files with 33 additions and 2 deletions
  1. 2
    1
      leobject/datasources/dummy.py
  2. 24
    1
      leobject/leobject.py
  3. 7
    0
      leobject/letype.py

+ 2
- 1
leobject/datasources/dummy.py View File

@@ -54,7 +54,7 @@ class DummyDatasource(object):
54 54
     
55 55
     ## @brief Add a superior to a LeObject
56 56
     # @note in the MySQL version the method will have a depth=None argument to allow reccursive calls to add all the path to the root with corresponding depth
57
-    # @param lesup LeType : superior LeType child class instance
57
+    # @param lesup LeType | LeRoot : superior LeType child class instance or @ref
58 58
     # @param lesub LeType : subordinate LeType child class instance
59 59
     # @param nature str : A relation nature @ref EditorialModel.classtypesa
60 60
     # @param rank int : The rank of this relation
@@ -85,6 +85,7 @@ class DummyDatasource(object):
85 85
     def get_subordinates(self, lesup, nature):
86 86
         pass
87 87
 
88
+
88 89
     ## @brief Make a relation between 2 LeType
89 90
     # @note rel2type relations. Superior is the LeType from the EmClass and subordinate the LeType for the EmType
90 91
     # @param lesup LeType : LeType child class instance that is from the EmClass containing the rel2type field

+ 24
- 1
leobject/leobject.py View File

@@ -264,7 +264,30 @@ class _LeObject(object):
264 264
                 raise RuntimeError("Unable to delete the previous superior")
265 265
 
266 266
         return self._datasource.add_superior(lesup, lesub, nature, rank)
267
-        
267
+    
268
+    ## @brief Delete a hierarchy link between two LeObject
269
+    # @param lesup LeType | LeRoot : LeType child class or hierarchy root
270
+    # @param lesub LeType : LeType child class
271
+    # @param nature str : The nature of the relation @ref EditorialModel.classtypes
272
+    # @return True if deletion done successfully
273
+    # @throw ValueError when bad arguments given
274
+    @classmethod
275
+    def hierarchy_del(cls, lesup, lesub, nature):
276
+        if nature not in EditorialModel.classtypes.EmClassType.natures(lesub._classtype):
277
+            raise ValueError("Invalid nature '%s' for %s"%(nature, lesup.__class__.__name__))
278
+
279
+        if not cls.leo_is_root(lesup):
280
+            if nature not in EditorialModel.classtypes.EmClassType.natures(lesup._classtype):
281
+                raise ValueError("Invalid nature '%s' for %s"%(nature, lesup.__class__.__name__))
282
+            if lesup.__class__ not in lesub._superiors[nature]:
283
+                raise ValueError("%s is not a valid superior for %s"%(lesup.__class__, lesub.__class__))
284
+        superiors = cls.hierarchy_get(lesub, nature, leo_is_sup = False)
285
+        res = True
286
+        for _lesup in superiors:
287
+            if not cls._datasource.del_superior(_lesup, lesub, nature):
288
+                #How to handler this ?
289
+                res = False
290
+        return res
268 291
 
269 292
     ## @brief Prepare a field_list
270 293
     # @param field_list list : List of string representing fields

+ 7
- 0
leobject/letype.py View File

@@ -167,6 +167,13 @@ class LeType(object):
167 167
     # @return The relation ID or False if fails
168 168
     def add_superior(self, leo, nature, rank = 'last', replace_if_exists = False):
169 169
         return leobject.lefactory.LeFactory.leobj_from_name('LeObject').hierarchy_add(leo, self, nature, rank, replace_if_exists)
170
+
171
+    ## @brief Delete a superior given a relation's natue
172
+    # @param leo LeType | LeRoot : The superior to delete
173
+    # @param nature str : The nature of the relation @ref EditorialModel.classtypes
174
+    # @return True if deletion is a success
175
+    def del_superior(self, leo, nature):
176
+        return leobject.lefactory.leobj_from_name('LeObject').hierarchy_del(leo, self, nature)
170 177
         
171 178
     
172 179
     ## @brief Delete a LeType from the datasource

Loading…
Cancel
Save