Stories can be filtered with LIKE clauses

Story title and description can now be passed to the browse API to
filter specific stories.

Change-Id: I0a25b0826615c040f1a9705ea20d246d05a04064
This commit is contained in:
Michael Krotscheck
2014-04-25 14:09:52 -07:00
parent a0b341d4e6
commit e1f4653dbd
3 changed files with 26 additions and 27 deletions

View File

@@ -101,15 +101,17 @@ class StoriesController(rest.RestController):
status_code=404)
@secure(checks.guest)
@wsme_pecan.wsexpose([Story], int, int, int, unicode)
@wsme_pecan.wsexpose([Story], int, int, int, unicode, unicode, unicode)
def get_all(self, project_id=None, marker=None, limit=None,
status=None):
status=None, title=None, description=None):
"""Retrieve definitions of all of the stories.
:param project_id: filter stories by project ID.
:param marker: The resource id where the page should begin.
:param limit: The number of stories to retrieve.
:param status: Only show stories with this particular status.
:param title: A string to filter the title by.
:param description: A string to filter the description by.
"""
# Boundary check on limit.
@@ -126,9 +128,13 @@ class StoriesController(rest.RestController):
stories = stories_api.story_get_all(marker=marker_story,
limit=limit,
project_id=project_id,
status=status)
status=status,
title=title,
description=description)
story_count = stories_api.story_get_count(project_id=project_id,
status=status)
status=status,
title=title,
description=description)
# Apply the query response headers.
response.headers['X-Limit'] = str(limit)

View File

@@ -4,7 +4,7 @@
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
@@ -71,7 +71,7 @@ def _destroy_facade_instance():
_FACADE = None
def _apply_query_filters(query, model, **kwargs):
def apply_query_filters(query, model, **kwargs):
"""Parses through a list of kwargs to determine which exist on the model,
which should be filtered as ==, and which should be filtered as LIKE
"""
@@ -141,9 +141,7 @@ def entity_get_all(kls, filter_non_public=False, marker=None, limit=None,
query = model_query(kls)
# Sanity check on input parameters
query = _apply_query_filters(query=query,
model=kls,
**kwargs)
query = apply_query_filters(query=query, model=kls, **kwargs)
# Construct the query
query = paginate_query(query=query,
@@ -170,9 +168,7 @@ def entity_get_count(kls, **kwargs):
query = model_query(kls)
# Sanity check on input parameters
query = _apply_query_filters(query=query,
model=kls,
**kwargs)
query = apply_query_filters(query=query, model=kls, **kwargs)
count = query.count()
@@ -221,7 +217,6 @@ def entity_update(kls, entity_id, values):
def entity_hard_delete(kls, entity_id):
session = get_session()
with session.begin():
query = model_query(kls, session)

View File

@@ -22,28 +22,26 @@ def story_get(story_id):
return api_base.entity_get(models.StorySummary, story_id)
def story_get_all(marker=None, limit=None, project_id=None, status=None):
def story_get_all(marker=None, limit=None, project_id=None, **kwargs):
if project_id:
return _story_get_all_in_project(marker=marker,
limit=limit,
project_id=project_id,
status=status)
**kwargs)
else:
return api_base.entity_get_all(models.StorySummary,
marker=marker, limit=limit,
status=status)
**kwargs)
def story_get_count(project_id=None, status=None):
def story_get_count(project_id=None, **kwargs):
if project_id:
return _story_get_count_in_project(project_id, status=status)
return _story_get_count_in_project(project_id, **kwargs)
else:
return api_base.entity_get_count(models.StorySummary, status=status)
return api_base.entity_get_count(models.StorySummary, **kwargs)
def _story_get_all_in_project(project_id, marker=None, limit=None, **kwargs):
# Sanity check on input parameters
kwargs = dict((k, v) for k, v in kwargs.iteritems() if v)
session = api_base.get_session()
@@ -52,9 +50,9 @@ def _story_get_all_in_project(project_id, marker=None, limit=None, **kwargs):
.distinct(True) \
.subquery('project_tasks')
query = api_base.model_query(models.StorySummary, session) \
.filter_by(**kwargs) \
.join(sub_query, models.StorySummary.id == sub_query.c.story_id)
query = api_base.model_query(models.StorySummary, session)
query = api_base.apply_query_filters(query, models.StorySummary, **kwargs)
query.join(sub_query, models.StorySummary.id == sub_query.c.story_id)
query = api_base.paginate_query(query=query,
model=models.StorySummary,
@@ -77,9 +75,9 @@ def _story_get_count_in_project(project_id, **kwargs):
.distinct(True) \
.subquery('project_tasks')
query = api_base.model_query(models.StorySummary, session) \
.filter_by(**kwargs) \
.join(sub_query, models.StorySummary.id == sub_query.c.story_id)
query = api_base.model_query(models.StorySummary, session)
query = api_base.apply_query_filters(query, models.StorySummary, **kwargs)
query.join(sub_query, models.StorySummary.id == sub_query.c.story_id)
return query.count()