Skip to content

Commit

Permalink
Merge pull request #4475 from SaptakS/user-directory/default-sort
Browse files Browse the repository at this point in the history
Sorts user directory by previously worked and leaderboard
  • Loading branch information
octavioamu authored May 29, 2019
2 parents 50b5b81 + 1fec164 commit 88e4c03
Showing 1 changed file with 28 additions and 10 deletions.
38 changes: 28 additions & 10 deletions app/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,27 +757,45 @@ def users_fetch(request):
skills = request.GET.get('skills', '')
limit = int(request.GET.get('limit', 10))
page = int(request.GET.get('page', 1))
order_by = request.GET.get('order_by', '-actions_count')
order_by = request.GET.get('order_by', 'leaderboard_ranks__rank')
bounties_completed = request.GET.get('bounties_completed', '').strip().split(',')
leaderboard_rank = request.GET.get('leaderboard_rank', '').strip().split(',')
rating = int(request.GET.get('rating', '0'))
organisation = request.GET.get('organisation', '')

user_id = request.GET.get('user', None)
if user_id:
profile = Profile.objects.get(id=int(user_id))
current_user = User.objects.get(id=int(user_id))
else:
profile = request.user.profile if hasattr(request, 'user') and request.user.is_authenticated and hasattr(request.user, 'profile') else None
current_user = request.user if hasattr(request, 'user') and request.user.is_authenticated else None

context = {}
if not settings.DEBUG:
network = 'mainnet'
else:
network = 'rinkeby'

profile_list = Profile.objects.prefetch_related(
'fulfilled', 'leaderboard_ranks', 'feedbacks_got'
).exclude(hide_profile=True).order_by(order_by)
if current_user:
profile_list = Profile.objects.prefetch_related(
'fulfilled', 'leaderboard_ranks', 'feedbacks_got'
).annotate(
previous_worked_count=Count('fulfilled', filter=Q(
fulfilled__bounty__network=network,
fulfilled__accepted=True,
fulfilled__bounty__bounty_owner_github_username__iexact=current_user.profile.handle
))
).exclude(hide_profile=True).order_by(
'-previous_worked_count',
order_by,
'-actions_count'
)
else:
profile_list = Profile.objects.prefetch_related(
'fulfilled', 'leaderboard_ranks', 'feedbacks_got'
).exclude(hide_profile=True).order_by(
order_by,
'-actions_count'
)

if q:
profile_list = profile_list.filter(Q(handle__icontains=q) | Q(keywords__icontains=q))
Expand Down Expand Up @@ -812,7 +830,7 @@ def users_fetch(request):
if organisation:
profile_list = profile_list.filter(
fulfilled__bounty__network=network,
fulfilled__bounty__accepted=True,
fulfilled__accepted=True,
fulfilled__bounty__github_url__icontains=organisation
).distinct()

Expand All @@ -822,12 +840,12 @@ def users_fetch(request):
for user in all_pages.page(page):
profile_json = {}
previously_worked_with = 0
if profile:
if current_user:
previously_worked_with = BountyFulfillment.objects.filter(
bounty__bounty_owner_github_username__iexact=profile.handle,
bounty__bounty_owner_github_username__iexact=current_user.profile.handle,
fulfiller_github_username__iexact=user.handle,
bounty__network=network,
bounty__accepted=True
accepted=True
).count()
count_work_completed = Activity.objects.filter(profile=user, activity_type='work_done').count()
count_work_in_progress = Activity.objects.filter(profile=user, activity_type='start_work').count()
Expand Down

0 comments on commit 88e4c03

Please sign in to comment.