def resources_timeslot(self, request, tl, one, two, module, extra, prog):
        context = {}
        response = None

        controller = ResourceController(prog)

        if request.GET.get('op') == 'edit':
            #   pre-fill form
            current_slot = Event.objects.get(id=request.GET['id'])
            context['timeslot_form'] = TimeslotForm()
            context['timeslot_form'].load_timeslot(current_slot)

        if request.GET.get('op') == 'delete':
            #   show delete confirmation page
            context['prog'] = self.program
            context['timeslot'] = Event.objects.get(id=request.GET['id'])
            response = render_to_response(self.baseDir()+'timeslot_delete.html', request, context)

        if request.method == 'POST':
            data = request.POST

            if data['command'] == 'reallyremove':
                controller.delete_timeslot(data['id'])

            elif data['command'] == 'addedit':
                #   add/edit timeslot
                form = TimeslotForm(data)
                if form.is_valid():
                    controller.add_or_edit_timeslot(form)
                else:
                    context['timeslot_form'] = form

        return (response, context)
Пример #2
0
    def resources_equipment(self, request, tl, one, two, module, extra, prog):
        context = {}
        response = None

        controller = ResourceController(prog)

        if request.GET.get('op') == 'edit':
            #   pre-fill form
            equip = Resource.objects.get(id=request.GET['id'])
            context['equipment_form'] = EquipmentForm(self.program)
            context['equipment_form'].load_equipment(self.program, equip)

        if request.GET.get('op') == 'delete':
            #   show delete confirmation page
            context['prog'] = self.program
            context['equipment'] = Resource.objects.get(id=request.GET['id'])
            response = render_to_response(
                self.baseDir() + 'equipment_delete.html', request, context)

        if request.method == 'POST':
            data = request.POST

            if data['command'] == 'reallyremove':
                controller.delete_equipment(data['id'])

            elif data['command'] == 'addedit':
                #   add/edit restype
                form = EquipmentForm(self.program, data)

                if form.is_valid():
                    form.save_equipment(self.program)
                else:
                    context['equipment_form'] = form

        return (response, context)
    def resources_equipment(self, request, tl, one, two, module, extra, prog):
        context = {}
        response = None

        controller = ResourceController(prog)

        if request.GET.get('op') == 'edit':
            #   pre-fill form
            equip = Resource.objects.get(id=request.GET['id'])
            context['equipment_form'] = EquipmentForm(self.program)
            context['equipment_form'].load_equipment(self.program, equip)

        if request.GET.get('op') == 'delete':
            #   show delete confirmation page
            context['prog'] = self.program
            context['equipment'] = Resource.objects.get(id=request.GET['id'])
            response = render_to_response(self.baseDir()+'equipment_delete.html', request, context)

        if request.method == 'POST':
            data = request.POST

            if data['command'] == 'reallyremove':
                controller.delete_equipment(data['id'])

            elif data['command'] == 'addedit':
                #   add/edit restype
                form = EquipmentForm(self.program, data)

                if form.is_valid():
                    form.save_equipment(self.program)
                else:
                    context['equipment_form'] = form

        return (response, context)
Пример #4
0
    def resources_timeslot_import(self, request, tl, one, two, module, extra,
                                  prog):
        context = {}
        response = None

        controller = ResourceController(prog)

        import_mode = 'preview'
        if 'import_confirm' in request.POST and request.POST[
                'import_confirm'] == 'yes':
            import_mode = 'save'

        import_form = TimeslotImportForm(request.POST)
        if not import_form.is_valid():
            context['import_timeslot_form'] = import_form
        else:
            past_program = import_form.cleaned_data['program']
            start_date = import_form.cleaned_data['start_date']

            if past_program == prog:
                raise ESPError(
                    "You're trying to import timeslots from a program"
                    " to itself! Try a different program instead.",
                    log=False)

            #   Figure out timeslot dates
            new_timeslots = []
            prev_timeslots = past_program.getTimeSlots().order_by('start')
            time_delta = start_date - prev_timeslots[0].start.date()
            for orig_timeslot in prev_timeslots:
                new_timeslot = Event(
                    program=self.program,
                    event_type=orig_timeslot.event_type,
                    short_description=orig_timeslot.short_description,
                    description=orig_timeslot.description,
                    priority=orig_timeslot.priority,
                    start=orig_timeslot.start + time_delta,
                    end=orig_timeslot.end + time_delta,
                )
                #   Save the new timeslot only if it doesn't duplicate an existing one
                if import_mode == 'save' and not Event.objects.filter(
                        program=new_timeslot.program,
                        start=new_timeslot.start,
                        end=new_timeslot.end).exists():
                    new_timeslot.save()
                new_timeslots.append(new_timeslot)

            #   Render a preview page showing the resources for the previous program if desired
            context['past_program'] = past_program
            context['start_date'] = start_date.strftime('%m/%d/%Y')
            context['new_timeslots'] = new_timeslots
            if import_mode == 'preview':
                context['prog'] = self.program
                response = render_to_response(
                    self.baseDir() + 'timeslot_import.html', request, context)
            else:
                extra = 'timeslot'

        return (response, context)
Пример #5
0
    def resources_timeslot(self, request, tl, one, two, module, extra, prog):
        context = {}
        response = None

        controller = ResourceController(prog)

        if request.GET.get('op') == 'edit':
            #   pre-fill form
            current_slot = Event.objects.get(id=request.GET['id'])
            context['timeslot_form'] = TimeslotForm()
            context['timeslot_form'].load_timeslot(current_slot)

        if request.GET.get('op') == 'delete':
            #   show delete confirmation page
            context['prog'] = self.program
            context['timeslot'] = Event.objects.get(id=request.GET['id'])
            response = render_to_response(
                self.baseDir() + 'timeslot_delete.html', request, context)

        if request.method == 'POST':
            data = request.POST

            if data['command'] == 'reallyremove':
                controller.delete_timeslot(data['id'])

            elif data['command'] == 'addedit':
                #   add/edit timeslot
                form = TimeslotForm(data)
                if form.is_valid():
                    controller.add_or_edit_timeslot(form)
                else:
                    context['timeslot_form'] = form

        return (response, context)
    def resources_classroom(self, request, tl, one, two, module, extra, prog):
        context = {}
        response = None

        controller = ResourceController(prog)

        if request.GET.get('op') == 'edit':
            #   pre-fill form
            current_room = Resource.objects.get(id=request.GET['id'])
            context['classroom_form'] = ClassroomForm(self.program)
            context['classroom_form'].load_classroom(self.program, current_room)

        if request.GET.get('op') == 'delete':
            #   show delete confirmation page
            context['prog'] = self.program
            context['classroom'] = Resource.objects.get(id=request.GET['id'])
            resources = self.program.getClassrooms().filter(name=context['classroom'].name)
            context['timeslots'] = [r.event for r in resources]
            sections = ClassSection.objects.filter(resourceassignment__resource__id__in=resources.values_list('id', flat=True)).distinct()

            context['sections'] = sections
            response = render_to_response(self.baseDir()+'classroom_delete.html', request, context)

        if request.method == 'POST':
            data = request.POST

            if data['command'] == 'reallyremove':
                controller.delete_classroom(data['id'])

            elif data['command'] == 'addedit':
                form = ClassroomForm(self.program, data)
                if form.is_valid():
                    controller.add_or_edit_classroom(form)
                else:
                    context['classroom_form'] = form

        return (response, context)
Пример #7
0
    def resources_classroom(self, request, tl, one, two, module, extra, prog):
        context = {}
        response = None

        controller = ResourceController(prog)

        if request.GET.get('op') == 'edit':
            #   pre-fill form
            current_room = Resource.objects.get(id=request.GET['id'])
            context['classroom_form'] = ClassroomForm(self.program)
            context['classroom_form'].load_classroom(self.program,
                                                     current_room)

        if request.GET.get('op') == 'delete':
            #   show delete confirmation page
            context['prog'] = self.program
            context['classroom'] = Resource.objects.get(id=request.GET['id'])
            resources = self.program.getClassrooms().filter(
                name=context['classroom'].name)
            context['timeslots'] = [r.event for r in resources]
            sections = ClassSection.objects.filter(
                resourceassignment__resource__id__in=resources.values_list(
                    'id', flat=True)).distinct()

            context['sections'] = sections
            response = render_to_response(
                self.baseDir() + 'classroom_delete.html', request, context)

        if request.method == 'POST':
            data = request.POST

            if data['command'] == 'reallyremove':
                controller.delete_classroom(data['id'])

            elif data['command'] == 'addedit':
                form = ClassroomForm(self.program, data)
                if form.is_valid():
                    controller.add_or_edit_classroom(form)
                else:
                    context['classroom_form'] = form

        return (response, context)
Пример #8
0
    def resources_classroom_import(self, request, tl, one, two, module, extra,
                                   prog):
        context = {}
        response = None

        controller = ResourceController(prog)

        import_mode = 'preview'
        if 'import_confirm' in request.POST and request.POST[
                'import_confirm'] == 'yes':
            import_mode = 'save'

        import_form = ClassroomImportForm(request.POST)
        if not import_form.is_valid():
            context['import_form'] = import_form
        else:
            past_program = import_form.cleaned_data['program']
            complete_availability = import_form.cleaned_data[
                'complete_availability']

            resource_list = []
            if complete_availability:
                #   Make classrooms available at all of the new program's timeslots
                for resource in past_program.groupedClassrooms():
                    for timeslot in self.program.getTimeSlots():
                        new_res = Resource(name=resource.name,
                                           res_type=resource.res_type,
                                           num_students=resource.num_students,
                                           is_unique=resource.is_unique,
                                           user=resource.user,
                                           event=timeslot)
                        if import_mode == 'save' and not Resource.objects.filter(
                                name=new_res.name,
                                event=new_res.event).exists():
                            new_res.save()
                        resource_list.append(new_res)
            else:
                #   Attempt to match timeslots for the programs
                ts_old = past_program.getTimeSlots().filter(
                    event_type__description__icontains='class').order_by(
                        'start')
                ts_new = self.program.getTimeSlots().filter(
                    event_type__description__icontains='class').order_by(
                        'start')
                ts_map = {}
                for i in range(min(len(ts_old), len(ts_new))):
                    ts_map[ts_old[i].id] = ts_new[i]

                #   Iterate over the resources in the previous program
                for res in past_program.getClassrooms():
                    #   If we know what timeslot to put it in, make a copy
                    if res.event.id in ts_map:
                        new_res = Resource()
                        new_res.name = res.name
                        new_res.res_type = res.res_type
                        new_res.num_students = res.num_students
                        new_res.is_unique = res.is_unique
                        new_res.user = res.user
                        new_res.event = ts_map[res.event.id]
                        #   Check to avoid duplicating rooms (so the process is idempotent)
                        if import_mode == 'save' and not Resource.objects.filter(
                                name=new_res.name,
                                event=new_res.event).exists():
                            new_res.save()
                        #   Note: furnishings are messed up, so don't bother copying those yet.
                        resource_list.append(new_res)

            #   Render a preview page showing the resources for the previous program if desired
            context['past_program'] = past_program
            context['complete_availability'] = complete_availability
            if import_mode == 'preview':
                context['prog'] = self.program
                result = self.program.collapsed_dict(resource_list)
                key_list = result.keys()
                key_list.sort()
                context['new_rooms'] = [result[key] for key in key_list]
                response = render_to_response(
                    self.baseDir() + 'classroom_import.html', request, context)
            else:
                extra = 'classroom'

        return (response, context)