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:
parent
29046ff0c5
commit
75ad9b8756
|
@ -48,7 +48,9 @@ class TagsController(rest.RestController):
|
||||||
tag = tags_api.tag_get_by_id(tag_id)
|
tag = tags_api.tag_get_by_id(tag_id)
|
||||||
|
|
||||||
if tag:
|
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:
|
else:
|
||||||
raise exc.NotFound(_("Tag %s not found") % tag_id)
|
raise exc.NotFound(_("Tag %s not found") % tag_id)
|
||||||
|
|
||||||
|
@ -76,14 +78,24 @@ class TagsController(rest.RestController):
|
||||||
limit=limit,
|
limit=limit,
|
||||||
offset=offset)
|
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 = stories_api.story_get(
|
||||||
story_id, current_user=request.current_user_id)
|
story_id, current_user=request.current_user_id)
|
||||||
if not story:
|
if not story:
|
||||||
raise exc.NotFound("Story %s not found" % story_id)
|
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)
|
@secure(checks.authenticated)
|
||||||
@wsme_pecan.wsexpose(wmodels.Story, int, body=[wtypes.text])
|
@wsme_pecan.wsexpose(wmodels.Story, int, body=[wtypes.text])
|
||||||
|
|
|
@ -288,10 +288,17 @@ class Tag(base.APIBase):
|
||||||
name = wtypes.text
|
name = wtypes.text
|
||||||
"""The tag name"""
|
"""The tag name"""
|
||||||
|
|
||||||
|
popularity = int
|
||||||
|
"""The number of stories with this tag"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def sample(cls):
|
def sample(cls):
|
||||||
return cls(name="low_hanging_fruit")
|
return cls(name="low_hanging_fruit")
|
||||||
|
|
||||||
|
@nodoc
|
||||||
|
def set_popularity(self, tag):
|
||||||
|
self.popularity = len(tag.stories)
|
||||||
|
|
||||||
|
|
||||||
class Task(base.APIBase):
|
class Task(base.APIBase):
|
||||||
"""A Task represents an actionable work item, targeting a specific Project
|
"""A Task represents an actionable work item, targeting a specific Project
|
||||||
|
|
Loading…
Reference in New Issue