Browse Source

Implements _LeObject.hierarchy_get() method

Yann Weber 9 years ago
parent
commit
3503537b0d
2 changed files with 20 additions and 3 deletions
  1. 2
    2
      leobject/datasources/dummy.py
  2. 18
    1
      leobject/leobject.py

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

@@ -75,14 +75,14 @@ class DummyDatasource(object):
75 75
     # @param lesub LeType : subordinate LeType child class instance
76 76
     # @param nature str : A relation nature @ref EditorialModel.classtypes
77 77
     # @return A list of LeType ordered by depth (the first is the direct superior)
78
-    def get_superiors(self, lesub, nature = None):
78
+    def get_superiors(self, lesub, nature):
79 79
         pass
80 80
 
81 81
     ## @brief Fetch the list of the subordinates given a nature
82 82
     # @param lesup LeType : superior LeType child class instance
83 83
     # @param nature str : A relation nature @ref EditorialModel.classtypes
84 84
     # @return A list of LeType that are subordinates of lesup in a "nature" relation
85
-    def get_subordinates(self, lesup, nature):
85
+    def get_subordinates(self, lesup, nature = None):
86 86
         pass
87 87
 
88 88
 

+ 18
- 1
leobject/leobject.py View File

@@ -288,7 +288,24 @@ class _LeObject(object):
288 288
                 #How to handler this ?
289 289
                 res = False
290 290
         return res
291
-
291
+    
292
+    ## @brief Fetch neighbour in hierarchy relation
293
+    # @param leo LeType | LeRoot : We want the neighbour of this LeObject (can be the root)
294
+    # @param nature str : @ref EditorialModel.classtypes
295
+    # @param leo_is_sup bool : if True leo is the superior and we want to fetch the subordinates else its the oposite
296
+    # @return A list of LeObject ordered by depth if leo_is_sup, else a list of subordinates
297
+    @classmethod
298
+    def hierarchy_get(cls, leo, nature, leo_is_sup = True):
299
+        #Checking arguments
300
+        if not (nature is None) and not cls.is_root(leo):
301
+            if nature not in EditorialModel.classtypes.EmClassType.natures(leo._classtype):
302
+                raise ValueError("Invalid nature '%s' for %s"%(nature, lesup.__class__.__name__))
303
+        
304
+        if leo_is_sup:
305
+            return cls._datasource.get_subordinates(leo, nature)
306
+        else:
307
+            return cls._datasource.get_superior(leo, nature)
308
+    
292 309
     ## @brief Prepare a field_list
293 310
     # @param field_list list : List of string representing fields
294 311
     # @param letype LeType : LeType child class

Loading…
Cancel
Save