Ejemplo n.º 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, 'reviewers/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')}))
Ejemplo n.º 2
0
def themes_search(request):
    search_form = forms.ThemeSearchForm(request.GET)
    if search_form.is_valid():
        q = search_form.cleaned_data['q']
        rereview = search_form.cleaned_data['queue_type'] == 'rereview'
        flagged = search_form.cleaned_data['queue_type'] == 'flagged'

        # ES query on name.
        themes = Addon.search().filter(type=amo.ADDON_PERSONA)
        if rereview:
            themes = themes.filter(has_theme_rereview=True)
        else:
            themes = themes.filter(status=(amo.STATUS_REVIEW_PENDING if flagged
                                           else amo.STATUS_PENDING),
                                   has_theme_rereview=False)
        themes = themes.filter_query_string(q)[:100]

        now = datetime.datetime.now()
        reviewers = []
        for theme in themes:
            try:
                themelock = theme.persona.themelock
                if themelock.expiry > now:
                    reviewers.append(themelock.reviewer.email)
                else:
                    reviewers.append('')
            except ObjectDoesNotExist:
                reviewers.append('')

        themes = list(themes.values_dict('name', 'slug', 'status'))

        for theme, reviewer in zip(themes, reviewers):
            # Collapse single value fields from a list.
            theme['id'] = theme['id']
            theme['slug'] = theme['slug']
            theme['status'] = theme['status']
            # Dehydrate.
            theme['reviewer'] = reviewer

        return {'objects': themes, 'meta': {'total_count': len(themes)}}