Beispiel #1
0
def _get_learning_unit_yrs_on_2_different_years(academic_yr_comparison,
                                                learning_unit_years):
    learning_unit_years = LearningUnitYear.objects.filter(
        learning_unit__in=(_get_learning_units(learning_unit_years)),
        academic_year__year__in=(
            learning_unit_years[0].academic_year.year,
            academic_yr_comparison)).select_related(
                'academic_year', 'learning_container_year',
                'learning_container_year__academic_year').prefetch_related(
                    get_learning_component_prefetch()).prefetch_related(
                        build_entity_container_prefetch(
                            entity_types.ALLOCATION_ENTITY),
                        build_entity_container_prefetch(
                            entity_types.REQUIREMENT_ENTITY),
                        build_entity_container_prefetch(
                            entity_types.ADDITIONAL_REQUIREMENT_ENTITY_1),
                        build_entity_container_prefetch(
                            entity_types.ADDITIONAL_REQUIREMENT_ENTITY_2),
                    ).order_by('learning_unit', 'academic_year__year')
    [
        append_latest_entities(learning_unit)
        for learning_unit in learning_unit_years
    ]
    [append_components(learning_unit) for learning_unit in learning_unit_years]
    return learning_unit_years
Beispiel #2
0
    def get_learning_units_and_summary_status(self,
                                              requirement_entities=None,
                                              luy_status=None):
        self.cleaned_data['status'] = self._set_status(luy_status)

        if requirement_entities:
            self.cleaned_data['requirement_entities'] = requirement_entities

        queryset = self.get_queryset()
        if self.cleaned_data and queryset.count() > self.MAX_RECORDS:
            raise TooManyResultsException

        queryset = queryset.prefetch_related(
            build_entity_container_prefetch(
                entity_container_year_link_type.ALLOCATION_ENTITY),
            build_entity_container_prefetch(
                entity_container_year_link_type.REQUIREMENT_ENTITY),
            Prefetch(
                'attribution_set',
                queryset=Attribution.objects.filter(summary_responsible=True),
                to_attr='summary_responsibles'))

        cms_list = TranslatedText.objects.filter(
            entity=LEARNING_UNIT_YEAR,
            text_label__label__in=CMS_LABEL_PEDAGOGY,
            changed__isnull=False,
            reference__in=queryset.values_list(
                'pk', flat=True)).select_related('text_label')

        for learning_unit_yr in queryset:
            append_latest_entities(learning_unit_yr)
            _set_summary_status_on_luy(cms_list, learning_unit_yr)

        return queryset
Beispiel #3
0
    def filter_queryset(self, queryset):
        qs = super().filter_queryset(queryset)
        qs = qs.prefetch_related(
            build_entity_container_prefetch(entity_container_year_link_type.ALLOCATION_ENTITY),
            build_entity_container_prefetch(entity_container_year_link_type.REQUIREMENT_ENTITY),
        )

        for luy in qs:
            append_latest_entities(luy, service_course_search=True)

        return qs.filter(pk__in=[lu.pk for lu in qs if lu.entities.get(SERVICE_COURSE)])
Beispiel #4
0
    def get_learning_units(self, service_course_search=None, requirement_entities=None, luy_status=None):
        service_course_search = service_course_search or self.service_course_search
        clean_data = self.cleaned_data
        clean_data['status'] = self._set_status(luy_status)

        if requirement_entities:
            clean_data['requirement_entities'] = requirement_entities

        # TODO Use a queryset instead !!
        clean_data['learning_container_year_id'] = get_filter_learning_container_ids(clean_data)

        if not service_course_search \
                and clean_data \
                and mdl.learning_unit_year.count_search_results(**clean_data) > SearchForm.MAX_RECORDS:
            raise TooManyResultsException

        learning_units = mdl.learning_unit_year.search(**clean_data) \
            .select_related('academic_year', 'learning_container_year',
                            'learning_container_year__academic_year') \
            .prefetch_related(build_entity_container_prefetch()) \
            .order_by('academic_year__year', 'acronym')

        # FIXME We must keep a queryset
        return [append_latest_entities(learning_unit, service_course_search) for learning_unit in
                learning_units]
Beispiel #5
0
    def get_learning_units_and_summary_status(self, requirement_entities=None, luy_status=None):
        self.cleaned_data['status'] = self._set_status(luy_status)

        if requirement_entities:
            self.cleaned_data['requirement_entities'] = requirement_entities

        queryset = self.get_queryset()
        if self.cleaned_data and queryset.count() > self.MAX_RECORDS:
            raise TooManyResultsException

        queryset = queryset.prefetch_related(
            build_entity_container_prefetch([
                entity_container_year_link_type.ALLOCATION_ENTITY,
                entity_container_year_link_type.REQUIREMENT_ENTITY
            ]),
            Prefetch(
                'attribution_set',
                queryset=Attribution.objects.filter(summary_responsible=True),
                to_attr='summary_responsibles'
            )
        )

        cms_list = TranslatedText.objects.filter(
            entity=LEARNING_UNIT_YEAR,
            text_label__label__in=CMS_LABEL_PEDAGOGY,
            changed__isnull=False,
            reference__in=queryset.values_list('pk', flat=True)
        ).select_related('text_label')

        for learning_unit_yr in queryset:
            append_latest_entities(learning_unit_yr)
            _set_summary_status_on_luy(cms_list, learning_unit_yr)

        return queryset
Beispiel #6
0
def get_list_entity_learning_unit_yr(an_entity_version, current_academic_yr):
    entity_ids = get_entities_ids(an_entity_version.entity.most_recent_acronym,
                                  False)
    entities_id_list = get_entity_container_list(
        [], entity_ids, entity_container_year_link_type.REQUIREMENT_ENTITY)

    return learning_unit_year.search(**{'learning_container_year_id': entities_id_list,
                                        'academic_year_id': current_academic_yr,
                                        'status': True}) \
        .select_related('academic_year', 'learning_container_year',
                        'learning_container_year__academic_year') \
        .prefetch_related(build_entity_container_prefetch()) \
        .order_by('academic_year__year', 'acronym')
Beispiel #7
0
def _get_learning_unit_yr_with_component(learning_unit_years):
    learning_unit_years = LearningUnitYear.objects.filter(
        learning_unit_year_id__in=[luy.id for luy in learning_unit_years]
    ).select_related(
        'academic_year', 'learning_container_year',
        'learning_container_year__academic_year').prefetch_related(
            get_learning_component_prefetch()).prefetch_related(
                build_entity_container_prefetch(
                    entity_types.ALLOCATION_ENTITY),
                build_entity_container_prefetch(
                    entity_types.REQUIREMENT_ENTITY),
                build_entity_container_prefetch(
                    entity_types.ADDITIONAL_REQUIREMENT_ENTITY_1),
                build_entity_container_prefetch(
                    entity_types.ADDITIONAL_REQUIREMENT_ENTITY_2),
            ).order_by('learning_unit', 'academic_year__year')
    [
        append_latest_entities(learning_unit)
        for learning_unit in learning_unit_years
    ]
    [append_components(learning_unit) for learning_unit in learning_unit_years]
    return learning_unit_years
Beispiel #8
0
    def get_learning_units(self, service_course_search=None):
        service_course_search = service_course_search or self.service_course_search

        learning_units = self.get_queryset()

        if not service_course_search and self.cleaned_data and learning_units.count(
        ) > self.MAX_RECORDS:
            raise TooManyResultsException

        if self.borrowed_course_search:
            learning_units = self._filter_borrowed_learning_units(
                learning_units)

        learning_units = learning_units.prefetch_related(
            build_entity_container_prefetch(
                entity_container_year_link_type.ALLOCATION_ENTITY),
            build_entity_container_prefetch(
                entity_container_year_link_type.REQUIREMENT_ENTITY),
        )
        for learning_unit in learning_units:
            append_latest_entities(learning_unit, service_course_search)

        return learning_units
Beispiel #9
0
def _get_learning_unit_yr_with_component(learning_unit_years):
    learning_unit_years = LearningUnitYear.objects.filter(
        learning_unit_year_id__in=[luy.id for luy in learning_unit_years]
        ).select_related(
        'academic_year',
        'learning_container_year',
        'learning_container_year__academic_year'
    ).prefetch_related(
        get_learning_component_prefetch()
    ).prefetch_related(
        build_entity_container_prefetch([
            entity_types.ALLOCATION_ENTITY,
            entity_types.REQUIREMENT_ENTITY,
            entity_types.ADDITIONAL_REQUIREMENT_ENTITY_1,
            entity_types.ADDITIONAL_REQUIREMENT_ENTITY_2
        ])
    ).order_by('learning_unit', 'academic_year__year')
    [append_latest_entities(learning_unit) for learning_unit in learning_unit_years]
    [append_components(learning_unit) for learning_unit in learning_unit_years]
    return learning_unit_years
Beispiel #10
0
    def get_queryset(self):
        """ Filter a LearningUnitYearQueryset """
        has_proposal = ProposalLearningUnit.objects.filter(
            learning_unit_year=OuterRef('pk'),
        )

        learning_units = mdl.learning_unit_year.search(**self.cleaned_data)
        learning_units = self.get_filter_learning_container_ids(learning_units)

        learning_units = learning_units.select_related(
            'academic_year', 'learning_container_year__academic_year') \
            .prefetch_related(
                build_entity_container_prefetch([
                    entity_container_year_link_type.ALLOCATION_ENTITY,
                    entity_container_year_link_type.REQUIREMENT_ENTITY
                ])
            ).order_by('academic_year__year', 'acronym').annotate(has_proposal=Exists(has_proposal))

        learning_units = self.get_filter_learning_container_ids(learning_units)

        return learning_units
Beispiel #11
0
    def get_learning_units(self, service_course_search=None):
        service_course_search = service_course_search or self.service_course_search

        learning_units = self.get_queryset()
        if not service_course_search and self.cleaned_data and learning_units.count() > self.MAX_RECORDS:
            raise TooManyResultsException

        learning_units = learning_units.prefetch_related(
            build_entity_container_prefetch([
                entity_container_year_link_type.ALLOCATION_ENTITY,
                entity_container_year_link_type.REQUIREMENT_ENTITY
            ])
        )

        if self.borrowed_course_search:
            # TODO must return a queryset
            learning_units = list(self._filter_borrowed_learning_units(learning_units))

        for learning_unit in learning_units:
            append_latest_entities(learning_unit, service_course_search)

        return learning_units
Beispiel #12
0
def _get_learning_unit_yrs_on_2_different_years(academic_yr_comparison, learning_unit_years):
    learning_unit_years = LearningUnitYear.objects.filter(
        learning_unit__in=(_get_learning_units(learning_unit_years)),
        academic_year__year__in=(
            learning_unit_years[0].academic_year.year,
            academic_yr_comparison)
    ).select_related(
        'academic_year',
        'learning_container_year',
        'learning_container_year__academic_year'
    ).prefetch_related(
        get_learning_component_prefetch()
    ).prefetch_related(
        build_entity_container_prefetch([
            entity_types.ALLOCATION_ENTITY,
            entity_types.REQUIREMENT_ENTITY,
            entity_types.ADDITIONAL_REQUIREMENT_ENTITY_1,
            entity_types.ADDITIONAL_REQUIREMENT_ENTITY_2
        ])
    ).order_by('learning_unit', 'academic_year__year')
    [append_latest_entities(learning_unit) for learning_unit in learning_unit_years]
    [append_components(learning_unit) for learning_unit in learning_unit_years]
    return learning_unit_years