PEP8 fixes.
This commit is contained in:
parent
427b745f2f
commit
6a038bb24e
7 changed files with 56 additions and 45 deletions
|
@ -41,7 +41,7 @@ def create_confirm_email_code(user):
|
|||
|
||||
def confirm_user_email(code):
|
||||
code = EmailConfirmation.get(EmailConfirmation.code == code,
|
||||
EmailConfirmation.email_confirm == True)
|
||||
EmailConfirmation.email_confirm is True)
|
||||
|
||||
user = code.user
|
||||
user.verified = True
|
||||
|
@ -96,14 +96,15 @@ def get_token(code):
|
|||
return AccessToken.get(AccessToken.code == code)
|
||||
|
||||
|
||||
def get_visible_repositories(username=None, include_public=True, limit=None, sort=False):
|
||||
def get_visible_repositories(username=None, include_public=True, limit=None,
|
||||
sort=False):
|
||||
if not username and not include_public:
|
||||
return []
|
||||
|
||||
query = Repository.select().distinct().join(Visibility)
|
||||
or_clauses = []
|
||||
if include_public:
|
||||
or_clauses.append((Visibility.name == 'public'));
|
||||
or_clauses.append((Visibility.name == 'public'))
|
||||
|
||||
if username:
|
||||
with_perms = query.switch(Repository).join(RepositoryPermission,
|
||||
|
@ -123,6 +124,7 @@ def get_visible_repositories(username=None, include_public=True, limit=None, sor
|
|||
|
||||
return query
|
||||
|
||||
|
||||
def get_matching_repositories(repo_term, username=None):
|
||||
namespace_term = repo_term
|
||||
name_term = repo_term
|
||||
|
|
|
@ -102,6 +102,7 @@ def create_repo_api():
|
|||
@app.route('/api/find/repository', methods=['GET'])
|
||||
def match_repos_api():
|
||||
prefix = request.args.get('query', '')
|
||||
|
||||
def repo_view(repo):
|
||||
return {
|
||||
'namespace': repo.namespace,
|
||||
|
@ -109,7 +110,10 @@ def match_repos_api():
|
|||
'description': repo.description
|
||||
}
|
||||
|
||||
username = current_user.db_user.username if current_user.is_authenticated() else None
|
||||
username = None
|
||||
if current_user.is_authenticated():
|
||||
username = current_user.db_user.username
|
||||
|
||||
matching = model.get_matching_repositories(prefix, username)
|
||||
response = {
|
||||
'repositories': [repo_view(repo) for repo in matching]
|
||||
|
@ -141,10 +145,14 @@ def list_repos_api():
|
|||
include_private = include_private == 'true'
|
||||
sort = sort == 'true'
|
||||
|
||||
username = current_user.db_user.username if current_user.is_authenticated() and include_private else None
|
||||
repos = [repo_view(repo)
|
||||
for repo in model.get_visible_repositories(
|
||||
username, limit = limit, include_public = include_public, sort = sort)]
|
||||
username = None
|
||||
if current_user.is_authenticated() and include_private:
|
||||
username = current_user.db_user.username
|
||||
|
||||
repo_query = model.get_visible_repositories(username, limit=limit,
|
||||
include_public=include_public,
|
||||
sort=sort)
|
||||
repos = [repo_view(repo) for repo in repo_query]
|
||||
response = {
|
||||
'repositories': repos
|
||||
}
|
||||
|
@ -170,7 +178,8 @@ def update_repo_api(namespace, repository):
|
|||
abort(404)
|
||||
|
||||
|
||||
@app.route('/api/repository/<path:repository>/changevisibility', methods=['POST'])
|
||||
@app.route('/api/repository/<path:repository>/changevisibility',
|
||||
methods=['POST'])
|
||||
@api_login_required
|
||||
@parse_repository_name
|
||||
def change_repo_visibility_api(namespace, repository):
|
||||
|
@ -422,4 +431,4 @@ def get_subscription():
|
|||
return jsonify({
|
||||
'plan': 'free',
|
||||
'usedPrivateRepos': private_repos,
|
||||
});
|
||||
})
|
||||
|
|
|
@ -184,8 +184,8 @@ def put_image_checksum(namespace, repository, image_id):
|
|||
@set_cache_headers
|
||||
def get_image_json(namespace, repository, image_id, headers):
|
||||
permission = ReadRepositoryPermission(namespace, repository)
|
||||
if (not permission.can() and not
|
||||
model.repository_is_public(namespace, repository)):
|
||||
if not permission.can() and not model.repository_is_public(namespace,
|
||||
repository):
|
||||
abort(403)
|
||||
|
||||
try:
|
||||
|
@ -214,8 +214,8 @@ def get_image_json(namespace, repository, image_id, headers):
|
|||
@set_cache_headers
|
||||
def get_image_ancestry(namespace, repository, image_id, headers):
|
||||
permission = ReadRepositoryPermission(namespace, repository)
|
||||
if (not permission.can() and not
|
||||
model.repository_is_public(namespace, repository)):
|
||||
if not permission.can() and not model.repository_is_public(namespace,
|
||||
repository):
|
||||
abort(403)
|
||||
|
||||
try:
|
||||
|
|
|
@ -60,7 +60,7 @@ def common_login(db_user):
|
|||
identity=Identity(db_user.username, 'username'))
|
||||
return True
|
||||
else:
|
||||
logger.debug('User could not be logged in, inactive?.');
|
||||
logger.debug('User could not be logged in, inactive?.')
|
||||
return False
|
||||
|
||||
|
||||
|
|
Reference in a new issue