def get_lunch_subject(self, day):
        """ Locate lunch subject with the appropriate day in the 'message for directors' field. """

        category = self.get_lunch_category()
        lunch_subjects = ClassSubject.objects.filter(parent_program__id=self.program.id, category=self.get_lunch_category(), message_for_directors=day.isoformat())
        lunch_subject = None
        example_timeslot = self.days[day]['lunch'][0]
        timeslot_length = (example_timeslot.end - example_timeslot.start).seconds / 3600.0

        if lunch_subjects.count() == 0:
            #   If no lunch was found, create a new subject
            new_subject = ClassSubject()
            new_subject.grade_min = 7
            new_subject.grade_max = 12
            new_subject.parent_program = self.program
            new_subject.category = category
            new_subject.class_info = 'Enjoy a break for lunch with your friends!  Please register for at least one lunch period on each day of the program.'
            new_subject.class_size_min = 0
            # If the program doesn't have a max size, we unfortunately still
            # need one here.  Set a really big one.
            new_subject.class_size_max = self.program.program_size_max or 10**6
            new_subject.status = 10
            new_subject.duration = '%.4f' % timeslot_length
            new_subject.message_for_directors = day.isoformat()
            new_subject.save()
            new_subject.title = 'Lunch Period'
            new_subject.save()
            lunch_subject = new_subject
        else:
            #   Otherwise, return an existing lunch subject
            lunch_subject = lunch_subjects[0]
        return lunch_subject
Esempio n. 2
0
    def get_lunch_subject(self, day):
        """ Locate lunch subject with the appropriate day in the 'message for directors' field. """

        category = self.get_lunch_category()
        lunch_subjects = ClassSubject.objects.filter(
            parent_program__id=self.program.id,
            category=self.get_lunch_category(),
            message_for_directors=day.isoformat())
        lunch_subject = None
        example_timeslot = self.days[day]['lunch'][0]
        timeslot_length = (example_timeslot.end -
                           example_timeslot.start).seconds / 3600.0

        if lunch_subjects.count() == 0:
            #   If no lunch was found, create a new subject
            new_subject = ClassSubject()
            new_subject.grade_min = 7
            new_subject.grade_max = 12
            new_subject.parent_program = self.program
            new_subject.category = category
            new_subject.class_info = 'Enjoy a break for lunch with your friends!  Please register for at least one lunch period on each day of the program.'
            new_subject.class_size_min = 0
            new_subject.class_size_max = self.program.program_size_max
            new_subject.status = 10
            new_subject.duration = '%.4f' % timeslot_length
            new_subject.message_for_directors = day.isoformat()
            new_subject.anchor = self.program.classes_node()
            new_subject.save()
            nodestring = new_subject.category.symbol + str(new_subject.id)
            new_anchor = new_subject.anchor.tree_create([nodestring])
            new_anchor.friendly_name = 'Lunch Period'
            new_anchor.save()
            new_subject.anchor = new_anchor
            new_subject.save()
            lunch_subject = new_subject
            #   print 'Generated subject: %s' % lunch_subject
        else:
            #   Otherwise, return an existing lunch subject
            lunch_subject = lunch_subjects[0]
            #   print 'Selected subject: %s' % lunch_subject
        return lunch_subject
Esempio n. 3
0
    def get_lunch_subject(self, day):
        """ Locate lunch subject with the appropriate day in the 'message for directors' field. """

        category = self.get_lunch_category()
        lunch_subjects = ClassSubject.objects.filter(
            parent_program__id=self.program.id,
            category=self.get_lunch_category(),
            message_for_directors=day.isoformat())
        lunch_subject = None
        example_timeslot = self.days[day]['lunch'][0]
        timeslot_length = (example_timeslot.end -
                           example_timeslot.start).seconds / 3600.0

        if lunch_subjects.count() == 0:
            #   If no lunch was found, create a new subject
            new_subject = ClassSubject()
            new_subject.grade_min = 7
            new_subject.grade_max = 12
            new_subject.parent_program = self.program
            new_subject.category = category
            new_subject.class_info = 'Enjoy a break for lunch with your friends!  Please register for at least one lunch period on each day of the program.'
            new_subject.class_size_min = 0
            # If the program doesn't have a max size, we unfortunately still
            # need one here.  Set a really big one.
            new_subject.class_size_max = self.program.program_size_max or 10**6
            new_subject.status = 10
            new_subject.duration = '%.4f' % timeslot_length
            new_subject.message_for_directors = day.isoformat()
            new_subject.save()
            new_subject.title = 'Lunch Period'
            new_subject.save()
            lunch_subject = new_subject
        else:
            #   Otherwise, return an existing lunch subject
            lunch_subject = lunch_subjects[0]
        return lunch_subject
    def satprep_classgen(self, request, tl, one, two, module, extra, prog):
        """ This view will generate the classes for all the users. """

        delete = False

        if not request.method == 'POST' and not request.POST.has_key(
                'newclass_create'):
            #   Show the form asking for a room number and capacity for each teacher.

            user_list = self.program.getLists()['teachers_satprepinfo']['list']
            reginfos = [
                module_ext.SATPrepTeacherModuleInfo.objects.get(program=prog,
                                                                user=u)
                for u in user_list
            ]
            reginfos.sort(key=lambda x: x.subject + x.section)
            user_list = [r.user for r in reginfos]

            context = {
                'timeslots': prog.getTimeSlots(),
                'teacher_data': zip([ESPUser(u) for u in user_list], reginfos)
            }

            return render_to_response(self.baseDir() + 'newclass_confirm.html',
                                      request, (prog, tl), context)

        #   Delete current classes if specified (currently turned off, not necessary)
        if delete:
            cur_classes = ClassSubject.objects.filter(
                parent_program=self.program)
            [cls.delete() for cls in cur_classes]

        data = request.POST

        #   Pull the timeslots from the multiselect field on the form.
        timeslots = []
        for ts_id in data.getlist('timeslot_ids'):
            ts = Event.objects.get(id=ts_id)
            timeslots.append(ts)

        #   Create classrooms based on the form input.
        for key in data:
            key_dir = key.split('_')
            if len(key_dir) == 2 and key_dir[0] == 'room' and len(
                    data[key]) > 0:
                #   Extract a room number and capacity from POST data.
                room_num = data.get(key)
                cap_key = 'capacity_' + key_dir[1]
                room_capacity = int(data.get(cap_key))
                reginfo = module_ext.SATPrepTeacherModuleInfo.objects.get(
                    id=int(key_dir[1]))
                user = reginfo.user

                #   Initialize a class subject.
                newclass = ClassSubject()
                newclass.parent_program = self.program
                newclass.class_info = '%s: Section %s (%s)' % (
                    reginfo.get_subject_display(), reginfo.section,
                    reginfo.get_section_display())
                newclass.grade_min = 9
                newclass.grade_max = 12

                newclass.class_size_min = 0
                newclass.class_size_max = room_capacity

                newclass.category = ClassCategories.objects.get(
                    category='SATPrep')
                newclass.anchor = self.program.classes_node()

                newclass.save()

                nodestring = 'SAT' + str(newclass.id)
                newclass.anchor = self.program.classes_node().tree_create(
                    [nodestring])
                newclass.anchor.friendly_name = 'SAT Prep %s - %s' % (
                    reginfo.get_subject_display(),
                    reginfo.get_section_display())
                newclass.anchor.save()
                newclass.anchor.tree_create(['TeacherEmail'])
                newclass.save()

                newclass.makeTeacher(user)
                newclass.accept()

                #   Create a section of the class for each timeslot.
                #   The sections are all held in the same room by default.  This can be changed
                #   in the scheduling module later.
                for ts in timeslots:
                    new_room, created = Resource.objects.get_or_create(
                        name=room_num,
                        res_type=ResourceType.get_or_create('Classroom'),
                        event=ts)
                    new_room.num_students = room_capacity
                    new_room.save()
                    sec = newclass.add_section(
                        duration=(ts.duration().seconds / 3600.0))
                    sec.meeting_times.add(ts)
                    sec.assign_room(new_room)
                    sec.status = 10
                    sec.save()

        #dummy_anchor.delete()
        return HttpResponseRedirect('/manage/%s/schedule_options' %
                                    self.program.getUrlBase())
    def diagnostic_sections(self, request, tl, one, two, module, extra, prog):
        """ Step 2 of the diagnostic setup process. """

        #   Initialize some stuff
        empty_rooms = request.GET['empty_rooms'].split(',')

        timeslot_id = int(request.GET['timeslot'])
        timeslot = Event.objects.get(id=timeslot_id)

        rooms = list(
            prog.getClassrooms(timeslot=timeslot).exclude(
                name__in=empty_rooms))

        #   Get student list, sort alphabetically
        students = list(prog.students()['confirmed'])
        num_students = len(students)
        students.sort(key=lambda s: s.last_name)

        debug_str = ''
        total_size = 0
        accum_capacity = {}

        #   Count cumulative capacity of rooms encountered so far
        for r in rooms:
            total_size += r.num_students
            accum_capacity[r.id] = total_size - r.num_students

        #   Reverse the list so you know how much space is remaining
        rooms.reverse()
        for r in rooms:
            r.add_students = num_students * r.num_students / total_size

        #   Iterate over the rooms, adding students until the number of students remaining
        #   matches the proportion of space remaining
        sections = []
        students_remaining = num_students
        i = 0
        j = 0
        for r in rooms:
            new_section = {
                'timeslot': timeslot,
                'students': [],
                'room': r,
                'index': i
            }
            new_class = ClassSubject()
            new_class.parent_program = prog
            new_class.class_size_max = r.num_students
            new_class.duration = timeslot.duration().seconds / 3600.0
            new_class.grade_min = 9
            new_class.grade_max = 12
            new_class.anchor = DataTree.get_by_uri(
                prog.anchor.get_uri() + '/Classes/Diag' + str(i + 1),
                create=True)
            new_class.category = ClassCategories.objects.get(
                category='SATPrep')
            new_class.status = 10
            new_class.save()
            new_sec = new_class.add_default_section()

            new_sec.meeting_times.add(timeslot)
            new_sec.assignClassRoom(r)
            while students_remaining > (accum_capacity[r.id] * num_students /
                                        total_size):
                debug_str += 'i=%d %d/%d ac=%d\n' % (i, j, num_students,
                                                     accum_capacity[r.id])
                new_sec.preregister_student(students[j])
                new_section['students'].append(students[j])
                j += 1
                students_remaining -= 1
            if len(new_section['students']) > 0:
                new_section['fln'] = new_section['students'][0].last_name
                new_section['lln'] = new_section['students'][-1].last_name
                new_class.anchor.friendly_name = 'SAT Prep Diagnostic %d: %s - %s' % (
                    i + 1, new_section['fln'], new_section['lln'])
                new_class.anchor.save()
            i += 1
            sections.append(new_section)

        context = {'prog': prog, 'sections': sections}
        return render_to_response(self.baseDir() + 'diagnostic_sections.html',
                                  request, (prog, tl), context)