def filter_queryset(self, request, queryset, view): is_homescreen = request.GET.get('is_homescreen') if is_homescreen is None: return queryset if is_homescreen == u'false': return queryset.filter( Bool(must_not=[F('term', is_homescreen=True)])) else: return queryset.filter(Bool(must=[F('term', is_homescreen=True)]))
def filter_queryset(self, request, queryset, view): queryset = super(ReviewerSearchFormFilter, self).filter_queryset(request, queryset, view) # Special case for `is_tarako`, which gets converted to a tag filter. is_tarako = self.form_data.get('is_tarako') if is_tarako is not None: if is_tarako: queryset = queryset.filter( Bool(must=[F('term', tags='tarako')])) else: queryset = queryset.filter( Bool(must=[~F('term', tags='tarako')])) return queryset
def filter_queryset(self, request, queryset, view): form = view.form_class(request.GET) if not form.is_valid(): raise form_errors(form) self.form_data = form.cleaned_data data = {} for k, v in self.form_data.items(): data[self.FORM_TO_FIELD_MAP.get(k, k)] = v # Must filters. must = [] for field in self.VALID_FILTERS: value = data.get(field) if value is not None: if type(value) == list: filter_type = 'terms' else: filter_type = 'term' must.append(F(filter_type, **{field: value})) if must: return queryset.filter(Bool(must=must)) return queryset
def filter_queryset(self, request, qs, view): return qs.filter( Bool(must=[F('term', status=amo.REVIEWED_STATUSES)], must_not=[ F('term', is_deleted=True), F('term', is_listed=False), F('term', is_disabled=True) ]))
def filter_queryset(self, request, queryset, view): region = get_region_from_request(request) if region: return queryset.filter( Bool(must_not=[F('term', region_exclusions=region.id)])) return queryset
def filter_queryset(self, request, queryset, view): device_id = get_device_id(request) if device_id: queryset = queryset.filter( Bool(must=[F('term', device=device_id)])) return queryset
def filter_queryset(self, request, queryset, view): device_id = get_device_id(request) data = { 'gaia': getattr(request, 'GAIA', False), 'mobile': getattr(request, 'MOBILE', False), 'tablet': getattr(request, 'TABLET', False), } flash_incompatible = data['mobile'] or data['gaia'] if device_id: queryset = queryset.filter( Bool(must=[F('term', device=device_id)])) if flash_incompatible: queryset = queryset.filter( Bool(must_not=[F('term', uses_flash=True)])) return queryset
def filter_queryset(self, request, qs, view): return qs.filter( Bool(must=[ F('terms', status=amo.REVIEWED_STATUSES), F('exists', field='current_version') ], must_not=[ F('term', is_deleted=True), F('term', is_disabled=True) ]))
def filter_queryset(self, request, queryset, view): # Note: only Extensions have is_deleted, for Webapps the status is # changed when deleted. That's why a must_not is used, it will be true # even if the field does not exist. return queryset.filter( Bool(must=[ F('term', status=mkt.STATUS_PUBLIC), F('term', is_disabled=False) ], must_not=[F('term', is_deleted=True)]))
def filter_queryset(self, request, queryset, view): profile = get_feature_profile(request) if profile: must_not = [] for k in profile.to_kwargs(prefix='features.has_').keys(): must_not.append(F('term', **{k: True})) if must_not: return queryset.filter(Bool(must_not=must_not)) return queryset
def filter_by_apps(cls, app_ids, queryset=None): """ Filters the given queryset by the given app IDs. This uses a `should` filter, which is equivalent to an "OR". """ queryset = queryset or cls.search() app_ids = list(set(app_ids)) # De-dupe. queryset = queryset.filter(Bool(should=[F('terms', id=app_ids)])) return queryset[0:len(app_ids)]
def filter_queryset(self, request, qs, view): must = [] for filter_class in self.available_filters: filter_ = filter_class(request) if filter_.query_param in request.GET: try: must.extend(filter_.get_es_filter()) except ValueError: continue return qs.filter(Bool(must=must)) if must else qs
def filter_queryset(self, request, qs, view): must = [] for filter_class in self.available_filters: try: # Initialize the filter class if its query parameter is present # in the request, otherwise don't, to avoid raising exceptions # because of missing params in complex filters. if filter_class.query_param in request.GET: filter_ = filter_class(request) must.extend(filter_.get_es_filter()) except ValueError as exc: raise serializers.ValidationError(*exc.args) return qs.filter(Bool(must=must)) if must else qs
def get_queryset(self): qs = BaseMultiSearchView.get_queryset(self) return qs.filter(Bool(must=[F('term', device=mkt.DEVICE_TV.id)]))
def filter_queryset(self, request, queryset, view): return queryset.filter( Bool(must=[F('term', **{'features.has_openmobileacl': True})]))
def filter_queryset(self, request, queryset, view): return queryset.filter( Bool(must=[ F('terms', status=mkt.VALID_STATUSES), F('term', is_disabled=False) ]))