Mercurial > kallithea
comparison rhodecode/model/db.py @ 1385:7e221629a3e5 beta
#209 Added recursive count on repositories to calculate all repos within all nested groups
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Thu, 16 Jun 2011 23:00:19 +0200 |
parents | a1ab3e9c7e82 |
children | 2029c17cc6c6 |
comparison
equal
deleted
inserted
replaced
1384:4fd86e3deccf | 1385:7e221629a3e5 |
---|---|
466 def url_sep(cls): | 466 def url_sep(cls): |
467 return '/' | 467 return '/' |
468 | 468 |
469 @property | 469 @property |
470 def parents(self): | 470 def parents(self): |
471 parents_limit = 5 | 471 parents_recursion_limit = 5 |
472 groups = [] | 472 groups = [] |
473 if self.parent_group is None: | 473 if self.parent_group is None: |
474 return groups | 474 return groups |
475 cur_gr = self.parent_group | 475 cur_gr = self.parent_group |
476 groups.insert(0, cur_gr) | 476 groups.insert(0, cur_gr) |
479 cnt += 1 | 479 cnt += 1 |
480 gr = getattr(cur_gr, 'parent_group', None) | 480 gr = getattr(cur_gr, 'parent_group', None) |
481 cur_gr = cur_gr.parent_group | 481 cur_gr = cur_gr.parent_group |
482 if gr is None: | 482 if gr is None: |
483 break | 483 break |
484 if cnt == parents_limit: | 484 if cnt == parents_recursion_limit: |
485 # this will prevent accidental infinit loops | 485 # this will prevent accidental infinit loops |
486 log.error('group nested more than %s' % | 486 log.error('group nested more than %s' % |
487 parents_limit) | 487 parents_recursion_limit) |
488 break | 488 break |
489 | 489 |
490 groups.insert(0, gr) | 490 groups.insert(0, gr) |
491 return groups | 491 return groups |
492 | 492 |
493 @property | |
494 def children(self): | |
495 return Session.query(Group).filter(Group.parent_group == self) | |
493 | 496 |
494 @property | 497 @property |
495 def full_path(self): | 498 def full_path(self): |
496 return Group.url_sep().join([g.group_name for g in self.parents] + | 499 return Group.url_sep().join([g.group_name for g in self.parents] + |
497 [self.group_name]) | 500 [self.group_name]) |
498 | 501 |
499 @property | 502 @property |
500 def repositories(self): | 503 def repositories(self): |
501 return Session.query(Repository).filter(Repository.group == self) | 504 return Session.query(Repository).filter(Repository.group == self) |
505 | |
506 @property | |
507 def repositories_recursive_count(self): | |
508 cnt = self.repositories.count() | |
509 | |
510 def children_count(group): | |
511 cnt = 0 | |
512 for child in group.children: | |
513 cnt += child.repositories.count() | |
514 cnt += children_count(child) | |
515 return cnt | |
516 | |
517 return cnt + children_count(self) | |
502 | 518 |
503 class Permission(Base): | 519 class Permission(Base): |
504 __tablename__ = 'permissions' | 520 __tablename__ = 'permissions' |
505 __table_args__ = {'extend_existing':True} | 521 __table_args__ = {'extend_existing':True} |
506 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | 522 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |