def put(self, request, *args, **kwargs):
        queryset = self.get_queryset()
        serializer = self.get_serializer(queryset, data=request.data, many=True)
        serializer.is_valid(raise_exception=True)
        serializer.save()

        update_last_change_in_catalog(self.request.user.user_profile)

        return Response(serializer.data)
Esempio n. 2
0
    def update(self, instance, validated_data):
        instance = super().update(instance, validated_data)

        change_averages_after_examination_grade_operation(
            [instance.catalog_per_subject], instance.grade_type,
            instance.semester)
        update_last_change_in_catalog(
            self.context['request'].user.user_profile)

        return instance
Esempio n. 3
0
    def create(self, validated_data):
        catalog = self.context['catalog']

        instance = SubjectAbsence.objects.create(
            catalog_per_subject=catalog,
            student=catalog.student,
            subject_name=catalog.subject_name,
            academic_year=catalog.academic_year,
            **validated_data)
        change_absences_counts_on_add(catalog, instance)

        update_last_change_in_catalog(
            self.context['request'].user.user_profile)
        return instance
Esempio n. 4
0
    def create(self, validated_data):
        catalog = self.context['catalog']
        instance = super().create({
            'catalog_per_subject': catalog,
            'student_id': catalog.student_id,
            'subject_name': catalog.subject_name,
            'academic_year': catalog.academic_year,
            **validated_data
        })

        compute_averages([catalog], instance.semester)
        update_last_change_in_catalog(
            self.context['request'].user.user_profile)
        return instance
Esempio n. 5
0
    def create(self, validated_data):
        catalog = self.context['catalog']
        instance = ExaminationGrade.objects.create(
            catalog_per_subject=catalog,
            student_id=catalog.student_id,
            subject_name=catalog.subject_name,
            academic_year=catalog.academic_year,
            **validated_data)

        change_averages_after_examination_grade_operation([catalog],
                                                          instance.grade_type,
                                                          instance.semester)
        update_last_change_in_catalog(
            self.context['request'].user.user_profile)
        return instance
Esempio n. 6
0
    def delete(self, request, *args, **kwargs):
        error = self.check_grade_can_be_edited()
        if error:
            return error

        instance = self.get_object()
        instance.delete()

        change_averages_after_examination_grade_operation(
            [instance.catalog_per_subject], instance.grade_type,
            instance.semester)
        update_last_change_in_catalog(request.user.user_profile)

        return Response(
            StudentCatalogPerSubjectSerializer(
                instance.catalog_per_subject).data)
Esempio n. 7
0
    def delete(self, request, *args, **kwargs):
        instance = self.get_object()
        catalog = instance.catalog_per_subject

        if catalog.is_coordination_subject:
            return Response(
                {'message': _("Can't delete coordination subject grade.")},
                status=status.HTTP_400_BAD_REQUEST)

        error = self.check_grade_can_be_edited()
        if error:
            return error

        instance.delete()

        compute_averages([catalog], instance.semester)
        update_last_change_in_catalog(request.user.user_profile)
        return Response(StudentCatalogPerSubjectSerializer(catalog).data)
Esempio n. 8
0
    def create(self, validated_data):
        taken_at = validated_data['taken_at']
        semester = validated_data['semester']
        student_absences = validated_data['student_absences']

        instances_to_create = []
        for student_absence in student_absences:
            instances_to_create.append(
                SubjectAbsence(subject_name=self.context['subject'].name,
                               semester=semester,
                               taken_at=taken_at,
                               **student_absence))

        instances = SubjectAbsence.objects.bulk_create(instances_to_create)
        change_absence_counts_on_bulk_add(instances, semester)

        update_last_change_in_catalog(
            self.context['request'].user.user_profile)
        return instances
Esempio n. 9
0
    def update(self, instance, validated_data):
        instance = super().update(instance, validated_data)
        catalog = instance.catalog_per_subject

        if instance.catalog_per_subject.is_coordination_subject:
            if instance.semester == 1:
                catalog.avg_sem1 = instance.grade
            else:
                catalog.avg_sem2 = instance.grade
                catalog.avg_annual = (catalog.avg_sem1 + catalog.avg_sem2) / 2
                catalog.avg_final = catalog.avg_annual
            catalog.save()
            update_behavior_grades_task.delay(instance.student_id,
                                              instance.semester,
                                              instance.grade)
        else:
            compute_averages([catalog], instance.semester)

        update_last_change_in_catalog(
            self.context['request'].user.user_profile)
        return instance
Esempio n. 10
0
    def create(self, validated_data):
        taken_at = validated_data['taken_at']
        semester = validated_data['semester']
        student_grades = validated_data['student_grades']

        instances_to_create = []
        for student_grade in student_grades:
            instances_to_create.append(
                SubjectGrade(subject_name=self.context['subject'].name,
                             semester=semester,
                             taken_at=taken_at,
                             grade_type=SubjectGrade.GradeTypes.REGULAR,
                             **student_grade))

        instances = SubjectGrade.objects.bulk_create(instances_to_create)

        compute_averages(
            list(set(instance.catalog_per_subject for instance in instances)),
            semester)
        update_last_change_in_catalog(
            self.context['request'].user.user_profile)
        return instances
Esempio n. 11
0
    def post(self, request, *args, **kwargs):
        student = self.get_student()
        current_study_class = student.student_in_class
        destination_study_class = self.get_study_class()

        # Validate the destination study class
        response = self.validate_destination_study_class(
            student, current_study_class, destination_study_class)
        if response:
            return response

        with transaction.atomic():
            # Change the student's current class
            student.student_in_class = destination_study_class
            student.save()

            # Move student's data (from previous & current year) to the new class
            self.move_student_data(student, current_study_class,
                                   destination_study_class)

            update_last_change_in_catalog(self.request.user.user_profile)

        serializer = self.get_serializer(current_study_class)
        return Response(serializer.data)