Get the new context-sensitive new menu working

This commit is contained in:
Joseph Schorr 2015-04-07 18:33:43 -04:00
parent 40a6892a49
commit d09f2f6e22
13 changed files with 461 additions and 193 deletions

View file

@ -679,34 +679,27 @@ def get_user_or_org_by_customer_id(customer_id):
except User.DoesNotExist:
return None
def get_matching_user_entities(entity_prefix, user):
def get_matching_entities(entity_prefix):
matching_user_orgs = ((User.username ** (entity_prefix + '%')) & (User.robot == False))
if user is not None:
matching_robots = ((User.username ** (user.username + '+%' + entity_prefix + '%')) &
(User.robot == True))
else:
matching_robots = False
matching_robots = ((User.username ** ('%+%' + entity_prefix + '%')) & (User.robot == True))
query = (User.select()
.where(matching_user_orgs | matching_robots)
.limit(10))
.where(matching_user_orgs | matching_robots))
return query
def get_matching_user_teams(team_prefix, user):
def get_matching_user_teams(team_prefix, user, limit=10):
query = (Team.select()
.join(User)
.switch(Team)
.join(TeamMember)
.where(TeamMember.user == user, Team.name ** (team_prefix + '%'))
.distinct(Team.id)
.limit(10))
.limit(limit))
return query
def get_matching_admined_teams(team_prefix, user):
def get_matching_admined_teams(team_prefix, user, limit=10):
admined_orgs = (get_user_organizations(user.username)
.switch(Team)
.join(TeamRole)
@ -718,7 +711,7 @@ def get_matching_admined_teams(team_prefix, user):
.join(TeamMember)
.where(Team.name ** (team_prefix + '%'), Team.organization << (admined_orgs))
.distinct(Team.id)
.limit(10))
.limit(limit))
return query
@ -968,7 +961,7 @@ def _get_public_repo_visibility():
return _public_repo_visibility_cache
def get_matching_repositories(repo_term, username=None):
def get_matching_repositories(repo_term, username=None, limit=10):
namespace_term = repo_term
name_term = repo_term
@ -986,7 +979,7 @@ def get_matching_repositories(repo_term, username=None):
search_clauses = (Repository.name ** ('%' + name_term + '%') &
Namespace.username ** ('%' + namespace_term + '%'))
return visible.where(search_clauses).limit(10)
return visible.where(search_clauses).limit(limit)
def get_repository_pull_counts(repositories):
repo_pull = LogEntryKind.get(name = 'pull_repo')