# HG changeset patch # User Marcin Kuzminski # Date 2011-06-16 23:00:19 # Node ID 7e221629a3e50e0b1ce7441ba63c2b4808e61f79 # Parent 4fd86e3deccf00a644857dc5ebe18d4cb44bf06c #209 Added recursive count on repositories to calculate all repos within all nested groups diff --git a/rhodecode/model/db.py b/rhodecode/model/db.py --- a/rhodecode/model/db.py +++ b/rhodecode/model/db.py @@ -468,7 +468,7 @@ class Group(Base): @property def parents(self): - parents_limit = 5 + parents_recursion_limit = 5 groups = [] if self.parent_group is None: return groups @@ -481,15 +481,18 @@ class Group(Base): cur_gr = cur_gr.parent_group if gr is None: break - if cnt == parents_limit: + if cnt == parents_recursion_limit: # this will prevent accidental infinit loops log.error('group nested more than %s' % - parents_limit) + parents_recursion_limit) break groups.insert(0, gr) return groups + @property + def children(self): + return Session.query(Group).filter(Group.parent_group == self) @property def full_path(self): @@ -500,6 +503,19 @@ class Group(Base): def repositories(self): return Session.query(Repository).filter(Repository.group == self) + @property + def repositories_recursive_count(self): + cnt = self.repositories.count() + + def children_count(group): + cnt = 0 + for child in group.children: + cnt += child.repositories.count() + cnt += children_count(child) + return cnt + + return cnt + children_count(self) + class Permission(Base): __tablename__ = 'permissions' __table_args__ = {'extend_existing':True}