Abstract out constant scores into constants

This commit is contained in:
Joseph Schorr 2017-03-10 14:06:39 -05:00
parent b5bb76cdea
commit d42ec4e585

View file

@ -18,6 +18,12 @@ from util.names import parse_robot_username
import anunidecode # Don't listen to pylint's lies. This import is required.
import math
ENTITY_SEARCH_SCORE = 1
TEAM_SEARCH_SCORE = 2
REPOSITORY_SEARCH_SCORE = 4
@resource('/v1/entities/link/<username>')
@internal_only
class LinkExternalEntity(ApiResource):
@ -179,7 +185,7 @@ def search_entity_view(username, entity, get_short_name=None):
'kind': kind,
'avatar': avatar_data,
'name': entity.username,
'score': 1,
'score': ENTITY_SEARCH_SCORE,
'href': href
}
@ -203,7 +209,7 @@ def conduct_team_search(username, query, encountered_teams, results):
'name': team.name,
'organization': search_entity_view(username, team.organization),
'avatar': avatar.get_data_for_team(team),
'score': 2,
'score': TEAM_SEARCH_SCORE,
'href': '/organization/' + team.organization.username + '/teams/' + team.name
})
@ -222,7 +228,7 @@ def conduct_admined_team_search(username, query, encountered_teams, results):
'name': team.name,
'organization': search_entity_view(username, team.organization),
'avatar': avatar.get_data_for_team(team),
'score': 2,
'score': TEAM_SEARCH_SCORE,
'href': '/organization/' + team.organization.username + '/teams/' + team.name
})
@ -238,7 +244,7 @@ def conduct_repo_search(username, query, results):
'name': repo.name,
'description': repo.description,
'is_public': model.repository.is_repository_public(repo),
'score': 4,
'score': REPOSITORY_SEARCH_SCORE,
'href': '/repository/' + repo.namespace_user.username + '/' + repo.name
})