Mercurial > kallithea
comparison rhodecode/model/db.py @ 1538:27be8f94c207 beta
implements #226 repo groups available by path
fixes #259 Groups with the same name but with different parent group
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Mon, 10 Oct 2011 02:09:52 +0200 |
parents | 04027bdb876c |
children | bd604cf75c5a |
comparison
equal
deleted
inserted
replaced
1537:c307c920f94c | 1538:27be8f94c207 |
---|---|
124 def query(cls): | 124 def query(cls): |
125 return Session.query(cls) | 125 return Session.query(cls) |
126 | 126 |
127 @classmethod | 127 @classmethod |
128 def get(cls, id_): | 128 def get(cls, id_): |
129 return Session.query(cls).get(id_) | 129 if id_: |
130 return Session.query(cls).get(id_) | |
130 | 131 |
131 @classmethod | 132 @classmethod |
132 def delete(cls, id_): | 133 def delete(cls, id_): |
133 obj = Session.query(cls).get(id_) | 134 obj = Session.query(cls).get(id_) |
134 Session.delete(obj) | 135 Session.delete(obj) |
718 self.group_name) | 719 self.group_name) |
719 | 720 |
720 @classmethod | 721 @classmethod |
721 def url_sep(cls): | 722 def url_sep(cls): |
722 return '/' | 723 return '/' |
724 | |
725 @classmethod | |
726 def get_by_group_name(cls, group_name): | |
727 return cls.query().filter(cls.group_name == group_name).scalar() | |
723 | 728 |
724 @property | 729 @property |
725 def parents(self): | 730 def parents(self): |
726 parents_recursion_limit = 5 | 731 parents_recursion_limit = 5 |
727 groups = [] | 732 groups = [] |
748 @property | 753 @property |
749 def children(self): | 754 def children(self): |
750 return Session.query(Group).filter(Group.parent_group == self) | 755 return Session.query(Group).filter(Group.parent_group == self) |
751 | 756 |
752 @property | 757 @property |
758 def name(self): | |
759 return self.group_name.split(Group.url_sep())[-1] | |
760 | |
761 @property | |
753 def full_path(self): | 762 def full_path(self): |
754 return Group.url_sep().join([g.group_name for g in self.parents] + | 763 return self.group_name |
755 [self.group_name]) | 764 |
765 @property | |
766 def full_path_splitted(self): | |
767 return self.group_name.split(Group.url_sep()) | |
756 | 768 |
757 @property | 769 @property |
758 def repositories(self): | 770 def repositories(self): |
759 return Session.query(Repository).filter(Repository.group == self) | 771 return Session.query(Repository).filter(Repository.group == self) |
760 | 772 |
768 cnt += child.repositories.count() | 780 cnt += child.repositories.count() |
769 cnt += children_count(child) | 781 cnt += children_count(child) |
770 return cnt | 782 return cnt |
771 | 783 |
772 return cnt + children_count(self) | 784 return cnt + children_count(self) |
785 | |
786 | |
787 def get_new_name(self, group_name): | |
788 """ | |
789 returns new full group name based on parent and new name | |
790 | |
791 :param group_name: | |
792 """ | |
793 path_prefix = self.parent_group.full_path_splitted if self.parent_group else [] | |
794 return Group.url_sep().join(path_prefix + [group_name]) | |
795 | |
773 | 796 |
774 class Permission(Base, BaseModel): | 797 class Permission(Base, BaseModel): |
775 __tablename__ = 'permissions' | 798 __tablename__ = 'permissions' |
776 __table_args__ = {'extend_existing':True} | 799 __table_args__ = {'extend_existing':True} |
777 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) | 800 permission_id = Column("permission_id", Integer(), nullable=False, unique=True, default=None, primary_key=True) |