Beispiel #1
0
def contributor_timeline(request, username):
    """Contributor events in the timeline."""
    user = get_object_or_404(User, username=username)
    try:
        page = int(request.GET.get("page", 1))
    except ValueError:
        raise Http404("Invalid page number.")

    # Exclude obsolete translations
    contributor_translations = (user.contributed_translations.exclude(
        entity__obsolete=True).extra({
            "day": "date(date)"
        }).order_by("-day"))

    counts_by_day = contributor_translations.values("day").annotate(
        count=Count("id"))

    try:
        events_paginator = Paginator(
            counts_by_day,
            django_settings.CONTRIBUTORS_TIMELINE_EVENTS_PER_PAGE)

        timeline_events = map_translations_to_events(
            events_paginator.page(page).object_list, contributor_translations)

        # Join is the last event in this reversed order.
        if page == events_paginator.num_pages:
            timeline_events.append({"date": user.date_joined, "type": "join"})

    except EmptyPage:
        # Return the join event if user reaches the last page.
        raise Http404("No events.")

    return render(request, "contributors/includes/timeline.html",
                  {"events": timeline_events})
Beispiel #2
0
def contributor_timeline(request, username):
    """Contributor events in the timeline."""
    user = get_object_or_404(User, username=username)
    try:
        page = int(request.GET.get('page', 1))
    except ValueError:
        raise Http404('Invalid page number.')

    # Exclude obsolete translations
    contributor_translations = (user.contributed_translations.exclude(
        entity__obsolete=True).extra({
            'day': "date(date)"
        }).order_by('-day'))

    counts_by_day = contributor_translations.values('day').annotate(
        count=Count('id'))

    try:
        events_paginator = Paginator(counts_by_day, 10)
        timeline_events = []

        timeline_events = map_translations_to_events(
            events_paginator.page(page).object_list, contributor_translations)

        # Join is the last event in this reversed order.
        if page == events_paginator.num_pages:
            timeline_events.append({'date': user.date_joined, 'type': 'join'})

    except EmptyPage:
        # Return the join event if user reaches the last page.
        raise Http404('No events.')

    return render(request, 'contributors/includes/timeline.html',
                  {'events': timeline_events})
Beispiel #3
0
def contributor_timeline(request, username):
    """Contributor events in the timeline."""
    user = get_object_or_404(User, username=username)
    try:
        page = int(request.GET.get('page', 1))
    except ValueError:
        raise Http404('Invalid page number.')

    # Exclude obsolete translations
    contributor_translations = (
        user.contributed_translations
            .exclude(entity__obsolete=True)
            .extra({'day': "date(date)"})
            .order_by('-day')
    )

    counts_by_day = contributor_translations.values('day').annotate(count=Count('id'))

    try:
        events_paginator = Paginator(counts_by_day, 10)
        timeline_events = []

        timeline_events = map_translations_to_events(
            events_paginator.page(page).object_list,
            contributor_translations
        )

        # Join is the last event in this reversed order.
        if page == events_paginator.num_pages:
            timeline_events.append({
                'date': user.date_joined,
                'type': 'join'
            })

    except EmptyPage:
        # Return the join event if user reaches the last page.
        raise Http404('No events.')

    return render(request, 'contributors/includes/timeline.html', {
        'events': timeline_events
    })