Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[bug 1032823] Add Locale selector for top contributors.

commit c9ca13f8151db160ad33a97963de1a5b7f874013 1 parent c7a7a3e
ricky rosario rlr authored
3  kitsune/community/static/less/select.less
@@ -27,7 +27,8 @@
27 27 margin-bottom: .2rem;
28 28 min-width: 120px;
29 29 padding: .6rem;
30   - width: auto;
  30 + text-align: left;
  31 + width: 15rem;
31 32 }
32 33 .selector-arrow {
33 34 padding-right: 1.5rem;
88 kitsune/community/templates/community/index.html
@@ -6,42 +6,66 @@ <h1 class="main-heading">{{ _('Community Hub') }}</h1>
6 6 <article class="contributors">
7 7 <h1>{{ _('Top Contributors') }}</h1>
8 8
9   - {# TODO: comment out for now
10 9 <div class="selector block">
11 10 <button type="button" class="ts-select-trigger">
12 11 <!-- arrow icon using icon font -->
13 12 <span aria-hidden="true" data-icon-arrow="&#xe800;" class="selector-arrow">
14   - <span class='current-selected'>{{ _('Select Top Contributors by Locale') }}</span>
  13 + <span class='current-selected'>
  14 + {% if not locale %}
  15 + {{ _('Select Top Contributors by Locale') }}
  16 + {% else %}
  17 + {{ settings.LANGUAGES_DICT[locale.lower()] }}
  18 + {% endif %}
  19 + </span>
15 20 </span>
16 21 </button>
17 22 <div class="select-options ts-modal" aria-expanded="false">
  23 + {% set base_url = url('community.home') %}
18 24 <ul class="ts-options" tabindex="-1">
19   - <li><a href="#en-US" class="selected" aria-checked="true">{{ _('English') }}</a></li>
20   - <li><a href="#fr">{{ _('French') }}</a></li>
21   - <li><a href="#de">{{ _('German') }}</a></li>
  25 + <li>
  26 + <a href="{{ base_url }}" {% if not locale %} aria-checked="true" class="selected"{% endif %}>
  27 + {{ _('All locales') }}
  28 + </a>
  29 + </li>
  30 + {% for l in settings.LANGUAGE_CHOICES %}
  31 + <li>
  32 + <a href="{{ base_url|urlparams(locale=l[0]) }}"{% if l[0] == locale %} aria-checked="true" class="selected"{% endif %}>
  33 + {{ l[1] }}
  34 + </a>
  35 + </li>
  36 + {% endfor %}
22 37 </ul>
23 38 </div>
24 39 </div>
25   - #}
26 40
  41 + {% if top_contributors_questions %}
27 42 <section class="contributor-group">
28 43 <h2>{{ _('Support Forum') }}</h2>
29   - {{ render_contributors(top_contributors_questions, 'questions') }}
  44 + {{ render_contributors(top_contributors_questions, 'questions', locale) }}
30 45 </section>
  46 + {% endif %}
31 47
32   - <section class="contributor-group">
33   - <h2>{{ _('Knowledge Base') }}</h2>
34   - {{ render_contributors(top_contributors_kb, 'kb') }}
35   - </section>
  48 + {% if top_contributors_kb %}
  49 + <section class="contributor-group">
  50 + <h2>{{ _('Knowledge Base') }}</h2>
  51 + {{ render_contributors(top_contributors_kb, 'kb', locale) }}
  52 + </section>
  53 + {% endif %}
36 54
37   - <section class="contributor-group">
38   - <h2>{{ _('Localization') }}</h2>
39   - {{ render_contributors(top_contributors_l10n, 'l10n') }}
40   - </section>
  55 + {% if top_contributors_l10n %}
  56 + <section class="contributor-group">
  57 + <h2>{{ _('Localization') }}</h2>
  58 + {{ render_contributors(top_contributors_l10n, 'l10n', locale) }}
  59 + </section>
  60 + {% endif %}
  61 +
  62 + {% if top_contributors_aoa %}
  63 + <section class="contributor-group">
  64 + <h2>{{ _('Army of Awesome') }}</h2>
  65 + {{ render_contributors(top_contributors_aoa, 'army-of-awesome', locale) }}
  66 + </section>
  67 + {% endif %}
41 68
42   - <section class="contributor-group">
43   - <h2>{{ _('Army of Awesome') }}</h2>
44   - {{ render_contributors(top_contributors_aoa, 'army-of-awesome') }}
45 69 </article>
46 70
47 71 <article class="community-news">
@@ -49,26 +73,6 @@ <h1 class="main-heading">{{ _('Community Hub') }}</h1>
49 73 <h1>{{ _('Find your fellow contributors') }}</h1>
50 74
51 75 <form name="find-contributor" id="find-contributor" action="{{ url('community.search') }}" method="get">
52   -
53   - {# COMMENT THIS OUT FOR NOW
54   - <input type="hidden" value="" id="ts-value" name="findby" />
55   -
56   - <div class="selector" data-emulate-select="true">
57   - <button type="button" class="ts-select-trigger">
58   - <!-- arrow icon using icon font -->
59   - <span aria-hidden="true" data-icon-arrow="&#xe800;" class="selector-arrow">
60   - <span class='currently-selected'>{{ _('Find By') }}</span>
61   - </span>
62   - </button>
63   - <div class="select-options ts-modal" aria-expanded="false">
64   - <ul class="ts-options" tabindex="-1">
65   - <li><a href="javascript:void(0);" data-value="username">{{ _('Username') }}</a></li>
66   - <li><a href="javascript:void(0);" data-value="display_name">{{ _('Display Name') }}</a></li>
67   - </ul>
68   - </div>
69   - </div>
70   - ENDCOMMENT #}
71   -
72 76 <fieldset>
73 77 <input type="text" name="q" id="search" placeholder="{{ _('Username or Display Name') }}" />
74 78 <input type="submit" value="{{ _('Search') }}" class="search" />
@@ -86,7 +90,7 @@ <h1 class="main-heading">{{ _('Community Hub') }}</h1>
86 90 </article>
87 91 {% endblock %}
88 92
89   -{% macro render_contributors(results, area) -%}
  93 +{% macro render_contributors(results, area, locale) -%}
90 94 <ul class="contributor-list {{ area }}">
91 95 {% for result in results %}
92 96 <li>
@@ -98,7 +102,11 @@ <h1 class="main-heading">{{ _('Community Hub') }}</h1>
98 102 {% endfor %}
99 103 </ul>
100 104 <p>
101   - <a href="{{ url('community.top_contributors', area=area) }}" class="view-all">
  105 + {% set all_url = url('community.top_contributors', area=area) %}
  106 + {% if locale %}
  107 + {% set all_url = all_url|urlparams(locale=locale) %}
  108 + {% endif %}
  109 + <a href="{{ all_url }}" class="view-all">
102 110 {{ _('See All') }}
103 111 </a>
104 112 </p>
34 kitsune/community/templates/community/top_contributors.html
@@ -20,27 +20,39 @@ <h1 class="main-heading">{{ _('Community Hub') }}</h1>
20 20 <section class="community-results-header">
21 21 <h1>{{ title }}</h1>
22 22
23   - {# TODO: commenting this out for now
24   - <form name="find-contributor" id="find-contributor" action="community/contributor_results" method="post">
25   - {{ csrf() }}
26   - <input type="hidden" value="" id="ts-value" name="findby" />
27   -
28   - <div class="selector" data-emulate-select="true">
  23 + {% if locales %}
  24 + <div class="selector">
29 25 <button type="button" class="ts-select-trigger">
30 26 <!-- arrow icon using icon font -->
31 27 <span aria-hidden="true" data-icon-arrow="&#xe800;" class="selector-arrow">
32   - <span class='current-selected'>{{ _('Sort Contributors By') }}</span>
  28 + <span class='current-selected'>
  29 + {% if not locale %}
  30 + {{ _('Select Top Contributors by Locale') }}
  31 + {% else %}
  32 + {{ settings.LANGUAGES_DICT[locale.lower()] }}
  33 + {% endif %}
  34 + </span>
33 35 </span>
34 36 </button>
35 37 <div class="select-options ts-modal" aria-expanded="false">
  38 + {% set base_url = url('community.top_contributors', area=area) %}
36 39 <ul class="ts-options" tabindex="-1">
37   - <li><a href="#contributions" class="selected" aria-checked="true">{{ _('Contributions') }}</a></li>
38   - <li><a href="#activity">{{ _('Days Since Last Activity') }}</a></li>
  40 + <li>
  41 + <a href="{{ base_url }}" {% if not locale %} aria-checked="true" class="selected"{% endif %}>
  42 + {{ _('All locales') }}
  43 + </a>
  44 + </li>
  45 + {% for l in locales %}
  46 + <li>
  47 + <a href="{{ base_url|urlparams(locale=l) }}"{% if l == locale %} aria-checked="true" class="selected"{% endif %}>
  48 + {{ settings.LANGUAGES_DICT[l.lower()] }}
  49 + </a>
  50 + </li>
  51 + {% endfor %}
39 52 </ul>
40 53 </div>
41 54 </div>
42   - </form>
43   - #}
  55 + {% endif %}
44 56 </section>
45 57
46 58 <ol>
2  kitsune/community/urls.py
@@ -3,8 +3,8 @@
3 3
4 4 urlpatterns = patterns(
5 5 'kitsune.community.views',
  6 + url(r'^$', 'home', name='community.home'),
6 7 url(r'^/search$', 'search', name='community.search'),
7 8 url(r'^/top-contributors/(?P<area>[\w-]+)$', 'top_contributors',
8 9 name='community.top_contributors'),
9   - url(r'^$', 'home', name='community.home'),
10 10 )
7 kitsune/community/utils.py
@@ -45,14 +45,17 @@ def top_contributors_l10n(
45 45 return _get_creator_counts(query)
46 46
47 47
48   -def top_contributors_aoa(start=None, end=None, count=10):
  48 +def top_contributors_aoa(start=None, end=None, locale=None, count=10):
49 49 """Get the top Army of Awesome contributors."""
50 50 # Get the user ids and contribution count of the top contributors.
51 51 query = (ReplyMetricsMappingType
52 52 .search()
53 53 .facet('creator_id', filtered=True, size=count))
54 54
55   - query = _apply_filters(query, start, end)
  55 + # twitter only does language
  56 + locale = locale.split('-')[0] if locale else None
  57 +
  58 + query = _apply_filters(query, start, end, locale)
56 59
57 60 return _get_creator_counts(query)
58 61
55 kitsune/community/views.py
... ... @@ -1,5 +1,6 @@
1 1 import logging
2 2
  3 +from django.conf import settings
3 4 from django.http import Http404
4 5 from django.shortcuts import render
5 6
@@ -26,14 +27,38 @@ def home(request):
26 27
27 28 community_news = get_object_fallback(
28 29 Document, COMMUNITY_NEWS_DOC, request.LANGUAGE_CODE)
  30 + locale = _validate_locale(request.GET.get('locale'))
29 31
30   - return render(request, 'community/index.html', {
  32 + data = {
31 33 'community_news': community_news,
32   - 'top_contributors_aoa': top_contributors_aoa(),
33   - 'top_contributors_kb': top_contributors_kb(),
34   - 'top_contributors_l10n': top_contributors_l10n(),
35   - 'top_contributors_questions': top_contributors_questions(),
36   - })
  34 + 'locale': locale,
  35 + }
  36 +
  37 + if locale:
  38 + data['top_contributors_aoa'] = top_contributors_aoa(locale=locale)
  39 +
  40 + # If the locale is en-US we should top KB contributors, else we show
  41 + # top l10n contributors for that locale
  42 + if locale == settings.WIKI_DEFAULT_LANGUAGE:
  43 + data['top_contributors_kb'] = top_contributors_kb()
  44 + else:
  45 + data['top_contributors_l10n'] = top_contributors_l10n(
  46 + locale=locale)
  47 +
  48 + # If the locale is enabled for the Support Forum, show the top
  49 + # contributors for that locale
  50 + if locale in settings.AAQ_LANGUAGES:
  51 + data['top_contributors_questions'] = top_contributors_questions(
  52 + locale=locale)
  53 + else:
  54 + # If no locale is specified, we show overall top contributors
  55 + # across locales.
  56 + data['top_contributors_aoa'] = top_contributors_aoa()
  57 + data['top_contributors_kb'] = top_contributors_kb()
  58 + data['top_contributors_l10n'] = top_contributors_l10n()
  59 + data['top_contributors_questions'] = top_contributors_questions()
  60 +
  61 + return render(request, 'community/index.html', data)
37 62
38 63
39 64 def search(request):
@@ -78,20 +103,34 @@ def search(request):
78 103 def top_contributors(request, area):
79 104 """Top contributors list view."""
80 105
81   - locale = request.GET.get('locale')
  106 + locale = _validate_locale(request.GET.get('locale'))
82 107
83 108 if area == 'army-of-awesome':
84   - results = top_contributors_aoa(count=50)
  109 + results = top_contributors_aoa(locale=locale, count=50)
  110 + locales = settings.SUMO_LANGUAGES
85 111 elif area == 'questions':
86 112 results = top_contributors_questions(locale=locale, count=50)
  113 + locales = settings.AAQ_LANGUAGES
87 114 elif area == 'kb':
88 115 results = top_contributors_kb(count=50)
  116 + locales = None
89 117 elif area == 'l10n':
90 118 results = top_contributors_l10n(locale=locale, count=50)
  119 + locales = settings.SUMO_LANGUAGES
91 120 else:
92 121 raise Http404
93 122
94 123 return render(request, 'community/top_contributors.html', {
95 124 'results': results,
96 125 'area': area,
  126 + 'locale': locale,
  127 + 'locales': locales,
97 128 })
  129 +
  130 +
  131 +def _validate_locale(locale):
  132 + """Make sure the locale is enabled on SUMO."""
  133 + if locale and locale not in settings.SUMO_LANGUAGES:
  134 + raise Http404
  135 +
  136 + return locale

0 comments on commit c9ca13f

Please sign in to comment.
Something went wrong with that request. Please try again.