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.query(or_=name_only_query(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'][0] theme['slug'] = theme['slug'][0] theme['status'] = theme['status'][0] # Dehydrate. theme['reviewer'] = reviewer return {'objects': themes, 'meta': {'total_count': len(themes)}}