def get_queryset(self): parent = self.request.query_params.get( 'filter[parents]', None) or self.request.query_params.get( 'filter[parent]', None) provider = get_object_or_error(PreprintProvider, self.kwargs['provider_id'], self.request, display_name='PreprintProvider') if parent: if parent == 'null': return provider.top_level_subjects if provider.subjects.exists(): return optimize_subject_query( provider.subjects.filter(parent___id=parent)) else: # TODO: Delet this when all PreprintProviders have a mapping # Calculate this here to only have to do it once. allowed_parents = [ id_ for sublist in provider.subjects_acceptable for id_ in sublist[0] ] allows_children = [ subs[0][-1] for subs in provider.subjects_acceptable if subs[1] ] return [ sub for sub in optimize_subject_query( Subject.objects.filter(parent___id=parent)) if provider.subjects_acceptable == [] or self.is_valid_subject(allows_children=allows_children, allowed_parents=allowed_parents, sub=sub) ] return optimize_subject_query(provider.all_subjects)
def get_default_queryset(self): parent = self.request.query_params.get('filter[parent]', None) provider = get_object_or_error(self.provider_class, self.kwargs['provider_id'], self.request, display_name=self.provider_class.__name__) if parent: if parent == 'null': return provider.top_level_subjects return optimize_subject_query(provider.all_subjects.filter(parent___id=parent)) return optimize_subject_query(provider.all_subjects)
def get_queryset(self): parent = self.request.query_params.get('filter[parents]', None) or self.request.query_params.get('filter[parent]', None) provider = get_object_or_error(self._model_class, self.kwargs['provider_id'], self.request, display_name=self._model_class.__name__) if parent: if parent == 'null': return provider.top_level_subjects return optimize_subject_query(provider.all_subjects.filter(parent___id=parent)) return optimize_subject_query(provider.all_subjects)
def top_level_subjects(self): if self.subjects.exists(): return optimize_subject_query(self.subjects.filter(parent__isnull=True)) return optimize_subject_query(Subject.objects.filter( parent__isnull=True, provider___id='osf', provider__type='osf.preprintprovider', ))
def top_level_subjects(self): if self.subjects.exists(): return optimize_subject_query(self.subjects.filter(parent__isnull=True)) else: # TODO: Delet this when all PreprintProviders have a mapping if len(self.subjects_acceptable) == 0: return optimize_subject_query(Subject.objects.filter(parent__isnull=True, provider___id='osf')) tops = set([sub[0][0] for sub in self.subjects_acceptable]) return [Subject.load(sub) for sub in tops]
def get_queryset(self): parent = self.request.query_params.get('filter[parents]', None) or self.request.query_params.get('filter[parent]', None) provider = get_object_or_error(PreprintProvider, self.kwargs['provider_id'], self.request, display_name='PreprintProvider') if parent: if parent == 'null': return provider.top_level_subjects if provider.subjects.exists(): return optimize_subject_query(provider.subjects.filter(parent___id=parent)) else: # TODO: Delet this when all PreprintProviders have a mapping # Calculate this here to only have to do it once. allowed_parents = [id_ for sublist in provider.subjects_acceptable for id_ in sublist[0]] allows_children = [subs[0][-1] for subs in provider.subjects_acceptable if subs[1]] return [sub for sub in optimize_subject_query(Subject.objects.filter(parent___id=parent)) if provider.subjects_acceptable == [] or self.is_valid_subject(allows_children=allows_children, allowed_parents=allowed_parents, sub=sub)] return optimize_subject_query(provider.all_subjects)
def get_queryset(self): provider = get_object_or_error(self._model_class, self.kwargs['provider_id'], self.request, display_name=self._model_class.__name__) return optimize_subject_query( Subject.objects.filter( id__in=[s.id for s in provider.highlighted_subjects]).order_by( 'text'))
def get_queryset(self): provider = get_object_or_error(PreprintProvider, self.kwargs['provider_id'], self.request, display_name='PreprintProvider') return optimize_subject_query( Subject.objects.filter( id__in=[s.id for s in provider.highlighted_subjects]).order_by( 'text'))
def get_subject(self, check_object_permissions=True): subject_id = self.kwargs[self.subject_lookup_url_kwarg] try: subject = optimize_subject_query( Subject.objects).get(_id=subject_id) except ObjectDoesNotExist: raise NotFound if check_object_permissions: self.check_object_permissions(self.request, subject) return subject
def get_default_queryset(self): return optimize_subject_query(Subject.objects.all())
def get_queryset(self): provider = get_object_or_error(self._model_class, self.kwargs['provider_id'], self.request, display_name=self._model_class.__name__) return optimize_subject_query(Subject.objects.filter(id__in=[s.id for s in provider.highlighted_subjects]).order_by('text'))
def get_object(self): try: return optimize_subject_query(Subject.objects).get(_id=self.kwargs['taxonomy_id']) except ObjectDoesNotExist: raise NotFound
def get_default_queryset(self): subject = self.get_subject() return optimize_subject_query(subject.children.all())
def top_level_subjects(self): if self.subjects.exists(): return optimize_subject_query( self.subjects.filter(parent__isnull=True))
def get_queryset(self): provider = get_object_or_error(PreprintProvider, self.kwargs['provider_id'], self.request, display_name='PreprintProvider') return optimize_subject_query(Subject.objects.filter(id__in=[s.id for s in provider.highlighted_subjects]).order_by('text'))
def get_object(self): try: return optimize_subject_query( Subject.objects).get(_id=self.kwargs['taxonomy_id']) except ObjectDoesNotExist: raise NotFound