Allow tags to be filtered by name

This allows users to browse the list of all tags by part of the tag
name. This can be used by the UI to provide suggestions of tags to
search for.

Change-Id: If13b29d050abd66428c6787121d6b61b357bc9fb
This commit is contained in:
Adam Coldrick 2016-06-17 11:36:17 +01:00
parent 176001d685
commit 92d83cd680
2 changed files with 16 additions and 6 deletions

View File

@ -49,17 +49,25 @@ class TagsController(rest.RestController):
raise exc.NotFound(_("Tag %s not found") % tag_id)
@secure(checks.guest)
@wsme_pecan.wsexpose([wmodels.Tag], int, int, int)
def get_all(self, story_id=None, marker=None, limit=None):
@wsme_pecan.wsexpose([wmodels.Tag], int, wtypes.text, int, int, int)
def get_all(self, story_id=None, name=None, marker=None, limit=None,
offset=None):
"""Retrieve all tags for a given Story. If no story_id is provided
all tags will be returned.
all tags will be returned, optionally filtered by name.
:param story_id: Filter tags by story ID.
:param name: Filter tags by name.
:param marker: ID of the tag to start results from.
:param limit: Maximum number of results per page.
:param offset: Number of results to offset page by.
"""
if not story_id:
marker_tag = tags_api.tag_get_by_id(marker)
tags = tags_api.tag_get_all(marker_tag, limit)
tags = tags_api.tag_get_all(name=name,
marker=marker_tag,
limit=limit,
offset=offset)
return [wmodels.Tag.from_db_model(t) for t in tags]

View File

@ -39,10 +39,12 @@ def tag_get_by_name(name, session=None):
return query.first()
def tag_get_all(marker=None, limit=None):
def tag_get_all(name=None, marker=None, limit=None, offset=None):
return api_base.entity_get_all(models.StoryTag,
name=name,
marker=marker,
limit=limit)
limit=limit,
offset=offset)
def tag_get_count(**kwargs):