Skip to content

Commit

Permalink
Add default ordering users in user directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafal Kowalski committed Jun 9, 2019
1 parent b17efb5 commit 4bdab39
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions app/dashboard/views.py
Expand Up @@ -774,8 +774,12 @@ def users_fetch(request):
network = 'mainnet'
else:
network = 'rinkeby'

coworkers_profile = []
if current_user:
coworkers_profile = [
feedback.receiver_profile for feedback in current_user.profile.feedbacks_sent.all()
if not feedback.receiver_profile.hide_profile
]
profile_list = Profile.objects.prefetch_related(
'fulfilled', 'leaderboard_ranks', 'feedbacks_got'
).annotate(
Expand All @@ -787,7 +791,8 @@ def users_fetch(request):
).exclude(hide_profile=True).order_by(
'-previous_worked_count',
order_by,
'-actions_count'
'-actions_count',
'feedbacks_got__rating'
)
else:
profile_list = Profile.objects.prefetch_related(
Expand Down Expand Up @@ -834,8 +839,9 @@ def users_fetch(request):
fulfilled__bounty__github_url__icontains=organisation
).distinct()

profile_list = profile_list.exclude(id__in=[coworker_profile.id for coworker_profile in coworkers_profile])
params = dict()
all_pages = Paginator(profile_list, limit)
all_pages = Paginator(list(coworkers_profile) + list(profile_list), limit)
all_users = []
for user in all_pages.page(page):
profile_json = {}
Expand Down Expand Up @@ -872,6 +878,7 @@ def users_fetch(request):
profile_json['blog'] = user_data['blog']

all_users.append(profile_json)

# dumping and loading the json here quickly passes serialization issues - definitely can be a better solution
params['data'] = json.loads(json.dumps(all_users, default=str))
params['has_next'] = all_pages.page(page).has_next()
Expand Down

0 comments on commit 4bdab39

Please sign in to comment.