Allow Teams to be filtered by project_id
Change-Id: I46b482b68b58288c183abe7446531d6686ad91c3
This commit is contained in:
parent
84518d0ccc
commit
30337674c5
@ -197,9 +197,10 @@ class TeamsController(rest.RestController):
|
||||
@decorators.db_exceptions
|
||||
@secure(checks.guest)
|
||||
@wsme_pecan.wsexpose([wmodels.Team], int, int, int, wtypes.text,
|
||||
wtypes.text, wtypes.text, wtypes.text)
|
||||
wtypes.text, int, wtypes.text, wtypes.text)
|
||||
def get(self, marker=None, offset=None, limit=None, name=None,
|
||||
description=None, sort_field='id', sort_dir='asc'):
|
||||
description=None, project_id=None, sort_field='id',
|
||||
sort_dir='asc'):
|
||||
"""Retrieve a list of teams.
|
||||
|
||||
Example::
|
||||
@ -211,6 +212,7 @@ class TeamsController(rest.RestController):
|
||||
:param limit: The number of teams to retrieve.
|
||||
:param name: A string to filter the name by.
|
||||
:param description: A string to filter the description by.
|
||||
:param project_id: The ID of a project to filter by.
|
||||
:param sort_field: The name of the field to sort on.
|
||||
:param sort_dir: Sort direction for results (asc, desc).
|
||||
"""
|
||||
@ -226,11 +228,13 @@ class TeamsController(rest.RestController):
|
||||
limit=limit,
|
||||
name=name,
|
||||
description=description,
|
||||
project_id=project_id,
|
||||
sort_field=sort_field,
|
||||
sort_dir=sort_dir)
|
||||
|
||||
team_count = teams_api.team_get_count(name=name,
|
||||
description=description)
|
||||
description=description,
|
||||
project_id=project_id)
|
||||
|
||||
# Apply the query response headers.
|
||||
if limit:
|
||||
|
@ -38,19 +38,36 @@ def team_get(team_id):
|
||||
return _entity_get(team_id)
|
||||
|
||||
|
||||
def _team_build_query(project_id=None, **kwargs):
|
||||
query = api_base.model_query(models.Team)
|
||||
|
||||
if project_id:
|
||||
query = query.join(models.Team.projects)
|
||||
query = query.filter(models.Project.id == project_id)
|
||||
|
||||
query = api_base.apply_query_filters(query=query,
|
||||
model=models.Team,
|
||||
**kwargs)
|
||||
|
||||
return query
|
||||
|
||||
|
||||
def team_get_all(marker=None, offset=None, limit=None, sort_field=None,
|
||||
sort_dir=None, **kwargs):
|
||||
return api_base.entity_get_all(models.Team,
|
||||
offset=offset,
|
||||
marker=marker,
|
||||
limit=limit,
|
||||
sort_field=sort_field,
|
||||
sort_dir=sort_dir,
|
||||
**kwargs)
|
||||
sort_dir=None, project_id=None, **kwargs):
|
||||
query = _team_build_query(project_id, **kwargs)
|
||||
query = api_base.paginate_query(query=query,
|
||||
model=models.Team,
|
||||
limit=limit,
|
||||
sort_key=sort_field,
|
||||
marker=marker,
|
||||
offset=offset,
|
||||
sort_dir=sort_dir)
|
||||
return query.all()
|
||||
|
||||
|
||||
def team_get_count(**kwargs):
|
||||
return api_base.entity_get_count(models.Team, **kwargs)
|
||||
def team_get_count(project_id=None, **kwargs):
|
||||
query = _team_build_query(project_id, **kwargs)
|
||||
return query.count()
|
||||
|
||||
|
||||
def team_create(values):
|
||||
|
Loading…
x
Reference in New Issue
Block a user