Esempio n. 1
0
    def test_possible(self):
        calendar_response = self.calendar_client.get_calendars([self.captain, self.first_mate], self.time_period)
        interviewer_groups = [schedule_calculator.InterviewerGroup(interviewers=calendar_response.interview_calendars, num_required=2)]
        schedules = schedule_calculator.calculate_schedules(
                interviewer_groups,
                self.time_period,
                possible_break=self.default_break,
        )

        self.assertEqual(len(schedules), 1)
Esempio n. 2
0
def scheduler_post(request):
    requisition_formset = RequisitionScheduleFormset(request.POST)
    scheduler_form = SuggestScheduleForm(request.POST)
    valid_submission = scheduler_form.is_valid() and requisition_formset.is_valid()
    schedules = []
    if not valid_submission:
        return render(
                request,
                'scheduler.html',
                dict(
                    requisition_formset=requisition_formset,
                    scheduler_form=scheduler_form,
                    valid_submission=valid_submission,
                    schedules=schedules,
                )
        )

    interviewer_groups = get_interviewer_groups(
            requisition_formset,
            also_include=scheduler_form.cleaned_data['also_include'],
            dont_include=scheduler_form.cleaned_data['dont_include'],
    )

    calendar_responses = [
        calendar_client.get_calendars(
            interviewer_group.interviewers,
            scheduler_form.time_period)
        for interviewer_group in interviewer_groups
        if interviewer_group.num_required
    ]

    interviewer_groups_with_calendars = [
        schedule_calculator.InterviewerGroup(
            interviewers=calendar_response.interview_calendars,
            num_required=interviewer_group.num_required,
        )
        for calendar_response, interviewer_group in zip(calendar_responses, interviewer_groups)
    ]

    schedules = schedule_calculator.calculate_schedules(
            interviewer_groups_with_calendars,
            time_period=scheduler_form.time_period,
            possible_break=scheduler_form.possible_break,
    )

    return render(
            request,
            'scheduler.html',
            dict(
                requisition_formset=requisition_formset,
                scheduler_form=scheduler_form,
                valid_submission=valid_submission,
                schedules=schedules,
            )
    )
Esempio n. 3
0
    def test_break_before_and_after(self):
        calendar_response = self.calendar_client.get_calendars([self.captain, self.first_mate], self.time_period)
        interviewer_groups = [
            schedule_calculator.InterviewerGroup(interviewers=[interview_calendar], num_required=1)
            for interview_calendar in calendar_response.interview_calendars
        ]

        schedules = schedule_calculator.calculate_schedules(
                interviewer_groups,
                self.time_period,
                possible_break=self.default_break.shift_minutes(45),
        )

        self.assertEqual(len(schedules), 2)
Esempio n. 4
0
    def test_no_break(self):
        calendar_response = self.calendar_client.get_calendars([self.first_mate], self.time_period)
        interviewer_groups = [
            schedule_calculator.InterviewerGroup(interviewers=[interview_calendar], num_required=1)
            for interview_calendar in calendar_response.interview_calendars
        ]

        schedules = schedule_calculator.calculate_schedules(
                interviewer_groups,
                self.time_period,
        )
        print self.time_period
        print schedules

        self.assertEqual(len(schedules), 13)
Esempio n. 5
0
def new_scheduler_post(request):
    form_data = request.POST
    candidate_name = form_data['candidate_name']
    interview_template_id = int(form_data['interview_template'])
    # error checking for request.POST
    form_is_valid, error_fields = error_check_scheduler_form_post(form_data)

    if not form_is_valid:
        return HttpResponse(simplejson.dumps({'form_is_valid': form_is_valid, 'error_fields': error_fields}))

    interview_template = models.InterviewTemplate.objects.get(id=interview_template_id)
    interviewer_groups = get_interview_groups_with_requirements(
        interview_template.interviewtemplaterequisition_set.values()
    )
    time_period = get_time_period(
        form_data['start_time'],
        form_data['end_time'],
        form_data['date'],
    )

    calendar_responses = [
        calendar_client.get_calendars(
            interviewer_group.interviewers,
            time_period)
        for interviewer_group in interviewer_groups
        if interviewer_group.num_required
    ]

    interviewer_groups_with_calendars = [
        schedule_calculator.InterviewerGroup(
            interviewers=calendar_response.interview_calendars,
            num_required=interviewer_group.num_required,
        )
        for calendar_response, interviewer_group in zip(calendar_responses, interviewer_groups)
    ]

    possible_break = determine_break_from_interview_time(
        time_period,
        interview_template.type,
    )

    schedules = schedule_calculator.calculate_schedules(
            interviewer_groups_with_calendars,
            time_period=time_period,
            interview_type=interview_template.type,
            possible_break=possible_break,
    )
    if not schedules:
        return HttpResponse(simplejson.dumps({'form_is_valid': False, 'error_fields': ['no result found']}))

    scheduler_post_result = {
        'form_is_valid': form_is_valid,
        'data': _dump_schedules_into_json(schedules),
        'interview_type': interview_template.type,
        'candidate_name': candidate_name,
        'interview_template_name': interview_template.template_name,
    }

    return HttpResponse(
        simplejson.dumps(scheduler_post_result),
        mimetype='application/json',
    )