Exemplo n.º 1
0
    def get_hours_substitution_done(self, obj, *args, **kwargs):
        # Get start_date and end_date parameters from url
        start_date = self.context.get('request').query_params.get('start_date')
        end_date = self.context.get('request').query_params.get('end_date')

        school_year = self.context.get('request').query_params.get(
            'school_year')

        assignments = Assignment.objects.filter(course=obj.id,
                                                school=obj.school,
                                                school_year=school_year,
                                                substitution=True).values(
                                                    'date__week_day',
                                                    'hour_start', 'hour_end')
        # Filter in a time interval
        if start_date and utils.is_date_string_valid(start_date):
            assignments = assignments.filter(date__gte=start_date)
        if end_date and utils.is_date_string_valid(end_date):
            assignments = assignments.filter(date__lte=end_date)

        for el in assignments:
            el['date__week_day'] = utils.convert_weekday_into_0_6_format(
                el['date__week_day'])

        hours_slots = HourSlot.objects.filter(school=obj.school,
                                              school_year=school_year).values(
                                                  "day_of_week", "starts_at",
                                                  "ends_at", "legal_duration")
        total = utils.compute_total_hours_assignments(assignments, hours_slots)
        return total
Exemplo n.º 2
0
    def get_missing_hours_bes(self, obj, *args, **kwargs):
        """
            Missing hours is computed over the hours the teacher needs to do for a given class,
            and the hours already planned in that class.
            :param obj:
            :param args:
            :param kwargs:
            :return:
            """
        start_date = self.context.get('request').query_params.get('start_date')
        end_date = self.context.get('request').query_params.get('end_date')

        assignments = Assignment.objects.filter(teacher=obj.teacher,
                                                course=obj.course,
                                                subject=obj.subject,
                                                school=obj.school,
                                                bes=True,
                                                co_teaching=False).values(
                                                    'date__week_day',
                                                    'hour_start', 'hour_end')

        # Filter in a time interval
        if start_date and utils.is_date_string_valid(start_date):
            assignments = assignments.filter(date__gte=start_date)
        if end_date and utils.is_date_string_valid(end_date):
            assignments = assignments.filter(date__lte=end_date)

        for el in assignments:
            el['date__week_day'] = utils.convert_weekday_into_0_6_format(
                el['date__week_day'])

        hours_slots = HourSlot.objects.filter(
            school=obj.school,
            school_year=obj.school_year).values("day_of_week", "starts_at",
                                                "ends_at", "legal_duration")
        total = utils.compute_total_hours_assignments(assignments, hours_slots)

        return obj.hours_bes - total