Exemple #1
0
    def get_queryset(self):
        # Need this close so as to return empty query by default when form is unbound
        if not self.data:
            return LearningUnitYear.objects.none()

        has_proposal = ProposalLearningUnit.objects.filter(
            learning_unit_year=OuterRef('pk'), )

        qs = LearningUnitYear.objects_with_container.filter(
            externallearningunityear__co_graduation=True,
            externallearningunityear__mobility=False,
        ).select_related(
            'academic_year',
            'learning_container_year__academic_year',
            'language',
            'externallearningunityear',
            'campus',
            'proposallearningunit',
            'campus__organization',
        ).prefetch_related("learningcomponentyear_set").annotate(
            has_proposal=Exists(has_proposal)).order_by(
                'academic_year__year', 'acronym')

        qs = LearningUnitYearQuerySet.annotate_full_title_class_method(qs)
        qs = LearningUnitYearQuerySet.annotate_entities_allocation_and_requirement_acronym(
            qs)
        return qs
    def get_queryset(self):
        # Need this close so as to return empty query by default when form is unbound
        if not self.data:
            return LearningUnitYear.objects.none()

        entity_folder = EntityVersion.objects.filter(
            entity=OuterRef('proposallearningunit__entity'), ).current(
                OuterRef('academic_year__start_date')).values('acronym')[:1]

        has_proposal = ProposalLearningUnit.objects.filter(
            learning_unit_year=OuterRef('pk'), )

        queryset = LearningUnitYear.objects_with_container.filter(
            proposallearningunit__isnull=False).select_related(
                'academic_year',
                'learning_container_year__academic_year',
                'language',
                'externallearningunityear',
                'campus',
                'proposallearningunit',
                'campus__organization',
            ).prefetch_related("learningcomponentyear_set", ).annotate(
                has_proposal=Exists(has_proposal),
                entity_folder=Subquery(entity_folder),
            )

        queryset = LearningUnitYearQuerySet.annotate_full_title_class_method(
            queryset)
        queryset = LearningUnitYearQuerySet.annotate_entities_allocation_and_requirement_acronym(
            queryset)

        return queryset
Exemple #3
0
    def filter_queryset(self, queryset):
        queryset = queryset.filter(academic_year=self.academic_year).annotate(
            full_title=Case(
                When(Q(learning_container_year__common_title__isnull=True)
                     | Q(learning_container_year__common_title__exact=''),
                     then='specific_title'),
                When(Q(specific_title__isnull=True)
                     | Q(specific_title__exact=''),
                     then='learning_container_year__common_title'),
                default=Concat('learning_container_year__common_title',
                               Value(' - '), 'specific_title'),
                output_field=CharField(),
            ))
        queryset = business_scores_responsible.filter_learning_unit_year_according_person(
            queryset,
            self.request.user.person,
        )
        queryset = super().filter_queryset(queryset)

        entity_requirement = EntityVersion.objects.filter(entity=OuterRef(
            'learning_container_year__requirement_entity'), ).current(
                OuterRef('academic_year__start_date')).values('acronym')[:1]
        queryset = LearningUnitYearQuerySet.annotate_entities_allocation_and_requirement_acronym(
            queryset)
        return queryset.select_related(
            'learning_container_year').prefetch_related(
                Prefetch(
                    'attribution_set',
                    queryset=Attribution.objects.all(
                    ).select_related('tutor__person').order_by(
                        '-score_responsible', 'tutor__person__last_name',
                        'tutor__person__first_name'))).annotate(
                            requirement_entity=Subquery(entity_requirement))
Exemple #4
0
 def get_queryset(self):
     # Need this close so as to return empty query by default when form is unbound
     if not self.data:
         return LearningUnitYear.objects.none()
     queryset = LearningUnitYear.objects_with_container.select_related(
         'academic_year', )
     queryset = LearningUnitYearQuerySet.annotate_full_title_class_method(
         queryset)
     return queryset
Exemple #5
0
    def get_queryset(self):
        # Need this close so as to return empty query by default when form is unbound
        if not self.data:
            return LearningUnitYear.objects.none()

        has_proposal = ProposalLearningUnit.objects.filter(
            learning_unit_year=OuterRef('pk'),
        )

        queryset = LearningUnitYear.objects_with_container.select_related(
            'academic_year',
            'learning_container_year__academic_year',
            'language',
            'proposallearningunit',
            'externallearningunityear'
        ).order_by('academic_year__year', 'acronym').annotate(
            has_proposal=Exists(has_proposal),
        )
        queryset = LearningUnitYearQuerySet.annotate_full_title_class_method(queryset)
        queryset = LearningUnitYearQuerySet.annotate_entities_allocation_and_requirement_acronym(queryset)
        return queryset
    def test_get_results_external_ue(self):
        ExternalLearningUnitYearFactory(learning_unit_year=self.luy)
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        luy_with_full_title = LearningUnitYear.objects.filter(
            pk=self.luy.pk).annotate_full_title()
        luy_with_full_title = LearningUnitYearQuerySet.annotate_entities_allocation_and_requirement_acronym(
            luy_with_full_title).get()
        serializer = ExternalLearningUnitDetailedSerializer(
            luy_with_full_title,
            context={
                'request': RequestFactory().get(self.url),
                'language': settings.LANGUAGE_CODE
            })
        self.assertEqual(response.data, serializer.data)