Ignore:
Timestamp:
Apr 18, 2010, 4:58:22 PM (15 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, client
Children:
074fac7
Parents:
5a72e32
git-author:
Alex Dehnert <adehnert@…> (04/18/10 16:58:22)
git-committer:
Alex Dehnert <adehnert@…> (04/18/10 16:58:22)
Message:

Allow getting nodes by path relative to a base

File:
1 edited

Legend:

Unmodified
Added
Removed
  • remit/finance_core/models.py

    r5a72e32 rbc798fc  
    5656
    5757    @classmethod
    58     def get_by_path(cls, path):
    59         try:
    60             root = BudgetArea.objects.get(name=path[0], depth=1)
    61         except IndexError, e:
    62             raise KeyError(e)
    63         node = root
    64         for name in path[1:]:
     58    def get_by_path(cls, path, base=None, ):
     59        if base:
     60            node = base
     61        else:
     62            try:
     63                root = BudgetArea.objects.get(name=path[0], depth=1)
     64            except IndexError, e:
     65                raise KeyError(e)
     66            node = root
     67            path = path[1:]
     68        for name in path:
    6569            try:
    6670                node = node.get_children().filter(name=name)[0]
     
    7074
    7175    @classmethod
    72     def get_by_pathstr(cls, path):
     76    def get_by_pathstr(cls, path, base=None):
    7377        path = path.split('.')
    74         return cls.get_by_path(path)
     78        return cls.get_by_path(path, base=base, )
    7579
    7680    def pathstr(self, skip=0):
Note: See TracChangeset for help on using the changeset viewer.