def test_top_contributors_kb(self): d = DocumentFactory(locale='en-US') r1 = RevisionFactory(document=d) RevisionFactory(document=d, creator=r1.creator) RevisionFactory(document=d) r4 = RevisionFactory(document=d, created=date.today() - timedelta(days=91)) self.refresh() # By default, we should only get 2 top contributors back. top, _ = top_contributors_kb() eq_(2, len(top)) assert r4.creator_id not in [u['term'] for u in top] eq_(r1.creator_id, top[0]['term']) # If we specify an older start, then we get all 3. top, _ = top_contributors_kb(start=date.today() - timedelta(days=92)) eq_(3, len(top)) # If we also specify an older end date, we only get the creator for # the older revision. top, _ = top_contributors_kb( start=date.today() - timedelta(days=92), end=date.today() - timedelta(days=1)) eq_(1, len(top)) eq_(r4.creator_id, top[0]['term'])
def test_top_contributors_kb(self): d = document(locale='en-US', save=True) r1 = revision(document=d, save=True) r2 = revision(document=d, creator=r1.creator, save=True) r3 = revision(document=d, save=True) r4 = revision(document=d, created=date.today() - timedelta(days=91), save=True) for u in User.objects.all(): profile(user=u) self.refresh() # By default, we should only get 2 top contributors back. top, _ = top_contributors_kb() eq_(2, len(top)) assert r4.creator_id not in [u['term'] for u in top] eq_(r1.creator_id, top[0]['term']) # If we specify an older start, then we get all 3. top, _ = top_contributors_kb(start=date.today() - timedelta(days=92)) eq_(3, len(top)) # If we also specify an older end date, we only get the creator for # the older revision. top, _ = top_contributors_kb(start=date.today() - timedelta(days=92), end=date.today() - timedelta(days=1)) eq_(1, len(top)) eq_(r4.creator_id, top[0]['term'])
def test_top_contributors_kb(self): d = document(locale='en-US', save=True) r1 = revision(document=d, save=True) r2 = revision(document=d, creator=r1.creator, save=True) r3 = revision(document=d, save=True) r4 = revision(document=d, created=date.today()-timedelta(days=91), save=True) self.refresh() # By default, we should only get 2 top contributors back. top = top_contributors_kb() eq_(2, len(top)) assert r4.creator_id not in [u['term'] for u in top] eq_(r1.creator_id, top[0]['term']) # If we specify an older start, then we get all 3. top = top_contributors_kb(start=date.today() - timedelta(days=92)) eq_(3, len(top)) # If we also specify an older end date, we only get the creator for # the older revision. top = top_contributors_kb( start=date.today() - timedelta(days=92), end=date.today() - timedelta(days=1)) eq_(1, len(top)) eq_(r4.creator_id, top[0]['term'])
def home(request): """Community hub landing page.""" community_news = get_object_fallback( Document, COMMUNITY_NEWS_DOC, request.LANGUAGE_CODE) locale = _validate_locale(request.GET.get('locale')) product = request.GET.get('product') if product: product = get_object_or_404(Product, slug=product) # Get the 5 most recent Community Discussion threads. recent_threads = Thread.objects.filter(forum__slug='contributors')[:5] data = { 'community_news': community_news, 'locale': locale, 'product': product, 'products': Product.objects.filter(visible=True), 'threads': recent_threads, } if locale: data['top_contributors_aoa'], _ = top_contributors_aoa(locale=locale) # If the locale is en-US we should top KB contributors, else we show # top l10n contributors for that locale if locale == settings.WIKI_DEFAULT_LANGUAGE: data['top_contributors_kb'], _ = top_contributors_kb( product=product) else: data['top_contributors_l10n'], _ = top_contributors_l10n( locale=locale, product=product) # If the locale is enabled for the Support Forum, show the top # contributors for that locale if locale in QuestionLocale.objects.locales_list(): data['top_contributors_questions'], _ = top_contributors_questions( locale=locale, product=product) else: # If no locale is specified, we show overall top contributors # across locales. data['top_contributors_aoa'], _ = top_contributors_aoa() data['top_contributors_kb'], _ = top_contributors_kb(product=product) data['top_contributors_l10n'], _ = top_contributors_l10n( product=product) data['top_contributors_questions'], _ = top_contributors_questions( product=product) return render(request, 'community/index.html', data)
def home(request): """Community hub landing page.""" community_news = get_object_fallback(Document, COMMUNITY_NEWS_DOC, request.LANGUAGE_CODE) locale = _validate_locale(request.GET.get("locale")) product = request.GET.get("product") if product: product = get_object_or_404(Product, slug=product) # Get the 5 most recent Community Discussion threads. recent_threads = Thread.objects.filter(forum__slug="contributors")[:5] data = { "community_news": community_news, "locale": locale, "product": product, "products": Product.objects.filter(visible=True), "threads": recent_threads, } if locale: data["top_contributors_aoa"], _ = top_contributors_aoa(locale=locale) # If the locale is en-US we should top KB contributors, else we show # top l10n contributors for that locale if locale == settings.WIKI_DEFAULT_LANGUAGE: data["top_contributors_kb"], _ = top_contributors_kb( product=product) else: data["top_contributors_l10n"], _ = top_contributors_l10n( locale=locale, product=product) # If the locale is enabled for the Support Forum, show the top # contributors for that locale if locale in QuestionLocale.objects.locales_list(): data["top_contributors_questions"], _ = top_contributors_questions( locale=locale, product=product) else: # If no locale is specified, we show overall top contributors # across locales. data["top_contributors_aoa"], _ = top_contributors_aoa() data["top_contributors_kb"], _ = top_contributors_kb(product=product) data["top_contributors_l10n"], _ = top_contributors_l10n( product=product) data["top_contributors_questions"], _ = top_contributors_questions( product=product) return render(request, "community/index.html", data)
def top_contributors(request, area): """Top contributors list view.""" locale = _validate_locale(request.GET.get('locale')) product = request.GET.get('product') if product: product = get_object_or_404(Product, slug=product) if area == 'army-of-awesome': results = top_contributors_aoa(locale=locale, count=50) locales = settings.SUMO_LANGUAGES elif area == 'questions': results = top_contributors_questions( locale=locale, product=product, count=50) locales = settings.AAQ_LANGUAGES elif area == 'kb': results = top_contributors_kb(product=product, count=50) locales = None elif area == 'l10n': results = top_contributors_l10n( locale=locale, product=product, count=50) locales = settings.SUMO_LANGUAGES else: raise Http404 return render(request, 'community/top_contributors.html', { 'results': results, 'area': area, 'locale': locale, 'locales': locales, 'product': product, 'products': Product.objects.filter(visible=True), })
def home(request): """Community hub landing page.""" community_news = get_object_fallback(Document, COMMUNITY_NEWS_DOC, request.LANGUAGE_CODE) locale = _validate_locale(request.GET.get('locale')) product = request.GET.get('product') if product: product = get_object_or_404(Product, slug=product) # Get the 5 most recent Community Discussion threads. recent_threads = Thread.objects.filter(forum__slug='contributors')[:5] data = { 'community_news': community_news, 'locale': locale, 'product': product, 'products': Product.objects.filter(visible=True), 'threads': recent_threads, } if locale: data['top_contributors_aoa'] = top_contributors_aoa(locale=locale) # If the locale is en-US we should top KB contributors, else we show # top l10n contributors for that locale if locale == settings.WIKI_DEFAULT_LANGUAGE: data['top_contributors_kb'] = top_contributors_kb(product=product) else: data['top_contributors_l10n'] = top_contributors_l10n( locale=locale, product=product) # If the locale is enabled for the Support Forum, show the top # contributors for that locale if locale in settings.AAQ_LANGUAGES: data['top_contributors_questions'] = top_contributors_questions( locale=locale, product=product) else: # If no locale is specified, we show overall top contributors # across locales. data['top_contributors_aoa'] = top_contributors_aoa() data['top_contributors_kb'] = top_contributors_kb(product=product) data['top_contributors_l10n'] = top_contributors_l10n(product=product) data['top_contributors_questions'] = top_contributors_questions( product=product) return render(request, 'community/index.html', data)
def top_contributors(request, area): """Top contributors list view.""" try: page = int(request.GET.get("page", 1)) except ValueError: page = 1 page_size = 100 exceeds_page_size = False locale = _validate_locale(request.GET.get("locale")) product = request.GET.get("product") if product: product = get_object_or_404(Product, slug=product) if area == "army-of-awesome": results, total = top_contributors_aoa(locale=locale, count=page_size, page=page) locales = settings.SUMO_LANGUAGES elif area == "questions": results, total = top_contributors_questions(locale=locale, product=product, count=page_size) if total == page_size + 1: total -= 1 exceeds_page_size = True locales = QuestionLocale.objects.locales_list() elif area == "kb": results, total = top_contributors_kb(product=product, count=page_size, page=page) locales = None elif area == "l10n": results, total = top_contributors_l10n(locale=locale, product=product, count=page_size, page=page) locales = settings.SUMO_LANGUAGES else: raise Http404 return render( request, "community/top_contributors.html", { "results": results, "total": total, "area": area, "locale": locale, "locales": locales, "product": product, "products": Product.objects.filter(visible=True), "page": page, "page_size": page_size, "exceeds_page_size": exceeds_page_size, }, )
def home(request): """Community hub landing page.""" return render(request, 'community/index.html', { 'top_contributors_aoa': top_contributors_aoa(), 'top_contributors_kb': top_contributors_kb(), 'top_contributors_l10n': top_contributors_l10n(), 'top_contributors_questions': top_contributors_questions(), })
def home(request): """Community hub landing page.""" community_news = get_object_fallback( Document, COMMUNITY_NEWS_DOC, request.LANGUAGE_CODE) return render(request, 'community/index.html', { 'community_news': community_news, 'top_contributors_aoa': top_contributors_aoa(), 'top_contributors_kb': top_contributors_kb(), 'top_contributors_l10n': top_contributors_l10n(), 'top_contributors_questions': top_contributors_questions(), })
def top_contributors(request, area): """Top contributors list view.""" try: page = int(request.GET.get('page', 1)) except ValueError: page = 1 page_size = 100 locale = _validate_locale(request.GET.get('locale')) product = request.GET.get('product') if product: product = get_object_or_404(Product, slug=product) if area == 'army-of-awesome': results, total = top_contributors_aoa(locale=locale, count=page_size, page=page) locales = settings.SUMO_LANGUAGES elif area == 'questions': results, total = top_contributors_questions(locale=locale, product=product, count=page_size, page=page) locales = QuestionLocale.objects.locales_list() elif area == 'kb': results, total = top_contributors_kb(product=product, count=page_size, page=page) locales = None elif area == 'l10n': results, total = top_contributors_l10n(locale=locale, product=product, count=page_size, page=page) locales = settings.SUMO_LANGUAGES else: raise Http404 return render( request, 'community/top_contributors.html', { 'results': results, 'total': total, 'area': area, 'locale': locale, 'locales': locales, 'product': product, 'products': Product.objects.filter(visible=True), 'page': page, 'page_size': page_size, })
def test_top_contributors_kb(self): d = DocumentFactory(locale="en-US") r1 = RevisionFactory(document=d) RevisionFactory(document=d, creator=r1.creator) RevisionFactory(document=d) r4 = RevisionFactory(document=d, created=date.today() - timedelta(days=91)) self.refresh() # By default, we should only get 2 top contributors back. top, _ = top_contributors_kb() eq_(2, len(top)) assert r4.creator_id not in [u["term"] for u in top] eq_(r1.creator_id, top[0]["term"]) # If we specify an older start, then we get all 3. top, _ = top_contributors_kb(start=date.today() - timedelta(days=92)) eq_(3, len(top)) # If we also specify an older end date, we only get the creator for # the older revision. top, _ = top_contributors_kb(start=date.today() - timedelta(days=92), end=date.today() - timedelta(days=1)) eq_(1, len(top)) eq_(r4.creator_id, top[0]["term"])
def top_contributors(request, area): """Top contributors list view.""" try: page = int(request.GET.get('page', 1)) except ValueError: page = 1 page_size = 100 locale = _validate_locale(request.GET.get('locale')) product = request.GET.get('product') if product: product = get_object_or_404(Product, slug=product) if area == 'army-of-awesome': results, total = top_contributors_aoa( locale=locale, count=page_size, page=page) locales = settings.SUMO_LANGUAGES elif area == 'questions': results, total = top_contributors_questions( locale=locale, product=product, count=page_size, page=page) locales = QuestionLocale.objects.locales_list() elif area == 'kb': results, total = top_contributors_kb( product=product, count=page_size, page=page) locales = None elif area == 'l10n': results, total = top_contributors_l10n( locale=locale, product=product, count=page_size, page=page) locales = settings.SUMO_LANGUAGES else: raise Http404 return render(request, 'community/top_contributors.html', { 'results': results, 'total': total, 'area': area, 'locale': locale, 'locales': locales, 'product': product, 'products': Product.objects.filter(visible=True), 'page': page, 'page_size': page_size, })
def top_contributors(request, area): """Top contributors list view.""" locale = request.GET.get('locale') if area == 'army-of-awesome': results = top_contributors_aoa(count=50) elif area == 'questions': results = top_contributors_questions(locale=locale, count=50) elif area == 'kb': results = top_contributors_kb(count=50) elif area == 'l10n': results = top_contributors_l10n(locale=locale, count=50) else: raise Http404 return render(request, 'community/top_contributors.html', { 'results': results, 'area': area, })
def top_contributors(request, area): """Top contributors list view.""" locale = _validate_locale(request.GET.get('locale')) product = request.GET.get('product') if product: product = get_object_or_404(Product, slug=product) if area == 'army-of-awesome': results = top_contributors_aoa(locale=locale, count=50) locales = settings.SUMO_LANGUAGES elif area == 'questions': results = top_contributors_questions(locale=locale, product=product, count=50) locales = settings.AAQ_LANGUAGES elif area == 'kb': results = top_contributors_kb(product=product, count=50) locales = None elif area == 'l10n': results = top_contributors_l10n(locale=locale, product=product, count=50) locales = settings.SUMO_LANGUAGES else: raise Http404 return render( request, 'community/top_contributors.html', { 'results': results, 'area': area, 'locale': locale, 'locales': locales, 'product': product, 'products': Product.objects.filter(visible=True), })