def test_prepare_xls_content(self): qs = LearningUnitYear.objects.filter( pk=self.learning_unit_yr_1.pk).annotate( entity_requirement=Subquery(self.entity_requirement), entity_allocation=Subquery(self.entity_allocation), ) result = prepare_xls_content(qs, with_grp=True, with_attributions=True) self.assertEqual(len(result), 1) luy = annotate_qs(qs).get() self.assertListEqual(result[0], self._get_luy_expected_data(luy))
def test_prepare_xls_content(self): entity_requirement = EntityVersion.objects.filter(entity=OuterRef( 'learning_container_year__requirement_entity'), ).current( OuterRef('academic_year__start_date')).values('acronym')[:1] entity_allocation = EntityVersion.objects.filter(entity=OuterRef( 'learning_container_year__allocation_entity'), ).current( OuterRef('academic_year__start_date')).values('acronym')[:1] qs = LearningUnitYear.objects.filter( pk=self.learning_unit_yr_1.pk).annotate( entity_requirement=Subquery(entity_requirement), entity_allocation=Subquery(entity_allocation), ) result = prepare_xls_content(qs, with_grp=True, with_attributions=True) self.assertEqual(len(result), 1) luy = annotate_qs(qs).get() self.assertListEqual( result[0], [ luy.acronym, luy.academic_year.__str__(), luy.complete_title, luy.get_container_type_display(), luy.get_subtype_display(), luy.entity_requirement, '', # Proposal '', # Proposal state luy.credits, luy.entity_allocation, luy.complete_title_english, '', luy.get_periodicity_display(), yesno(luy.status), _get_significant_volume(luy.pm_vol_tot or 0), _get_significant_volume(luy.pm_vol_q1 or 0), _get_significant_volume(luy.pm_vol_q2 or 0), luy.pm_classes or 0, _get_significant_volume(luy.pp_vol_tot or 0), _get_significant_volume(luy.pp_vol_q1 or 0), _get_significant_volume(luy.pp_vol_q2 or 0), luy.pp_classes or 0, luy.get_quadrimester_display() or '', luy.get_session_display() or '', luy.language or "", "{} ({}) - {} - {}\n".format( self.an_education_group_parent.partial_acronym, "{0:.2f}".format( luy.credits), self.an_education_group_parent.acronym, self.an_education_group_parent.title) ])
def _get_optional_data(data, luy, optional_data_needed, gey): if optional_data_needed['has_required_entity']: data.append(luy.learning_container_year.requirement_entity) if optional_data_needed['has_allocation_entity']: data.append(luy.learning_container_year.allocation_entity) if optional_data_needed['has_credits']: data.append(gey.relative_credits or '-') data.append(luy.credits.to_integral_value() or '-') if optional_data_needed['has_periodicity']: data.append(luy.get_periodicity_display()) if optional_data_needed['has_active']: data.append(str.strip(yesno(luy.status))) if optional_data_needed['has_quadrimester']: data.append(luy.get_quadrimester_display() or '') if optional_data_needed['has_session_derogation']: data.append(luy.get_session_display() or '') if optional_data_needed['has_volume']: luys = annotate_qs(LearningUnitYear.objects.filter(id=luy.id)) data.extend(volume_information(luys[0])) if optional_data_needed['has_teacher_list']: attribution_values = attribution_charge_new.find_attribution_charge_new_by_learning_unit_year_as_dict( luy).values() data.append(";".join([ _get_attribution_line(value.get('person')) for value in attribution_values ])) data.append(";".join( [value.get('person').email for value in attribution_values])) if optional_data_needed['has_proposition']: proposal = find_by_learning_unit_year(luy) if proposal: data.append(proposal.get_type_display()) data.append(proposal.get_state_display()) else: data.append('') data.append('') if optional_data_needed['has_english_title']: data.append(luy.complete_title_english) if optional_data_needed['has_language']: data.append(luy.language) if optional_data_needed['has_specifications']: specifications_data = _build_specifications_cols(luy, gey) for k, v in zip(specifications_data._fields, specifications_data): data.append(v) if optional_data_needed['has_description_fiche']: description_fiche = _build_description_fiche_cols(luy, gey) for k, v in zip(description_fiche._fields, description_fiche): data.append(v) return data
def test_get_data_part2(self): learning_container_luy = LearningContainerYearFactory(academic_year=self.current_academic_year) luy = LearningUnitYearFactory(academic_year=self.current_academic_year, learning_container_year=learning_container_luy, periodicity=learning_unit_year_periodicity.ANNUAL, status=True, language=None, ) component_lecturing = LearningComponentYearFactory( learning_unit_year=luy, type=learning_component_year_type.LECTURING, hourly_volume_total_annual=15, hourly_volume_partial_q1=10, hourly_volume_partial_q2=5, planned_classes=1 ) component_practical = LearningComponentYearFactory( learning_unit_year=luy, type=learning_component_year_type.PRACTICAL_EXERCISES, hourly_volume_total_annual=15, hourly_volume_partial_q1=10, hourly_volume_partial_q2=5, planned_classes=1 ) a_tutor = TutorFactory() an_attribution = AttributionNewFactory( tutor=a_tutor, start_year=2017 ) attribution_charge_new_lecturing = AttributionChargeNewFactory(learning_component_year=component_lecturing, attribution=an_attribution, allocation_charge=15.0) attribution_charge_new_practical = AttributionChargeNewFactory(learning_component_year=component_practical, attribution=an_attribution, allocation_charge=5.0) # Simulate annotate luy = annotate_qs(LearningUnitYear.objects.filter(pk=luy.pk)).first() luy.entity_requirement = EntityVersionFactory() luy.attribution_charge_news = attribution_charge_new.find_attribution_charge_new_by_learning_unit_year_as_dict( luy) expected_common = [ str(_(luy.periodicity.title())), str(_('yes')) if luy.status else str(_('no')), component_lecturing.hourly_volume_total_annual, component_lecturing.hourly_volume_partial_q1, component_lecturing.hourly_volume_partial_q2, component_lecturing.planned_classes, component_practical.hourly_volume_total_annual, component_practical.hourly_volume_partial_q1, component_practical.hourly_volume_partial_q2, component_practical.planned_classes, luy.get_quadrimester_display() or '', luy.get_session_display() or '', "", ] self.assertEqual(_get_data_part2(luy, False), expected_common) self.assertEqual( _get_data_part2(luy, True), expected_attribution_data( attribution_charge_new_lecturing, attribution_charge_new_practical, expected_common, luy ) )
def prepare_xls_educational_information_and_specifications( learning_unit_years, request): qs = annotate_qs(learning_unit_years) user_language = get_user_interface_language(request.user) result = [] for learning_unit_yr in qs: translated_labels_with_text = _get_translated_labels_with_text( learning_unit_yr.id, user_language) teaching_materials = TeachingMaterial.objects.filter( learning_unit_year=learning_unit_yr).order_by('order') line = [ learning_unit_yr.acronym, learning_unit_yr.complete_title, learning_unit_yr.entity_requirement, ] for label_key in CMS_LABEL_PEDAGOGY_FR_AND_EN: translated_label = translated_labels_with_text.filter( text_label__label=label_key).first() if translated_label: line.append( get_html_to_text(translated_label.text_label.text_fr[0]. text ) if translated_label.text_label.text_fr and translated_label.text_label.text_fr[0].text else '') line.append( get_html_to_text(translated_label.text_label.text_en[0]. text ) if translated_label.text_label.text_en and translated_label.text_label.text_en[0].text else '') else: line.append('') line.append('') if teaching_materials: line.append("\n".join([ get_html_to_text(teaching_material.title) for teaching_material in teaching_materials ])) else: line.append('') for label_key in CMS_LABEL_PEDAGOGY_FR_ONLY: translated_label = translated_labels_with_text.filter( text_label__label=label_key).first() if translated_label: line.append( get_html_to_text(translated_label.text_label.text_fr[0]. text ) if translated_label.text_label.text_fr and translated_label.text_label.text_fr[0].text else '') else: line.append('') _add_specifications(learning_unit_yr, line, request) line.extend(_add_achievements(learning_unit_yr)) result.append(line) return result