From 75ad9b87564df2b59aca0a85d56c41c390dce15b Mon Sep 17 00:00:00 2001 From: Adam Coldrick Date: Thu, 29 Nov 2018 23:56:31 +0000 Subject: [PATCH] Add a popularity measurement to tags This commit adds a popularity measurement to tags, to aid users in selecting a sensible set of tags from suggestions. Story: 2004467 Task: 28156 Change-Id: I4d4e19a8fd6058f1c8384da515687ded3bc64551 --- storyboard/api/v1/tags.py | 18 +++++++++++++++--- storyboard/api/v1/wmodels.py | 7 +++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/storyboard/api/v1/tags.py b/storyboard/api/v1/tags.py index 35833808..2eadb8e0 100644 --- a/storyboard/api/v1/tags.py +++ b/storyboard/api/v1/tags.py @@ -48,7 +48,9 @@ class TagsController(rest.RestController): tag = tags_api.tag_get_by_id(tag_id) if tag: - return wmodels.Tag.from_db_model(tag) + tag_model = wmodels.Tag.from_db_model(tag) + tag_model.set_popularity(tag) + return tag_model else: raise exc.NotFound(_("Tag %s not found") % tag_id) @@ -76,14 +78,24 @@ class TagsController(rest.RestController): limit=limit, offset=offset) - return [wmodels.Tag.from_db_model(t) for t in tags] + result = [] + for t in tags: + tag = wmodels.Tag.from_db_model(t) + tag.set_popularity(t) + result.append(tag) + return result story = stories_api.story_get( story_id, current_user=request.current_user_id) if not story: raise exc.NotFound("Story %s not found" % story_id) - return [wmodels.Tag.from_db_model(t) for t in story.tags] + result = [] + for t in story.tags: + tag = wmodels.Tag.from_db_model(t) + tag.set_popularity(t) + result.append(tag) + return result @secure(checks.authenticated) @wsme_pecan.wsexpose(wmodels.Story, int, body=[wtypes.text]) diff --git a/storyboard/api/v1/wmodels.py b/storyboard/api/v1/wmodels.py index 1e43ac8e..5c81e909 100644 --- a/storyboard/api/v1/wmodels.py +++ b/storyboard/api/v1/wmodels.py @@ -288,10 +288,17 @@ class Tag(base.APIBase): name = wtypes.text """The tag name""" + popularity = int + """The number of stories with this tag""" + @classmethod def sample(cls): return cls(name="low_hanging_fruit") + @nodoc + def set_popularity(self, tag): + self.popularity = len(tag.stories) + class Task(base.APIBase): """A Task represents an actionable work item, targeting a specific Project