def get_queryset(self): invalid_filters = check_filters(self) if invalid_filters: raise InvalidFilters(invalid_filters=invalid_filters) return self.queryset
def get_queryset(self): invalid_filters = check_filters( self, special_filters=["organism__name", "result_id", "length"] ) if invalid_filters: raise InvalidFilters(invalid_filters=invalid_filters) queryset = OrganismIndex.public_objects.all() organism_name = self.request.query_params.get("organism__name", None) if organism_name is not None: queryset = queryset.filter(organism__name=organism_name.upper()) # https://github.com/AlexsLemonade/refinebio/issues/2459 # It looks like when we set `result_id` as a filterset field, # django_forms goes nuts and tries to call __str__ on every single # computational result in our database trying to find all of the # different possible computational_results. So let's just take care of # this one ourselves. result_id = self.request.query_params.get("result_id", None) if result_id is not None: queryset = queryset.filter(result_id=result_id) length = self.request.query_params.get("length", None) if length is not None: index_type = "TRANSCRIPTOME_{}".format(length.upper()) queryset = queryset.filter(index_type=index_type) return queryset
def add_to_params(self, key, value): """Add to query params, converting to string if necessary""" if type(value) == str: self.query_params.appendlist(key, value) elif type(value) == int or type(value) == bool: self.query_params.appendlist(key, str(value)) else: # We shouldn't be filtering on Null, lists, or dicts raise InvalidFilters( message="Invalid type {} for filter value {}".format( type(value), str(value)))
def get_queryset(self): """ ref https://www.django-rest-framework.org/api-guide/filtering/#filtering-against-query-parameters """ invalid_filters = check_filters( self, special_filters=[ "ids", "organism__name", "dataset_id", "experiment_accession_code", "accession_codes", "filter_by", ], ) if invalid_filters: raise InvalidFilters(invalid_filters=invalid_filters) queryset = (Sample.public_objects.select_related( "organism").prefetch_related("experiments").prefetch_related( Prefetch( "results", queryset=ComputationalResult.objects.select_related( "processor").select_related("organism_index").order_by( "time_start"), )).prefetch_related("sampleannotation_set").prefetch_related( "original_files").prefetch_related("computed_files"). filter(**self.get_query_params_filters())) # case insensitive search https://docs.djangoproject.com/en/2.1/ref/models/querysets/#icontains filter_by = self.request.query_params.get("filter_by", None) if filter_by: queryset = queryset.filter( Q(accession_code__icontains=filter_by) | Q(title__icontains=filter_by) | Q(sex__icontains=filter_by) | Q(age__icontains=filter_by) | Q(specimen_part__icontains=filter_by) | Q(genotype__icontains=filter_by) | Q(disease__icontains=filter_by) | Q(disease_stage__icontains=filter_by) | Q(cell_line__icontains=filter_by) | Q(treatment__icontains=filter_by) | Q(race__icontains=filter_by) | Q(subject__icontains=filter_by) | Q(compound__icontains=filter_by) | Q(time__icontains=filter_by)) return queryset
def get_queryset(self): invalid_filters = check_filters(self, ["sample_accession_code"]) if invalid_filters: raise InvalidFilters(invalid_filters=invalid_filters) queryset = DownloaderJob.objects.all() sample_accession_code = self.request.query_params.get( "sample_accession_code", None) if sample_accession_code: queryset = queryset.filter( original_files__samples__accession_code=sample_accession_code ).distinct() return queryset
def get_queryset(self): invalid_filters = check_filters(self, ["latest_version"]) if invalid_filters: raise InvalidFilters(invalid_filters) public_result_queryset = CompendiumResult.objects.filter( result__is_public=True) latest_version = self.request.query_params.get("latest_version", False) if latest_version: version_filter = Q( primary_organism=OuterRef("primary_organism"), quant_sf_only=OuterRef("quant_sf_only"), ) latest_version = ( public_result_queryset.filter(version_filter).order_by( "-compendium_version").values("compendium_version")) return public_result_queryset.annotate( latest_version=Subquery(latest_version[:1])).filter( compendium_version=F("latest_version")) return public_result_queryset