Ejemplo n.º 1
0
    def test_top_contributors_questions(self):
        firefox = product(slug='firefox', save=True)
        fxos = product(slug='firefox-os', save=True)
        a1 = answer(save=True)
        a1.question.product = firefox
        a1.question.save()
        a2 = answer(creator=a1.creator, save=True)
        a3 = answer(save=True)
        a3.question.product = fxos
        a3.question.save()
        a4 = answer(created=datetime.now() - timedelta(days=91), save=True)
        a5 = answer(creator=a1.creator, save=True)
        a5.question.product = fxos
        a5.question.save()
        answer(creator=a4.question.creator, question=a4.question, 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_questions()
        eq_(2, len(top))
        assert a4.creator_id not in [u['term'] for u in top]
        eq_(a1.creator_id, top[0]['term'])

        # Verify, filtering of Firefox questions only.
        top, _ = top_contributors_questions(product=firefox.slug)
        eq_(1, len(top))
        eq_(a1.creator_id, top[0]['term'])
        top, _ = top_contributors_questions(product=fxos.slug)
        eq_(2, len(top))
Ejemplo n.º 2
0
    def test_top_contributors_questions(self):
        firefox = product(slug='firefox', save=True)
        fxos = product(slug='firefox-os', save=True)
        a1 = answer(save=True)
        a1.question.products.add(firefox)
        a1.question.products.add(fxos)
        a2 = answer(creator=a1.creator, save=True)
        a3 = answer(save=True)
        a3.question.products.add(fxos)
        a4 = answer(created=datetime.now()-timedelta(days=91),
                    save=True)
        answer(creator=a4.question.creator, question=a4.question, 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_questions()
        eq_(2, len(top))
        assert a4.creator_id not in [u['term'] for u in top]
        eq_(a1.creator_id, top[0]['term'])

        # Verify, filtering of Firefox questions only.
        top = top_contributors_questions(product=firefox.slug)
        eq_(1, len(top))
        eq_(a1.creator_id, top[0]['term'])
        top = top_contributors_questions(product=fxos.slug)
        eq_(2, len(top))
Ejemplo n.º 3
0
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)
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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),
    })
Ejemplo n.º 6
0
def update_top_contributors():
    """"Update the top contributor lists and titles."""
    top25_ids = [
        x['user']['id'] for x in top_contributors_questions(count=25)[0]
    ]
    Title.objects.set_top10_contributors(top25_ids[:10])
    Title.objects.set_top25_contributors(top25_ids[10:25])
Ejemplo n.º 7
0
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)
Ejemplo n.º 8
0
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,
        },
    )
Ejemplo n.º 9
0
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(),
    })
Ejemplo n.º 10
0
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(),
    })
Ejemplo n.º 11
0
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,
        })
Ejemplo n.º 12
0
    def test_top_contributors_questions(self):
        a1 = answer(save=True)
        a2 = answer(creator=a1.creator, save=True)
        a3 = answer(save=True)
        a4 = answer(created=datetime.now()-timedelta(days=91),
                    save=True)

        self.refresh()

        # By default, we should only get 2 top contributors back.
        top = top_contributors_questions()
        eq_(2, len(top))
        assert a4.creator_id not in [u['term'] for u in top]
        eq_(a1.creator_id, top[0]['term'])
Ejemplo n.º 13
0
    def test_top_contributors_questions(self):
        firefox = ProductFactory(slug="firefox")
        fxos = ProductFactory(slug="firefox-os")
        a1 = AnswerFactory(question__product=firefox)
        AnswerFactory(creator=a1.creator)
        AnswerFactory(question__product=fxos)
        a4 = AnswerFactory(created=datetime.now() - timedelta(days=91))
        AnswerFactory(creator=a1.creator, question__product=fxos)
        AnswerFactory(creator=a4.question.creator, question=a4.question)

        self.refresh()

        # By default, we should only get 2 top contributors back.
        top, _ = top_contributors_questions()
        eq_(2, len(top))
        assert a4.creator_id not in [u["term"] for u in top]
        eq_(a1.creator_id, top[0]["term"])

        # Verify, filtering of Firefox questions only.
        top, _ = top_contributors_questions(product=firefox.slug)
        eq_(1, len(top))
        eq_(a1.creator_id, top[0]["term"])
        top, _ = top_contributors_questions(product=fxos.slug)
        eq_(2, len(top))
Ejemplo n.º 14
0
    def test_top_contributors_questions(self):
        firefox = ProductFactory(slug="firefox")
        fxos = ProductFactory(slug="firefox-os")
        a1 = AnswerFactory(question__product=firefox)
        AnswerFactory(creator=a1.creator)
        AnswerFactory(question__product=fxos)
        a4 = AnswerFactory(created=datetime.now() - timedelta(days=91))
        AnswerFactory(creator=a1.creator, question__product=fxos)
        AnswerFactory(creator=a4.question.creator, question=a4.question)

        self.refresh()

        # By default, we should only get 2 top contributors back.
        top, _ = top_contributors_questions()
        eq_(2, len(top))
        assert a4.creator_id not in [u["term"] for u in top]
        eq_(a1.creator_id, top[0]["term"])

        # Verify, filtering of Firefox questions only.
        top, _ = top_contributors_questions(product=firefox.slug)
        eq_(1, len(top))
        eq_(a1.creator_id, top[0]["term"])
        top, _ = top_contributors_questions(product=fxos.slug)
        eq_(2, len(top))
Ejemplo n.º 15
0
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,
    })
Ejemplo n.º 16
0
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,
    })
Ejemplo n.º 17
0
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),
        })
Ejemplo n.º 18
0
 def handle(self, **options):
     top25_ids = [
         x["user"]["id"] for x in top_contributors_questions(count=25)[0]
     ]
     Title.objects.set_top10_contributors(top25_ids[:10])
     Title.objects.set_top25_contributors(top25_ids[10:25])
Ejemplo n.º 19
0
def update_top_contributors():
    """"Update the top contributor lists and titles."""
    top25_ids = [x['user']['id'] for x in top_contributors_questions(count=25)[0]]
    Title.objects.set_top10_contributors(top25_ids[:10])
    Title.objects.set_top25_contributors(top25_ids[10:25])
Ejemplo n.º 20
0
 def handle(self, **options):
     top25_ids = [x['user']['id'] for x in top_contributors_questions(count=25)[0]]
     Title.objects.set_top10_contributors(top25_ids[:10])
     Title.objects.set_top25_contributors(top25_ids[10:25])