Refactor how parsed_args are passed to methods

This commit is contained in:
Jake Moshenko 2016-01-26 16:27:36 -05:00
parent daab1b3964
commit 018bf8c5ad
13 changed files with 142 additions and 137 deletions

View file

@ -19,18 +19,18 @@ import math
class EntitySearch(ApiResource):
""" Resource for searching entities. """
@path_param('prefix', 'The prefix of the entities being looked up')
@parse_args
@parse_args()
@query_param('namespace', 'Namespace to use when querying for org entities.', type=str,
default='')
@query_param('includeTeams', 'Whether to include team names.', type=truthy_bool, default=False)
@query_param('includeOrgs', 'Whether to include orgs names.', type=truthy_bool, default=False)
@nickname('getMatchingEntities')
def get(self, args, prefix):
def get(self, prefix, parsed_args):
""" Get a list of entities that match the specified prefix. """
teams = []
org_data = []
namespace_name = args['namespace']
namespace_name = parsed_args['namespace']
robot_namespace = None
organization = None
@ -42,11 +42,11 @@ class EntitySearch(ApiResource):
if permission.can():
robot_namespace = namespace_name
if args['includeTeams']:
if parsed_args['includeTeams']:
teams = model.team.get_matching_teams(prefix, organization)
if args['includeOrgs'] and AdministerOrganizationPermission(namespace_name) \
and namespace_name.startswith(prefix):
if (parsed_args['includeOrgs'] and AdministerOrganizationPermission(namespace_name) and
namespace_name.startswith(prefix)):
org_data = [{
'name': namespace_name,
'kind': 'org',
@ -217,13 +217,13 @@ def conduct_robot_search(username, query, results):
@resource('/v1/find/all')
class ConductSearch(ApiResource):
""" Resource for finding users, repositories, teams, etc. """
@parse_args
@parse_args()
@query_param('query', 'The search query.', type=str, default='')
@require_scope(scopes.READ_REPO)
@nickname('conductSearch')
def get(self, args):
def get(self, parsed_args):
""" Get a list of entities and resources that match the specified query. """
query = args['query']
query = parsed_args['query']
if not query:
return {'results': []}