|
a/Allura/allura/model/project.py |
|
b/Allura/allura/model/project.py |
|
... |
|
... |
5 |
import pkg_resources
|
5 |
import pkg_resources
|
6 |
from webob import exc
|
6 |
from webob import exc
|
7 |
from pymongo import bson
|
7 |
from pymongo import bson
|
8 |
|
8 |
|
9 |
from ming import schema as S
|
9 |
from ming import schema as S
|
|
|
10 |
from ming.utils import LazyProperty
|
10 |
from ming.orm import ThreadLocalORMSession
|
11 |
from ming.orm import ThreadLocalORMSession
|
11 |
from ming.orm.base import mapper, session, state
|
12 |
from ming.orm.base import mapper, session, state
|
12 |
from ming.orm.mapped_class import MappedClass
|
13 |
from ming.orm.mapped_class import MappedClass
|
13 |
from ming.orm.property import FieldProperty, RelationProperty, ForeignIdProperty
|
14 |
from ming.orm.property import FieldProperty, RelationProperty, ForeignIdProperty
|
14 |
|
15 |
|
|
... |
|
... |
203 |
|
204 |
|
204 |
@property
|
205 |
@property
|
205 |
def parent_project(self):
|
206 |
def parent_project(self):
|
206 |
if self.is_root: return None
|
207 |
if self.is_root: return None
|
207 |
return self.query.get(_id=self.parent_id)
|
208 |
return self.query.get(_id=self.parent_id)
|
|
|
209 |
|
|
|
210 |
@LazyProperty
|
|
|
211 |
def root_project(self):
|
|
|
212 |
if self.is_root: return self
|
|
|
213 |
return self.parent_project.root_project
|
|
|
214 |
|
|
|
215 |
@LazyProperty
|
|
|
216 |
def project_hierarchy(self):
|
|
|
217 |
if not self.is_root:
|
|
|
218 |
return self.root_project.project_hierarchy
|
|
|
219 |
projects = set([self])
|
|
|
220 |
while True:
|
|
|
221 |
new_projects = set(
|
|
|
222 |
self.query.find(dict(parent_id={'$in':[p._id for p in projects]})))
|
|
|
223 |
new_projects.update(projects)
|
|
|
224 |
if new_projects == projects: break
|
|
|
225 |
projects = new_projects
|
|
|
226 |
return projects
|
208 |
|
227 |
|
209 |
@property
|
228 |
@property
|
210 |
def category(self):
|
229 |
def category(self):
|
211 |
return ProjectCategory.query.find(dict(_id=self.category_id)).first()
|
230 |
return ProjectCategory.query.find(dict(_id=self.category_id)).first()
|
212 |
|
231 |
|