Example #1
0
    def _update_averages(self, catalogs, catalogs_with_difference_grades,
                         catalogs_with_second_examination_grades):
        compute_averages(catalogs, 1, is_async=False)
        compute_averages(catalogs, 2, is_async=False)

        if catalogs_with_difference_grades:
            change_averages_after_examination_grade_operation(
                catalogs_with_difference_grades,
                grade_type=ExaminationGrade.GradeTypes.DIFFERENCE,
                semester=1,
            )
            change_averages_after_examination_grade_operation(
                catalogs_with_difference_grades,
                grade_type=ExaminationGrade.GradeTypes.DIFFERENCE,
                semester=2,
            )
            change_averages_after_examination_grade_operation(
                catalogs_with_difference_grades,
                grade_type=ExaminationGrade.GradeTypes.DIFFERENCE,
                semester=None,
            )
        if catalogs_with_second_examination_grades:
            change_averages_after_examination_grade_operation(
                catalogs_with_second_examination_grades,
                grade_type=ExaminationGrade.GradeTypes.SECOND_EXAMINATION,
                semester=None,
            )

        catalog_ids = [catalog.id for catalog in catalogs]
        update_absences_counts_for_students_task.delay(catalog_ids)
Example #2
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
Example #3
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)
Example #4
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
    def update(self, instance, validated_data):
        instances_to_update = []

        for data in validated_data:
            catalog = data['catalog']
            for attr, value in data.items():
                setattr(catalog, attr, value)
            instances_to_update.append(catalog)

        if instances_to_update:
            StudentCatalogPerSubject.objects.bulk_update(
                instances_to_update, [
                    'wants_level_testing_grade', 'wants_thesis',
                    'wants_simulation', 'is_exempted', 'is_enrolled'
                ])
            current_calendar = get_current_academic_calendar()
            if not current_calendar:
                semester = 1
            else:
                semester = 2 if timezone.now().date(
                ) >= current_calendar.second_semester.starts_at else 1

            compute_averages(list(set(instances_to_update)), semester)

            subject = instances_to_update[0].subject
            if subject.allows_exemption:
                if subject.name == 'Religie':
                    label = Label.objects.filter(
                        text=EXEMPTED_RELIGION_LABEL).first()
                else:
                    label = Label.objects.filter(
                        text=EXEMPTED_SPORT_LABEL).first()

                for catalog in instances_to_update:
                    if catalog.is_exempted:
                        catalog.student.labels.add(label)
                    else:
                        catalog.student.labels.remove(label)

        return instance
Example #6
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