def test_all_optional_data_to_add(self):
     form = CustomXlsForm({
         'required_entity': 'on',
         'proposition': 'on',
         'credits': 'on',
         'allocation_entity': 'on',
         'english_title': 'on',
         'teacher_list': 'on',
         'periodicity': 'on',
         'active': 'on',
         'volume': 'on',
         'quadrimester': 'on',
         'session_derogation': 'on',
         'language': 'on',
         'description_fiche': 'on',
         'specifications': 'on',
     })
     self.assertDictEqual(
         _optional_data(form), {
             'has_required_entity': True,
             'has_proposition': True,
             'has_credits': True,
             'has_allocation_entity': True,
             'has_english_title': True,
             'has_teacher_list': True,
             'has_periodicity': True,
             'has_active': True,
             'has_volume': True,
             'has_quadrimester': True,
             'has_session_derogation': True,
             'has_language': True,
             'has_description_fiche': True,
             'has_specifications': True,
         })
    def test_header_lines_with_optional_titles(self):
        custom_xls_form = CustomXlsForm({
            'required_entity': 'on',
            'allocation_entity': 'on',
            'credits': 'on',
            'periodicity': 'on',
            'active': 'on',
            'quadrimester': 'on',
            'session_derogation': 'on',
            'volume': 'on',
            'teacher_list': 'on',
            'proposition': 'on',
            'english_title': 'on',
            'language': 'on',
            'specifications': 'on',
            'description_fiche': 'on',
        })

        expected_headers = \
            FIX_TITLES + optional_header_for_required_entity + optional_header_for_allocation_entity +  \
            optional_header_for_credits + optional_header_for_periodicity + optional_header_for_active + \
            optional_header_for_quadrimester + optional_header_for_session_derogation + optional_header_for_volume + \
            optional_header_for_teacher_list + optional_header_for_proposition + optional_header_for_english_title + \
            optional_header_for_language + optional_header_for_specifications + optional_header_for_description_fiche
        self.assertListEqual(
            _get_headers(custom_xls_form)[0], expected_headers)
    def test_get_optional_has_specifications_annotate_called(self, mock):
        optional_data = initialize_optional_data()
        optional_data['has_specifications'] = True

        custom_form = CustomXlsForm({'specifications': 'on'})
        EducationGroupYearLearningUnitsContainedToExcel(
            self.education_group_year, custom_form)
        self.assertTrue(mock.called)
 def test_keep_UES_tree_order_in_qs(self):
     exl = EducationGroupYearLearningUnitsContainedToExcel(
         self.education_group_year, CustomXlsForm({}))
     expected_ids_following_tree_order = [
         lu.id for lu in exl.learning_unit_years_parent
     ]
     ids_ordered_for_xls = [lu.id for lu in list(exl.qs)]
     self.assertCountEqual(expected_ids_following_tree_order,
                           ids_ordered_for_xls)
Exemple #5
0
def generate_ue_contained_for_workbook(custom_xls_form: CustomXlsForm,
                                       qs: QuerySet):
    data = _build_excel_lines_ues(custom_xls_form, qs)
    need_proposal_legend = custom_xls_form.is_valid(
    ) and custom_xls_form.cleaned_data['proposition']

    return _get_workbook_for_custom_xls(data.get('content'),
                                        need_proposal_legend,
                                        data.get('colored_cells'),
                                        data.get('row_height'))
 def test_row_height_populated(self):
     custom_form = CustomXlsForm({'description_fiche': 'on'})
     exl = EducationGroupYearLearningUnitsContainedToExcel(
         self.education_group_year, custom_form)
     data = _build_excel_lines_ues(custom_form, exl.qs)
     self.assertDictEqual(data.get('row_height'), {
         'height': 30,
         'start': 2,
         'stop': 4
     })
 def test_data(self):
     custom_form = CustomXlsForm({})
     exl = EducationGroupYearLearningUnitsContainedToExcel(
         self.education_group_year, custom_form)
     data = _build_excel_lines_ues(custom_form,
                                   exl.learning_unit_years_parent)
     content = data.get('content')
     self._assert_content_equals(content, exl)
     # First line (Header line) is always bold
     self.assertListEqual(
         data.get('colored_cells')[Style(font=BOLD_FONT)], [0])
Exemple #8
0
def get_learning_units_of_training_for_excel(request, education_group_year_pk):
    education_group_year = get_object_or_404(EducationGroupYear,
                                             pk=education_group_year_pk)
    custom_xls_form = CustomXlsForm(request.POST or None)
    excel = EducationGroupYearLearningUnitsContainedToExcel(
        education_group_year, custom_xls_form).to_excel()
    response = HttpResponse(excel, content_type=CONTENT_TYPE_XLS)
    filename = "{workbook_name}.xlsx".format(workbook_name=str(
        _("LearningUnitList-%(year)s-%(acronym)s") % {
            "year": education_group_year.academic_year.year,
            "acronym": education_group_year.acronym
        }))
    response['Content-Disposition'] = "%s%s" % ("attachment; filename=",
                                                filename)
    return response
Exemple #9
0
    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)

        # This objects are mandatory for all education group views
        context['person'] = self.person

        # FIXME same param
        context['root'] = self.root
        context['root_id'] = self.root.pk
        context['parent'] = self.root
        context['parent_training'] = self.object.parent_by_training()
        context["show_identification"] = self.show_identification()
        context["show_diploma"] = self.show_diploma()
        context["show_general_information"] = self.show_general_information()
        context["show_skills_and_achievements"] = self.show_skills_and_achievements()
        context["show_administrative"] = self.show_administrative()
        context["show_content"] = self.show_content()
        context["show_utilization"] = self.show_utilization()
        context["show_admission_conditions"] = self.show_admission_conditions()
        if self.with_tree:
            # FIXME: resolve dependency in other way
            from program_management.business.group_element_years.group_element_year_tree import EducationGroupHierarchy
            education_group_hierarchy_tree = EducationGroupHierarchy(self.root,
                                                                     tab_to_show=self.request.GET.get('tab_to_show'))
            context['tree'] = json.dumps(education_group_hierarchy_tree.to_json())
        context['group_to_parent'] = self.request.GET.get("group_to_parent") or '0'
        context['can_change_education_group'] = perms.is_eligible_to_change_education_group(
            person=self.person,
            education_group=context['object'],
        )
        context['can_change_coorganization'] = perms.is_eligible_to_change_coorganization(
            person=self.person,
            education_group=context['object'],
        )
        context['enums'] = mdl.enums.education_group_categories
        context['current_academic_year'] = self.starting_academic_year
        context['selected_element_clipboard'] = self.get_selected_element_for_clipboard()
        context['form_xls_custom'] = CustomXlsForm()

        return context
Exemple #10
0
    def __init__(self, egy: EducationGroupYear,
                 custom_xls_form: CustomXlsForm):
        self.egy = egy
        self.hierarchy = EducationGroupHierarchy(root=self.egy)
        self.learning_unit_years_parent = []

        for grp in self.hierarchy.included_group_element_years:
            if not grp.child_leaf:
                continue
            self.learning_unit_years_parent.append(grp)
        self.custom_xls_form = custom_xls_form
        self._get_ordered_queryset()
        description_fiche = False
        specifications = False

        if custom_xls_form.is_valid():
            description_fiche = True if 'description_fiche' in custom_xls_form.fields else False
            specifications = True if 'specifications' in custom_xls_form.fields else False

        if description_fiche or specifications:
            self.qs = _annotate_with_description_fiche_specifications(
                self.qs, description_fiche, specifications)
    def setUpTestData(cls):
        cls.education_group_year = EducationGroupYearFactory()
        cls.child_leaves = GroupElementYearChildLeafFactory.create_batch(
            2, parent=cls.education_group_year, is_mandatory=True)
        for node, acronym in zip(
                cls.child_leaves,
            ["LCORS124" + str(i) for i in range(0, len(cls.child_leaves))]):
            node.child_leaf.acronym = acronym
            node.child_leaf.save()

        cls.luy_children = [child.child_leaf for child in cls.child_leaves]
        cls.workbook_contains = \
            EducationGroupYearLearningUnitsContainedToExcel(cls.education_group_year, CustomXlsForm({}))._to_workbook()
        cls.sheet_contains = cls.workbook_contains.worksheets[0]

        generator_container = GenerateContainer(
            cls.education_group_year.academic_year,
            cls.education_group_year.academic_year)
        cls.luy = generator_container.generated_container_years[
            0].learning_unit_year_full

        cls.lecturing_component = LecturingLearningComponentYearFactory(
            learning_unit_year=cls.luy)
        cls.practical_component = PracticalLearningComponentYearFactory(
            learning_unit_year=cls.luy)
        cls.person_1 = PersonFactory(last_name='Dupont',
                                     first_name="Marcel",
                                     email="*****@*****.**")
        cls.person_2 = PersonFactory(last_name='Marseillais',
                                     first_name="Pol",
                                     email="*****@*****.**")
        cls.tutor_1 = TutorFactory(person=cls.person_1)
        cls.tutor_2 = TutorFactory(person=cls.person_2)
        cls.attribution_1 = AttributionNewFactory(
            tutor=cls.tutor_1,
            learning_container_year=cls.luy.learning_container_year)
        cls.charge_lecturing = AttributionChargeNewFactory(
            attribution=cls.attribution_1,
            learning_component_year=cls.lecturing_component)
        cls.charge_practical = AttributionChargeNewFactory(
            attribution=cls.attribution_1,
            learning_component_year=cls.practical_component)
        cls.attribution_2 = AttributionNewFactory(
            tutor=cls.tutor_2,
            learning_container_year=cls.luy.learning_container_year)
        cls.charge_lecturing = AttributionChargeNewFactory(
            attribution=cls.attribution_2,
            learning_component_year=cls.lecturing_component)
        cls.charge_practical = AttributionChargeNewFactory(
            attribution=cls.attribution_2,
            learning_component_year=cls.practical_component)
        cls.gey = GroupElementYearChildLeafFactory(child_leaf=cls.luy)
 def test_row_height_not_populated(self):
     custom_form = CustomXlsForm({})
     exl = EducationGroupYearLearningUnitsContainedToExcel(
         self.education_group_year, custom_form)
     data = _build_excel_lines_ues(custom_form, exl.qs)
     self.assertDictEqual(data.get('row_height'), {})
    def test_header_lines_without_optional_titles(self):
        custom_xls_form = CustomXlsForm({})
        expected_headers = FIX_TITLES

        self.assertListEqual(
            _get_headers(custom_xls_form)[0], expected_headers)