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
This commit is contained in:
Adam Coldrick 2018-11-29 23:56:31 +00:00
parent 29046ff0c5
commit 75ad9b8756
2 changed files with 22 additions and 3 deletions

View File

@ -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])

View File

@ -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