Ejemplo n.º 1
0
 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)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 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)
Ejemplo n.º 4
0
 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',
     ))
Ejemplo n.º 5
0
 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',
     ))
Ejemplo n.º 6
0
 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]
Ejemplo n.º 7
0
 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]
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
 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'))
Ejemplo n.º 10
0
 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'))
Ejemplo n.º 11
0
    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
Ejemplo n.º 12
0
 def get_default_queryset(self):
     return optimize_subject_query(Subject.objects.all())
Ejemplo n.º 13
0
 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'))
Ejemplo n.º 14
0
 def get_object(self):
     try:
         return optimize_subject_query(Subject.objects).get(_id=self.kwargs['taxonomy_id'])
     except ObjectDoesNotExist:
         raise NotFound
Ejemplo n.º 15
0
 def get_default_queryset(self):
     return optimize_subject_query(Subject.objects.all())
Ejemplo n.º 16
0
 def get_default_queryset(self):
     subject = self.get_subject()
     return optimize_subject_query(subject.children.all())
Ejemplo n.º 17
0
 def top_level_subjects(self):
     if self.subjects.exists():
         return optimize_subject_query(
             self.subjects.filter(parent__isnull=True))
Ejemplo n.º 18
0
 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'))
Ejemplo n.º 19
0
 def get_object(self):
     try:
         return optimize_subject_query(
             Subject.objects).get(_id=self.kwargs['taxonomy_id'])
     except ObjectDoesNotExist:
         raise NotFound