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

@ -167,7 +167,7 @@ class RepositoryList(ApiResource):
@require_scope(scopes.READ_REPO)
@nickname('listRepos')
@parse_args
@parse_args()
@query_param('page', 'Offset page number. (int)', type=int)
@query_param('limit', 'Limit on the number of results (int)', type=int)
@query_param('namespace', 'Filters the repositories returned to this namespace', type=str)
@ -179,24 +179,26 @@ class RepositoryList(ApiResource):
type=truthy_bool, default=False)
@query_param('popularity', 'Whether to include the repository\'s popularity metric.',
type=truthy_bool, default=False)
def get(self, args):
def get(self, parsed_args):
""" Fetch the list of repositories visible to the current user under a variety of situations.
"""
if not args['namespace'] and not args['starred'] and not args['public']:
if not parsed_args['namespace'] and not parsed_args['starred'] and not parsed_args['public']:
raise InvalidRequest('namespace, starred or public are required for this API call')
repositories, star_lookup = self._load_repositories(args['namespace'], args['public'],
args['starred'], args['limit'],
args['page'])
repositories, star_lookup = self._load_repositories(parsed_args['namespace'],
parsed_args['public'],
parsed_args['starred'],
parsed_args['limit'],
parsed_args['page'])
# Collect the IDs of the repositories found for subequent lookup of popularity
# and/or last modified.
repository_ids = [repo.id for repo in repositories]
if args['last_modified']:
if parsed_args['last_modified']:
last_modified_map = model.repository.get_when_last_modified(repository_ids)
if args['popularity']:
if parsed_args['popularity']:
action_count_map = model.repository.get_action_counts(repository_ids)
def repo_view(repo_obj):
@ -209,10 +211,10 @@ class RepositoryList(ApiResource):
repo_id = repo_obj.id
if args['last_modified']:
if parsed_args['last_modified']:
repo['last_modified'] = last_modified_map.get(repo_id)
if args['popularity']:
if parsed_args['popularity']:
repo['popularity'] = action_count_map.get(repo_id, 0)
if get_authenticated_user():