~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/routing/__init__.py

  • Committer: William Grant
  • Date: 2009-07-05 05:01:42 UTC
  • mto: (1294.4.2 ui-the-third)
  • mto: This revision was merged to the branch mainline in revision 1353.
  • Revision ID: grantw@unimelb.edu.au-20090705050142-7b9bglse6sku030i
Add Router.get_ancestors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
220
220
                names += subpath
221
221
        return os.path.join('/', *names)
222
222
 
 
223
    def get_ancestors(self, obj):
 
224
        """Get a sequence of an object's ancestors.
 
225
 
 
226
        Traverse up the tree of reverse routes, taking note of all ancestors.
 
227
        """
 
228
 
 
229
        # Attempt to get all the way to the top. Each reverse route should
 
230
        # return a (parent, pathsegments) tuple. We don't care about
 
231
        # pathsegments in this case.
 
232
        objs = [obj]
 
233
 
 
234
        # None represents the root.
 
235
        while objs[0] is not ROOT:
 
236
            route = self.rmap.get(type(objs[0]))
 
237
            if route is None:
 
238
                raise NoPath(obj, objs[0])
 
239
            objs.insert(0, route(objs[0])[0])
 
240
 
 
241
        return objs[1:]
223
242
 
224
243
    def _traverse(self, todo, obj, viewset):
225
244
        """Populate the object stack given a list of path segments.