Skip to content

Commit

Permalink
a few bugfixes for the last commit to allow us to view leaderboards f…
Browse files Browse the repository at this point in the history
…or any time cadence
  • Loading branch information
owocki committed Jul 20, 2019
1 parent b710cdb commit d02a905
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/assets/v2/js/pages/leaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ $(document).ready(function() {
$('#key').change(function() {
const val = $(this).val();

document.location.href = `/leaderboard/${val}`;
document.location.href = `/leaderboard/${val}` + '?cadence=' + $('#cadence').val() + '&keyword=' + $('#tech-keyword').val();
});


Expand Down
39 changes: 23 additions & 16 deletions app/marketing/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,32 +673,37 @@ def leaderboard(request, key=''):
cadences = ['all', 'weekly', 'monthly', 'quarterly', 'yearly']

keyword_search = request.GET.get('keyword', '')
keyword_search = '' if keyword_search == 'all' else keyword_search
limit = request.GET.get('limit', 25)
cadence = request.GET.get('cadence', 'quarterly')

# backwards compatibility fix for old inbound links
for ele in cadences:
key = key.replace(f"{ele}_", '')

titles = {
f'{cadence}_payers': _('Top Funders'),
f'{cadence}_earners': _('Top Coders'),
f'{cadence}_orgs': _('Top Orgs'),
f'{cadence}_tokens': _('Top Tokens'),
f'{cadence}_keywords': _('Top Keywords'),
f'{cadence}_kudos': _('Top Kudos'),
f'{cadence}_cities': _('Top Cities'),
f'{cadence}_countries': _('Top Countries'),
f'{cadence}_continents': _('Top Continents'),
f'payers': _('Top Funders'),
f'earners': _('Top Coders'),
f'orgs': _('Top Orgs'),
f'tokens': _('Top Tokens'),
f'keywords': _('Top Keywords'),
f'kudos': _('Top Kudos'),
f'cities': _('Top Cities'),
f'countries': _('Top Countries'),
f'continents': _('Top Continents'),
}

if not key:
key = f'{cadence}_earners'

key = f'earners'

if key not in titles.keys():
raise Http404

title = titles[key]
which_leaderboard = f"{cadence}_{key}"
ranks = LeaderboardRank.objects.filter(active=True, leaderboard=which_leaderboard)
if keyword_search:
ranks = LeaderboardRank.objects.filter(active=True, leaderboard=key, tech_keywords__icontains=keyword_search)
else:
ranks = LeaderboardRank.objects.filter(active=True, leaderboard=key)
ranks = ranks.filter(tech_keywords__icontains=keyword_search)

amount = ranks.values_list('amount').annotate(Max('amount')).order_by('-amount')
items = ranks.order_by('-amount')
Expand All @@ -721,15 +726,17 @@ def leaderboard(request, key=''):
profile_keys = ['_tokens', '_keywords', '_cities', '_countries', '_continents']
is_linked_to_profile = any(sub in key for sub in profile_keys)

cadence_ui = cadence if cadence != 'all' else 'All-Time'
page_title = f'{cadence_ui.title()} {keyword_search.title()} Leaderboard: {title.title()}'
context = {
'items': items[0:limit],
'nav': 'home',
'titles': titles,
'cadence': cadence,
'selected': title,
'is_linked_to_profile': is_linked_to_profile,
'title': f'{keyword_search} Leaderboard: {title}',
'card_title': f'{keyword_search} Leaderboard: {title}',
'title': page_title,
'card_title': page_title,
'card_desc': f'See the most valued members in the Gitcoin community recently . {top_earners}',
'action_past_tense': 'Transacted' if 'submitted' in key else 'bountied',
'amount_max': amount_max,
Expand Down
2 changes: 1 addition & 1 deletion app/retail/templates/leaderboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ <h6 class="pt-3 pb-2 text-center">
<!-- RESULTS TITLE & FILTER -->

<div class="col-12 my-auto col-lg-6 text-center text-md-left">
<h1 class="font-header font-weight-semibold mb-lg-0">{{cadence|title}} {{ title }} </h1>
<h1 class="font-header font-weight-semibold mb-lg-0">{{title}}</h1>
</div>
<div class="col-12 col-sm-6 col-lg-3 mx-auto my-2 my-md-0 text-center text-sm-right text-lg-left">
</div>
Expand Down

0 comments on commit d02a905

Please sign in to comment.