Beispiel #1
0
def themes_list(request, flagged=False, rereview=False):
    """Themes queue in list format."""
    themes = []
    if flagged:
        # TODO (ngoke): rename to STATUS_FLAGGED.
        themes = Addon.objects.filter(status=amo.STATUS_REVIEW_PENDING,
                                      type=amo.ADDON_PERSONA,
                                      persona__isnull=False)
    elif rereview:
        themes = [
            rqt.theme.addon for rqt in
            RereviewQueueTheme.objects.select_related('theme__addon')]
    else:
        themes = Addon.objects.filter(status=amo.STATUS_PENDING,
                                      type=amo.ADDON_PERSONA,
                                      persona__isnull=False)

    search_form = forms.ThemeSearchForm(request.GET)
    per_page = request.GET.get('per_page', QUEUE_PER_PAGE)
    pager = paginate(request, themes, per_page)

    return render(request, 'editors/themes/queue_list.html', context(
        **{
        'addons': pager.object_list,
        'flagged': flagged,
        'pager': pager,
        'rereview': rereview,
        'theme_search_form': search_form,
        'STATUS_CHOICES': amo.STATUS_CHOICES,
        'statuses': dict((k, unicode(v)) for k, v in
                         amo.STATUS_CHOICES_API.items()),
        'tab': ('rereview_themes' if rereview else
                'flagged_themes' if flagged else 'pending_themes'),
    }))
Beispiel #2
0
def themes_list(request, flagged=False, rereview=False):
    """Themes queue in list format."""
    themes = []
    if flagged:
        # TODO (ngoke): rename to STATUS_FLAGGED.
        themes = Addon.objects.filter(status=amo.STATUS_REVIEW_PENDING,
                                      type=amo.ADDON_PERSONA,
                                      persona__isnull=False)
    elif rereview:
        themes = [
            rqt.theme.addon for rqt in
            RereviewQueueTheme.objects.select_related('theme__addon')]
    else:
        themes = Addon.objects.filter(status=amo.STATUS_PENDING,
                                      type=amo.ADDON_PERSONA,
                                      persona__isnull=False)

    search_form = forms.ThemeSearchForm(request.GET)
    per_page = request.GET.get('per_page', QUEUE_PER_PAGE)
    pager = paginate(request, themes, per_page)

    return render(request, 'editors/themes/queue_list.html', context(
        **{'addons': pager.object_list,
           'flagged': flagged,
           'pager': pager,
           'rereview': rereview,
           'theme_search_form': search_form,
           'statuses': dict((k, unicode(v)) for k, v in
                            amo.STATUS_CHOICES_API.items()),
           'tab': ('rereview_themes' if rereview else
                   'flagged_themes' if flagged else 'pending_themes')}))
Beispiel #3
0
def themes_logs(request):
    data = request.GET.copy()

    if not data.get('start') and not data.get('end'):
        today = datetime.date.today()
        data['start'] = datetime.date(today.year, today.month, 1)

    form = forms.ReviewAppLogForm(data)

    theme_logs = ActivityLog.objects.filter(action=amo.LOG.THEME_REVIEW.id)

    if form.is_valid():
        data = form.cleaned_data
        if data.get('start'):
            theme_logs = theme_logs.filter(created__gte=data['start'])
        if data.get('end'):
            theme_logs = theme_logs.filter(created__lte=data['end'])
        if data.get('search'):
            term = data['search']
            theme_logs = theme_logs.filter(
                Q(_details__icontains=term) |
                Q(user__display_name__icontains=term) |
                Q(user__username__icontains=term)).distinct()

    pager = paginate(request, theme_logs, 30)
    data = context(form=form, pager=pager,
                   ACTION_DICT=rvw.REVIEW_ACTIONS,
                   REJECT_REASONS=rvw.THEME_REJECT_REASONS, tab='themes')
    return render(request, 'editors/themes/logs.html', data)
Beispiel #4
0
def themes_logs(request):
    data = request.GET.copy()

    if not data.get('start') and not data.get('end'):
        today = datetime.date.today()
        data['start'] = datetime.date(today.year, today.month, 1)

    form = forms.ReviewAppLogForm(data)

    theme_logs = ActivityLog.objects.filter(action=amo.LOG.THEME_REVIEW.id)

    if form.is_valid():
        data = form.cleaned_data
        if data.get('start'):
            theme_logs = theme_logs.filter(created__gte=data['start'])
        if data.get('end'):
            theme_logs = theme_logs.filter(created__lte=data['end'])
        if data.get('search'):
            term = data['search']
            theme_logs = theme_logs.filter(
                Q(_details__icontains=term) |
                Q(user__display_name__icontains=term) |
                Q(user__username__icontains=term)).distinct()

    pager = paginate(request, theme_logs, 30)
    data = context(form=form, pager=pager,
                   ACTION_DICT=rvw.REVIEW_ACTIONS,
                   REJECT_REASONS=rvw.THEME_REJECT_REASONS, tab='themes')
    return render(request, 'editors/themes/logs.html', data)
Beispiel #5
0
def home(request):
    data = context(
        reviews_total=ActivityLog.objects.total_reviews(theme=True)[:5],
        reviews_monthly=ActivityLog.objects.monthly_reviews(theme=True)[:5],
        queue_counts=queue_counts_themes(request)
    )
    return render(request, 'editors/themes/home.html', data)
Beispiel #6
0
def themes_history(request, username):
    if not username:
        username = request.amo_user.username

    return render(request, 'editors/themes/history.html', context(
        **{'theme_reviews':
            paginate(request, ActivityLog.objects.filter(
                action=amo.LOG.THEME_REVIEW.id, user__username=username), 20),
           'user_history': True,
           'username': username,
           'reject_reasons': rvw.THEME_REJECT_REASONS,
           'action_dict': rvw.REVIEW_ACTIONS}))
Beispiel #7
0
def _themes_queue(request, flagged=False, rereview=False):
    """Themes queue in interactive format."""
    themes = _get_themes(request, request.amo_user, flagged=flagged,
                         rereview=rereview)

    ThemeReviewFormset = formset_factory(forms.ThemeReviewForm)
    formset = ThemeReviewFormset(
        initial=[{'theme': _rereview_to_theme(rereview, theme).id} for theme
                 in themes])

    return render(request, 'editors/themes/queue.html', context(
        **{
        'actions': get_actions_json(),
        'formset': formset,
        'flagged': flagged,
        'reject_reasons': rvw.THEME_REJECT_REASONS.items(),
        'rereview': rereview,
        'reviewable': True,
        'theme_formsets': zip(themes, formset),
        'theme_count': len(themes),
        'tab': 'flagged' if flagged else 'rereview' if rereview else 'pending'
    }))
Beispiel #8
0
def _themes_queue(request, flagged=False, rereview=False):
    """Themes queue in interactive format."""
    themes = _get_themes(request, request.amo_user, flagged=flagged,
                         rereview=rereview)

    ThemeReviewFormset = formset_factory(forms.ThemeReviewForm)
    formset = ThemeReviewFormset(
        initial=[{'theme': _rereview_to_theme(rereview, theme).id} for theme
                 in themes])

    return render(request, 'editors/themes/queue.html', context(
        **{'actions': get_actions_json(),
           'formset': formset,
           'flagged': flagged,
           'reject_reasons': rvw.THEME_REJECT_REASONS,
           'rereview': rereview,
           'reviewable': True,
           'theme_formsets': zip(themes, formset),
           'theme_count': len(themes),
           'tab': (
               'flagged' if flagged else
               'rereview' if rereview else 'pending')}))
Beispiel #9
0
def themes_single(request, slug):
    """
    Like a detail page, manually review a single theme if it is pending
    and isn't locked.
    """
    reviewer = request.user.get_profile()
    reviewable = True

    # Don't review an already reviewed theme.
    theme = get_object_or_404(Persona, addon__slug=slug)
    if (theme.addon.status != amo.STATUS_PENDING and
        not theme.rereviewqueuetheme_set.all()):
        reviewable = False

    if (not settings.ALLOW_SELF_REVIEWS and
        not acl.action_allowed(request, 'Admin', '%') and
        theme.addon.has_author(request.amo_user)):
        reviewable = False
    else:
        # Don't review a locked theme (that's not locked to self).
        try:
            lock = theme.themelock
            if (lock.reviewer.id != reviewer.id and
                lock.expiry > datetime.datetime.now()):
                reviewable = False
            elif (lock.reviewer.id != reviewer.id and
                  lock.expiry < datetime.datetime.now()):
                # Steal expired lock.
                lock.reviewer = reviewer
                lock.expiry = get_updated_expiry()
                lock.save()
            else:
                # Update expiry.
                lock.expiry = get_updated_expiry()
                lock.save()
        except ThemeLock.DoesNotExist:
            # Create lock if not created.
            ThemeLock.objects.create(theme=theme, reviewer=reviewer,
                                     expiry=get_updated_expiry())

    ThemeReviewFormset = formset_factory(forms.ThemeReviewForm)
    formset = ThemeReviewFormset(initial=[{'theme': theme.id}])

    # Since we started the review on the single page, we want to return to the
    # single page rather than get shot back to the queue.
    request.session['theme_redirect_url'] = reverse('editors.themes.single',
                                                    args=[theme.addon.slug])

    rereview = (theme.rereviewqueuetheme_set.all()[0] if
        theme.rereviewqueuetheme_set.exists() else None)
    return render(request, 'editors/themes/single.html', context(
        **{
        'formset': formset,
        'theme': rereview if rereview else theme,
        'theme_formsets': zip([rereview if rereview else theme], formset),
        'theme_reviews': paginate(request, ActivityLog.objects.filter(
            action=amo.LOG.THEME_REVIEW.id,
            _arguments__contains=theme.addon.id)),
        'actions': get_actions_json(),
        'theme_count': 1,
        'rereview': rereview,
        'reviewable': reviewable,
        'reject_reasons': rvw.THEME_REJECT_REASONS.items(),
        'action_dict': rvw.REVIEW_ACTIONS,
        'tab': ('flagged' if theme.addon.status == amo.STATUS_REVIEW_PENDING
                else 'rereview' if rereview else 'pending')
    }))
Beispiel #10
0
def themes_single(request, slug):
    """
    Like a detail page, manually review a single theme if it is pending
    and isn't locked.
    """
    reviewer = request.user
    reviewable = True

    # Don't review an already reviewed theme.
    theme = get_object_or_404(Persona, addon__slug=slug)
    if (theme.addon.status != amo.STATUS_PENDING and
            not theme.rereviewqueuetheme_set.all()):
        reviewable = False

    if (not settings.ALLOW_SELF_REVIEWS and
            not acl.action_allowed(request, 'Admin', '%') and
            theme.addon.has_author(request.amo_user)):
        reviewable = False
    else:
        # Don't review a locked theme (that's not locked to self).
        try:
            lock = theme.themelock
            if (lock.reviewer.id != reviewer.id and
                    lock.expiry > datetime.datetime.now()):
                reviewable = False
            elif (lock.reviewer.id != reviewer.id and
                  lock.expiry < datetime.datetime.now()):
                # Steal expired lock.
                lock.reviewer = reviewer
                lock.expiry = get_updated_expiry()
                lock.save()
            else:
                # Update expiry.
                lock.expiry = get_updated_expiry()
                lock.save()
        except ThemeLock.DoesNotExist:
            # Create lock if not created.
            ThemeLock.objects.create(theme=theme, reviewer=reviewer,
                                     expiry=get_updated_expiry())

    ThemeReviewFormset = formset_factory(forms.ThemeReviewForm)
    formset = ThemeReviewFormset(initial=[{'theme': theme.id}])

    # Since we started the review on the single page, we want to return to the
    # single page rather than get shot back to the queue.
    request.session['theme_redirect_url'] = reverse('editors.themes.single',
                                                    args=[theme.addon.slug])

    rereview = (theme.rereviewqueuetheme_set.all()[0] if
                theme.rereviewqueuetheme_set.exists() else None)
    return render(request, 'editors/themes/single.html', context(
        **{'formset': formset,
           'theme': rereview if rereview else theme,
           'theme_formsets': zip([rereview if rereview else theme], formset),
           'theme_reviews': paginate(request, ActivityLog.objects.filter(
               action=amo.LOG.THEME_REVIEW.id,
               _arguments__contains=theme.addon.id)),
           'actions': get_actions_json(),
           'theme_count': 1,
           'rereview': rereview,
           'reviewable': reviewable,
           'reject_reasons': rvw.THEME_REJECT_REASONS,
           'action_dict': rvw.REVIEW_ACTIONS,
           'tab': ('flagged' if theme.addon.status == amo.STATUS_REVIEW_PENDING
                   else 'rereview' if rereview else 'pending')}))