Esempio n. 1
0
    def list(self, request, *args, **kwargs):
        school = request.GET.get("school", 0)

        queryset = self.queryset.filter(school_id=school)
        data = tablib.Dataset()
        data.headers = [
            _('Student number'),
            _('Student fullname'),
            _('Mother fullname'),
        ]

        content = []
        for line in queryset:
            content = [
                line.student.number,
                line.student.__unicode__(),
                line.student.mother_fullname,
            ]
            data.append(content)

        file_format = base_formats.XLS()
        # response = HttpResponse(
        #     file_format.export_data(data),
        #     content_type='application/vnd.ms-excel',
        # )
        # response['Content-Disposition'] = 'attachment; filename=registration_list.xls'
        return JsonResponse({'status': status.HTTP_200_OK})
Esempio n. 2
0
    def get(self, request, *args, **kwargs):

        classrooms = ClassRoom.objects.all()
        schools = self.queryset.values_list(
            'school',
            'school__number',
            'school__name',
            'school__location__name',
            'school__location__parent__name',
        ).distinct().order_by('school__number')

        data = tablib.Dataset()
        data.headers = [
            _('CERD'),
            _('School name'),
            _('# Students registered in the Compiler'),
            'Class name',
            '# Students registered in class',
            _('District'),
            _('Governorate'),
        ]

        queryset = self.queryset.filter(education_year__current_year=True)

        content = []
        for school in schools:
            enrollments = queryset.filter(school=school[0])
            nbr = enrollments.count()
            for cls in classrooms:
                nbr_cls = enrollments.filter(classroom=cls).count()
                if not nbr_cls:
                    pass

                content = [
                    school[1], school[2], nbr, cls.name, nbr_cls, school[3],
                    school[4]
                ]
                data.append(content)

        file_format = base_formats.XLS()
        response = HttpResponse(
            file_format.export_data(data),
            content_type='application/vnd.ms-excel',
        )
        response[
            'Content-Disposition'] = 'attachment; filename=student_by_cycle.xls'
        return response
Esempio n. 3
0
    def get(self, request, *args, **kwargs):

        alp_round = ALPRound.objects.get(current_pre_test=True)

        schools = self.queryset.filter(
            alp_round=alp_round,
            registered_in_level__isnull=False).values_list(
                'school',
                'school__number',
                'school__name',
                'school__location__name',
                'school__location__parent__name',
                'school__number_students_alp',
            ).distinct().order_by('school__number')

        data = tablib.Dataset()
        data.headers = [
            _('CERD'),
            _('School name'),
            _('# Students registered in the Compiler'),
            _('# Students reported by the Director'),
            _('District'),
            _('Governorate'),
        ]

        content = []
        for school in schools:
            nbr = self.model.objects.filter(
                school=school[0],
                alp_round=alp_round,
                registered_in_level__isnull=False).count()
            content = [
                school[1], school[2], nbr, school[5], school[3], school[4]
            ]
            data.append(content)

        file_format = base_formats.XLS()
        response = HttpResponse(
            file_format.export_data(data),
            content_type='application/vnd.ms-excel',
        )
        response[
            'Content-Disposition'] = 'attachment; filename=student_by_school.xls'
        return response
Esempio n. 4
0
    def get(self, request, *args, **kwargs):

        schools = self.queryset.values_list(
            'school',
            'school__number',
            'school__name',
            'school__location__name',
            'school__location__parent__name',
            'school__number_students_2nd_shift',
        ).distinct().order_by('school__number')

        data = tablib.Dataset()
        data.headers = [
            _('CERD'),
            _('School name'),
            _('# Students registered in the Compiler'),
            _('# Students reported by the Director'),
            _('District'),
            _('Governorate'),
        ]

        queryset = self.queryset.filter(education_year__current_year=True)

        content = []
        for school in schools:
            nbr = queryset.filter(school=school[0]).count()
            content = [
                school[1], school[2], nbr, school[5], school[3], school[4]
            ]
            data.append(content)

        file_format = base_formats.XLS()
        response = HttpResponse(
            file_format.export_data(data),
            content_type='application/vnd.ms-excel',
        )
        response[
            'Content-Disposition'] = 'attachment; filename=student_by_school.xls'
        return response
 def test_binary_format(self):
     self.assertTrue(base_formats.XLS().is_binary())
Esempio n. 6
0
    def get(self, request, *args, **kwargs):
        queryset = self.model.objects.all()
        school = int(request.GET.get('school', 0))
        location = int(request.GET.get('location', 0))
        alp_round = ALPRound.objects.get(current_round=True)

        if has_group(self.request.user, 'PARTNER'):
            alp_round = ALPRound.objects.get(current_pre_test=True)
            queryset = queryset.filter(owner=self.request.user, alp_round=alp_round)
        if has_group(self.request.user, 'ALP_SCHOOL') and self.request.user.school_id:
            school = self.request.user.school_id
        if school:
            queryset = queryset.filter(school_id=school, alp_round=alp_round).order_by('id')
        if location:
            queryset = queryset.filter(school__location_id=location, alp_round=alp_round).order_by('id')

        data = tablib.Dataset()

        data.headers = [
            _('ALP result'),
            _('ALP round'),
            _('ALP level'),
            _('Is the child participated in an ALP program'),

            _('Education year'),
            _('Last education level'),

            _('Phone prefix'),
            _('Phone number'),
            _('Student living address'),

            _('Student ID Number'),
            _('Student ID Type'),
            _('Registered in UNHCR'),

            _('Mother nationality'),
            _('Mother fullname'),

            _('Current Section'),
            _('Current Level'),

            _('Post-test result'),
            _('Assigned to level'),
            _('Pre-test result'),

            _('Student nationality'),
            _('Student age'),
            _('Student birthday'),
            _('Sex'),
            _('Student fullname'),

            _('School'),
            _('School number'),
            _('District'),
            _('Governorate'),
        ]

        content = []
        for line in queryset:
            if not line.student or not line.school:
                continue
            content = [
                line.last_informal_edu_final_result.name if line.last_informal_edu_final_result else '',
                line.last_informal_edu_round.name if line.last_informal_edu_round else '',
                line.last_informal_edu_level.name if line.last_informal_edu_level else '',
                _(line.participated_in_alp) if line.participated_in_alp else '',

                line.last_education_year,
                line.last_education_level.name if line.last_education_level else '',

                line.student.phone_prefix,
                line.student.phone,
                line.student.address,

                line.student.id_number,
                line.student.id_type.name if line.student.id_type else '',
                _(line.registered_in_unhcr) if line.registered_in_unhcr else '',

                line.student.mother_nationality.name if line.student.mother_nationality else '',
                line.student.mother_fullname,

                line.section.name if line.section else '',
                line.registered_in_level.name if line.registered_in_level else '',

                line.post_exam_total,
                line.assigned_to_level.name if line.assigned_to_level else '',
                line.exam_total,

                line.student.nationality_name(),
                line.student.calc_age,
                line.student.birthday,
                _(line.student.sex),
                line.student.__unicode__(),

                line.school.name,
                line.school.number,
                line.school.location.name,
                line.school.location.parent.name,
            ]
            data.append(content)

        file_format = base_formats.XLS()
        response = HttpResponse(
            file_format.export_data(data),
            content_type='application/application/ms-excel',
        )
        response['Content-Disposition'] = 'attachment; filename=outreach_list.xls'
        return response
 def setUp(self):
     self.format = base_formats.XLS()