Beispiel #1
0
    def test_single_result_form_saves_participant_and_voter_count(self):
        course = mommy.make(Course)
        evaluation = Evaluation(course=course, is_single_result=True)
        form_data = {
            "name_de": "qwertz",
            "name_en": "qwertz",
            "weight": 1,
            "event_date": "2014-01-01",
            "answer_1": 6,
            "answer_2": 0,
            "answer_3": 2,
            "answer_4": 0,
            "answer_5": 2,
            "course": course.pk
        }
        form = SingleResultForm(form_data,
                                instance=evaluation,
                                semester=evaluation.course.semester)
        self.assertTrue(form.is_valid())

        form.save(user=mommy.make(UserProfile))

        evaluation = Evaluation.objects.get()
        self.assertEqual(evaluation.num_participants, 10)
        self.assertEqual(evaluation.num_voters, 10)
Beispiel #2
0
    def test_single_result_form_can_change_responsible(self):
        responsible = mommy.make(UserProfile)
        course_type = mommy.make(CourseType)
        course = Course(semester=mommy.make(Semester))
        form_data = {
            "name_de": "qwertz",
            "name_en": "qwertz",
            "type": course_type.pk,
            "degrees": ["1"],
            "event_date": "2014-01-01",
            "responsible": responsible.pk,
            "answer_1": 6,
            "answer_2": 0,
            "answer_3": 2,
            "answer_4": 0,
            "answer_5": 2,
            "semester": course.semester.pk
        }
        form = SingleResultForm(form_data, instance=course)
        self.assertTrue(form.is_valid())

        form.save(user=mommy.make(UserProfile))
        self.assertEqual(course.responsible_contributors[0], responsible)

        new_responsible = mommy.make(UserProfile)
        form_data["responsible"] = new_responsible.pk
        form = SingleResultForm(form_data, instance=course)
        self.assertTrue(form.is_valid())

        form.save(user=mommy.make(UserProfile))
        self.assertEqual(course.responsible_contributors[0], new_responsible)
Beispiel #3
0
    def test_single_result_form_saves_participant_and_voter_count(self):
        responsible = mommy.make(UserProfile)
        course_type = mommy.make(CourseType)
        course = Course(semester=mommy.make(Semester))
        form_data = {
            "name_de": "qwertz",
            "name_en": "qwertz",
            "type": course_type.pk,
            "degrees": ["1"],
            "event_date": "2014-01-01",
            "responsible": responsible.pk,
            "answer_1": 6,
            "answer_2": 0,
            "answer_3": 2,
            "answer_4": 0,
            "answer_5": 2,
            "semester": course.semester.pk
        }
        form = SingleResultForm(form_data, instance=course)
        self.assertTrue(form.is_valid())

        form.save(user=mommy.make(UserProfile))

        course = Course.objects.get()
        self.assertEqual(course.num_participants, 10)
        self.assertEqual(course.num_voters, 10)
Beispiel #4
0
    def test_single_result_form_saves_participant_and_voter_count(self):
        responsible = mommy.make(UserProfile)
        course_type = mommy.make(CourseType)
        form_data = {
            "name_de": "qwertz",
            "name_en": "qwertz",
            "type": course_type.pk,
            "degrees": ["1"],
            "event_date": "02/1/2014",
            "responsible": responsible.pk,
            "answer_1": 6,
            "answer_2": 0,
            "answer_3": 2,
            "answer_4": 0,
            "answer_5": 2,
        }
        course = Course(semester=mommy.make(Semester))
        form = SingleResultForm(form_data, instance=course)
        self.assertTrue(form.is_valid())

        form.save(user=mommy.make(UserProfile))

        course = Course.objects.get()
        self.assertEqual(course.num_participants, 10)
        self.assertEqual(course.num_voters, 10)
Beispiel #5
0
    def test_single_result_form_can_change_responsible(self):
        responsible = mommy.make(UserProfile)
        course_type = mommy.make(CourseType)
        evaluation = Evaluation(course=mommy.make(Course),
                                is_single_result=True)
        form_data = {
            "name_de": "qwertz",
            "name_en": "qwertz",
            "type": course_type.pk,
            "degrees": [1],
            "event_date": "2014-01-01",
            "responsible": responsible.pk,
            "answer_1": 6,
            "answer_2": 0,
            "answer_3": 2,
            "answer_4": 0,
            "answer_5": 2,
            "semester": evaluation.course.semester.pk
        }
        form = SingleResultForm(form_data, instance=evaluation)
        self.assertTrue(form.is_valid())

        form.save(user=mommy.make(UserProfile))
        self.assertEqual(evaluation.course.responsibles.first(), responsible)

        new_responsible = mommy.make(UserProfile)
        form_data["responsible"] = new_responsible.pk
        form = SingleResultForm(form_data, instance=evaluation)
        self.assertTrue(form.is_valid())

        form.save(user=mommy.make(UserProfile))
        self.assertEqual(evaluation.course.responsibles.first(),
                         new_responsible)
Beispiel #6
0
def helper_single_result_edit(request, semester, course):
    form = SingleResultForm(request.POST or None, instance=course)

    if form.is_valid():
        if not course.can_staff_edit or course.is_archived:
            raise SuspiciousOperation("Modifying this course is not allowed.")

        form.save(user=request.user)

        messages.success(request, _("Successfully created single result."))
        return redirect('staff:semester_view', semester.id)
    else:
        return render(request, "staff_single_result_form.html", dict(semester=semester, form=form))
Beispiel #7
0
    def test_single_result_form_can_change_responsible(self):
        responsible = mommy.make(UserProfile)
        course_type = mommy.make(CourseType)
        course = Course(semester=mommy.make(Semester))
        form_data = {
            "name_de": "qwertz",
            "name_en": "qwertz",
            "type": course_type.pk,
            "degrees": ["1"],
            "event_date": "2014-01-01",
            "responsible": responsible.pk,
            "answer_1": 6,
            "answer_2": 0,
            "answer_3": 2,
            "answer_4": 0,
            "answer_5": 2,
            "semester": course.semester.pk
        }
        form = SingleResultForm(form_data, instance=course)
        self.assertTrue(form.is_valid())

        form.save(user=mommy.make(UserProfile))
        self.assertEqual(course.responsible_contributors[0], responsible)

        new_responsible = mommy.make(UserProfile)
        form_data["responsible"] = new_responsible.pk
        form = SingleResultForm(form_data, instance=course)
        self.assertTrue(form.is_valid())

        form.save(user=mommy.make(UserProfile))
        self.assertEqual(course.responsible_contributors[0], new_responsible)
Beispiel #8
0
def single_result_create(request, semester_id):
    semester = get_object_or_404(Semester, id=semester_id)
    raise_permission_denied_if_archived(semester)

    course = Course(semester=semester)

    form = SingleResultForm(request.POST or None, instance=course)

    if form.is_valid():
        form.save(user=request.user)

        messages.success(request, _("Successfully created single result."))
        return redirect('staff:semester_view', semester_id)
    else:
        return render(request, "staff_single_result_form.html", dict(semester=semester, form=form))
Beispiel #9
0
def single_result_create(request, semester_id):
    semester = get_object_or_404(Semester, id=semester_id)
    raise_permission_denied_if_archived(semester)

    course = Course(semester=semester)

    form = SingleResultForm(request.POST or None, instance=course)

    if form.is_valid():
        form.save(user=request.user)

        messages.success(request, _("Successfully created single result."))
        return redirect('staff:semester_view', semester_id)
    else:
        return render(request, "staff_single_result_form.html",
                      dict(semester=semester, form=form))
Beispiel #10
0
def helper_single_result_edit(request, semester, course):
    initial = {"responsible": course.responsible_contributor}
    answer_counts = defaultdict(int)
    for answer_counter in course.ratinganswer_counters:
        answer_counts[answer_counter.answer] = answer_counter.count
    for i in range(1, 6):
        initial["answer_" + str(i)] = answer_counts[i]

    form = SingleResultForm(request.POST or None, instance=course, initial=initial)

    if form.is_valid():
        form.save(user=request.user)

        messages.success(request, _("Successfully created single result."))
        return redirect("staff:semester_view", semester.id)
    else:
        return render(request, "staff_single_result_form.html", dict(semester=semester, form=form))
Beispiel #11
0
def helper_single_result_edit(request, semester, course):
    initial = {'responsible': course.responsible_contributor}
    answer_counts = defaultdict(int)
    for answer_counter in course.ratinganswer_counters:
        answer_counts[answer_counter.answer] = answer_counter.count
    for i in range(1, 6):
        initial['answer_' + str(i)] = answer_counts[i]

    form = SingleResultForm(request.POST or None,
                            instance=course,
                            initial=initial)

    if form.is_valid():
        form.save(user=request.user)

        messages.success(request, _("Successfully created single result."))
        return redirect('staff:semester_view', semester.id)
    else:
        return render(request, "staff_single_result_form.html",
                      dict(semester=semester, form=form))
Beispiel #12
0
    def test_single_result_form_saves_participant_and_voter_count(self):
        course = mommy.make(Course)
        evaluation = Evaluation(course=course, is_single_result=True)
        form_data = {
            "name_de": "qwertz",
            "name_en": "qwertz",
            "weight": 1,
            "event_date": "2014-01-01",
            "answer_1": 6,
            "answer_2": 0,
            "answer_3": 2,
            "answer_4": 0,
            "answer_5": 2,
            "course": course.pk
        }
        form = SingleResultForm(form_data, instance=evaluation, semester=evaluation.course.semester)
        self.assertTrue(form.is_valid())

        form.save(user=mommy.make(UserProfile))

        evaluation = Evaluation.objects.get()
        self.assertEqual(evaluation.num_participants, 10)
        self.assertEqual(evaluation.num_voters, 10)