Exemple #1
0
    def force_availability(self, request, tl, one, two, module, extra, prog):
        teacher_dict = prog.teachers(QObjects=True)
        unavailable_teachers = ESPUser.objects.filter(
            (teacher_dict['class_approved'] | teacher_dict['class_proposed'])
            & ~teacher_dict['availability']).distinct()

        if request.method == 'POST':
            if request.POST.has_key('sure') and request.POST['sure'] == 'True':

                #   Use the ClassCreationController to send e-mail
                from esp.program.controllers.classreg import ClassCreationController
                ccc = ClassCreationController(prog)

                for teacher in unavailable_teachers:
                    for ts in prog.getTimeSlots():
                        teacher.addAvailableTime(prog, ts)
                    ccc.send_availability_email(
                        teacher,
                        note=
                        'Availability was overridden by the program directors in order to make your class schedule feasible.  Please contact them for more information.'
                    )

                return self.scheduling(request, tl, one, two, module,
                                       'refresh', prog)
            else:
                return self.scheduling(request, tl, one, two, module, '', prog)

        #   Normally, though, return a page explaining the issue.
        context = {'prog': self.program}
        context['good_teacher_num'] = ESPUser.objects.filter(
            teacher_dict['class_approved']
            & teacher_dict['availability']).distinct().count()
        context['total_teacher_num'] = ESPUser.objects.filter(
            teacher_dict['class_approved']).distinct().count()
        context['bad_teacher_num'] = unavailable_teachers.count()

        return render_to_response(self.baseDir() + 'force_prompt.html',
                                  request, (prog, tl), context)
Exemple #2
0
    def availabilityForm(self, request, tl, one, two, prog, teacher, isAdmin):
        time_options = self.program.getTimeSlots(types=[self.event_type()])
        #   Group contiguous blocks
        if not Tag.getBooleanTag('availability_group_timeslots', default=True):
            time_groups = [list(time_options)]
        else:
            time_groups = Event.group_contiguous(list(time_options))

        blank = False

        available_slots = teacher.getAvailableTimes(self.program, True)
        # must set the ignore_classes=True parameter above, otherwise when a teacher tries to edit their
        # availability, it will show their scheduled times as unavailable.

        #   Fetch the timeslots the teacher is scheduled in and grey them out.
        #   If we found a timeslot that they are scheduled in but is not available, show a warning.
        taken_slots = []
        avail_and_teaching = []
        user_sections = teacher.getTaughtSections(self.program)
        conflict_found = False
        for section in user_sections:
            for timeslot in section.get_meeting_times():
                taken_slots.append(timeslot)
                if timeslot not in available_slots:
                    conflict_found = True
                else:
                    avail_and_teaching.append(timeslot)

        if request.method == 'POST':
            #   Process form
            post_vars = request.POST

            #   Reset teacher's availability
            teacher.clearAvailableTimes(self.program)
            #   But add back in the times they're teaching
            #   because those aren't submitted with the form
            for timeslot in avail_and_teaching:
                teacher.addAvailableTime(self.program, timeslot)

            #   Add in resources for the checked available times.
            timeslot_ids = map(int, post_vars.getlist('timeslots'))
            timeslots = Event.objects.filter(
                id__in=timeslot_ids).order_by('start')
            missing_tsids = set(timeslot_ids) - set(x.id for x in timeslots)
            if missing_tsids:
                raise ESPError(
                    'Received requests for the following timeslots that don\'t exist: %s'
                    % str(list(sorted(missing_tsids))),
                    log=False)

            blank = (not (bool(len(timeslot_ids) + len(avail_and_teaching))))
            if not blank:
                for timeslot in timeslots:
                    teacher.addAvailableTime(self.program, timeslot)

                #   Send an e-mail showing availability to the teacher (and the archive)
                ccc = ClassCreationController(self.program)
                ccc.send_availability_email(teacher)

                if isAdmin:
                    #   Return to the relevant check_availability page
                    return HttpResponseRedirect(
                        '/manage/%s/%s/check_availability?user=%s' %
                        (one, two, teacher.id))
                else:
                    #   Return to the main registration page
                    return self.goToCore(tl)

        #   Show new form

        if not (len(available_slots) or
                blank):  # I'm not sure whether or not we want the "or blank"
            #   If they didn't enter anything, make everything checked by default.
            available_slots = self.program.getTimeSlots(
                types=[self.event_type()])
            #   The following 2 lines mark the teacher as always available.  This
            #   is sometimes helpful, but not usually the desired behavior.
            #   for a in available_slots:
            #       teacher.addAvailableTime(self.program, a)

        context = {
            'groups': [{
                'selections': [{
                    'checked': (t in available_slots),
                    'taken': (t in taken_slots),
                    'slot': t
                } for t in group]
            } for group in time_groups]
        }
        context['num_groups'] = len(context['groups'])
        context['prog'] = self.program
        context['is_overbooked'] = (
            not self.isCompleted()
            and (teacher.getTaughtTime(self.program) > timedelta(0)))
        context['submitted_blank'] = blank
        context['conflict_found'] = conflict_found
        context['teacher_user'] = teacher

        return render_to_response(self.baseDir() + 'availability_form.html',
                                  request, context)