示例#1
0
文件: tests.py 项目: BenBals/EvaP
    def test_toggle_no_grades(self):
        course = mommy.make(
            Course,
            name_en="Toggle",
            vote_start_datetime=datetime.now(),
            state="reviewed",
            participants=[self.student, self.student2, self.student3],
            voters=[self.student, self.student2]
        )
        contribution = Contribution(course=course, contributor=UserProfile.objects.get(username="******"),
                                    responsible=True, can_edit=True, comment_visibility=Contribution.ALL_COMMENTS)
        contribution.save()
        contribution.questionnaires.set([mommy.make(Questionnaire, type=Questionnaire.CONTRIBUTOR)])

        course.general_contribution.questionnaires.set([mommy.make(Questionnaire)])

        self.assertFalse(course.gets_no_grade_documents)

        response = self.app.post("/grades/toggle_no_grades", params={"course_id": course.id}, user="******")
        self.assertEqual(response.status_code, 200)
        course = Course.objects.get(id=course.id)
        self.assertTrue(course.gets_no_grade_documents)
        # course should get published here
        self.assertEqual(course.state, "published")
        self.assertEqual(len(mail.outbox), course.num_participants + course.contributions.exclude(contributor=None).count())

        response = self.app.post("/grades/toggle_no_grades", params={"course_id": course.id}, user="******")
        self.assertEqual(response.status_code, 200)
        course = Course.objects.get(id=course.id)
        self.assertFalse(course.gets_no_grade_documents)
示例#2
0
文件: tests.py 项目: kateyy/EvaP
    def setUpTestData(cls):
        mommy.make(UserProfile, username="******", groups=[Group.objects.get(name="Grade publisher")])
        mommy.make(UserProfile, username="******", email="*****@*****.**")
        mommy.make(UserProfile, username="******", email="*****@*****.**")
        mommy.make(UserProfile, username="******", email="*****@*****.**")
        mommy.make(UserProfile, username="******", email="*****@*****.**")

        course = mommy.make(Course,
            name_en="Test",
            vote_start_date=datetime.date.today(),
            participants=[
                UserProfile.objects.get(username="******"),
                UserProfile.objects.get(username="******"),
                UserProfile.objects.get(username="******"),
            ],
            voters=[
                UserProfile.objects.get(username="******"),
                UserProfile.objects.get(username="******"),
            ]
        )
        contribution = Contribution(course=course, contributor=UserProfile.objects.get(username="******"), responsible=True)
        contribution.save()
        contribution.questionnaires = [mommy.make(Questionnaire, is_for_contributors=True)]

        course.general_contribution.questionnaires = [mommy.make(Questionnaire)]
示例#3
0
文件: forms.py 项目: lmm-git/EvaP
    def save(self, *args, **kw):
        user = kw.pop("user")
        self.instance.last_modified_user = user
        self.instance.vote_start_date = self.cleaned_data['event_date']
        self.instance.vote_end_date = self.cleaned_data['event_date']
        self.instance.is_graded = False
        super().save(*args, **kw)

        if not Contribution.objects.filter(course=self.instance,
                                           responsible=True).exists():
            contribution = Contribution(
                course=self.instance,
                contributor=self.cleaned_data['responsible'],
                responsible=True)
            contribution.save()
            contribution.questionnaires.add(
                Questionnaire.get_single_result_questionnaire())

        # set answers
        contribution = Contribution.objects.get(course=self.instance,
                                                responsible=True)
        for i in range(1, 6):
            count = {'count': self.cleaned_data['answer_' + str(i)]}
            answer_counter, created = RatingAnswerCounter.objects.update_or_create(
                contribution=contribution,
                question=contribution.questionnaires.first(
                ).question_set.first(),
                answer=i,
                defaults=count)

        # change state to "reviewed"
        # works only for single_results so the course and its contribution must be saved first
        self.instance.single_result_created()
        self.instance.save()
示例#4
0
    def test_toggle_no_grades(self):
        evaluation = mommy.make(
            Evaluation,
            name_en="Toggle",
            vote_start_datetime=datetime.now(),
            state="reviewed",
            participants=[self.student, self.student2, self.student3],
            voters=[self.student, self.student2]
        )
        contribution = Contribution(evaluation=evaluation, contributor=UserProfile.objects.get(username="******"),
                                    can_edit=True, textanswer_visibility=Contribution.GENERAL_TEXTANSWERS)
        contribution.save()
        contribution.questionnaires.set([mommy.make(Questionnaire, type=Questionnaire.CONTRIBUTOR)])

        evaluation.general_contribution.questionnaires.set([mommy.make(Questionnaire)])

        self.assertFalse(evaluation.course.gets_no_grade_documents)

        response = self.app.post("/grades/toggle_no_grades", params={"course_id": evaluation.course.id}, user="******")
        self.assertEqual(response.status_code, 200)
        evaluation = Evaluation.objects.get(id=evaluation.id)
        self.assertTrue(evaluation.course.gets_no_grade_documents)
        # evaluation should get published here
        self.assertEqual(evaluation.state, "published")
        self.assertEqual(len(mail.outbox), evaluation.num_participants + evaluation.contributions.exclude(contributor=None).count())

        response = self.app.post("/grades/toggle_no_grades", params={"course_id": evaluation.course.id}, user="******")
        self.assertEqual(response.status_code, 200)
        evaluation = Evaluation.objects.get(id=evaluation.id)
        self.assertFalse(evaluation.course.gets_no_grade_documents)
示例#5
0
文件: tests.py 项目: kateyy/EvaP
    def test_toggle_no_grades(self):
        course = mommy.make(Course,
            name_en="Toggle",
            vote_start_date=datetime.date.today(),
            state="reviewed",
            participants=[
                UserProfile.objects.get(username="******"),
                UserProfile.objects.get(username="******"),
                UserProfile.objects.get(username="******"),
            ],
            voters=[
                UserProfile.objects.get(username="******"),
                UserProfile.objects.get(username="******"),
            ]
        )
        contribution = Contribution(course=course, contributor=UserProfile.objects.get(username="******"), responsible=True)
        contribution.save()
        contribution.questionnaires = [mommy.make(Questionnaire, is_for_contributors=True)]

        course.general_contribution.questionnaires = [mommy.make(Questionnaire)]

        toggle_url = "/grades/semester/"+str(course.semester.id)+"/course/"+str(course.id)+"/togglenogrades"

        self.assertFalse(course.gets_no_grade_documents)

        self.get_submit_assert_302(toggle_url, "grade_publisher")
        course = Course.objects.get(id=course.id)
        self.assertTrue(course.gets_no_grade_documents)
        # course should get published here
        self.assertEqual(course.state, "published")
        self.assertEqual(len(mail.outbox), course.num_participants + course.contributions.exclude(contributor=None).count())

        self.get_submit_assert_302(toggle_url, "grade_publisher")
        course = Course.objects.get(id=course.id)
        self.assertFalse(course.gets_no_grade_documents)
示例#6
0
文件: forms.py 项目: jb3rndt/EvaP
    def save(self, commit=True):
        new_course: Course = super().save()
        # we need to create copies of evaluations and their participation as well
        for old_evaluation in self.old_course.evaluations.exclude(
                is_single_result=True):
            new_evaluation = Evaluation(
                **{
                    field: getattr(old_evaluation, field)
                    for field in self.EVALUATION_COPIED_FIELDS
                },
                can_publish_text_results=False,
                course=new_course,
                vote_start_datetime=self.cleaned_data["vote_start_datetime"],
                vote_end_date=self.cleaned_data["vote_end_date"],
            )
            new_evaluation.save()

            new_evaluation.contributions.all().delete(
            )  # delete default general contribution
            for old_contribution in old_evaluation.contributions.all():
                new_contribution = Contribution(
                    **{
                        field: getattr(old_contribution, field)
                        for field in self.CONTRIBUTION_COPIED_FIELDS
                    },
                    evaluation=new_evaluation,
                )
                new_contribution.save()
                new_contribution.questionnaires.set(
                    old_contribution.questionnaires.all())

        return new_course
示例#7
0
文件: views.py 项目: piepmatz/EvaP
def questionnaire_view(request, questionnaire_id):
    questionnaire = get_object_or_404(Questionnaire, id=questionnaire_id)

    # build forms
    contribution = Contribution(contributor=request.user)
    form = QuestionsForm(request.POST or None, contribution=contribution, questionnaire=questionnaire)

    return render_to_response("fsr_questionnaire_view.html", dict(forms=[form], questionnaire=questionnaire), context_instance=RequestContext(request))
示例#8
0
文件: forms.py 项目: PFischbeck/EvaP
 def __init__(self, data=None, instance=None, evaluation=None, **kwargs):
     initial = None
     copied_instance = Contribution(evaluation=evaluation)
     if instance:
         opts = self._meta
         initial = forms.models.model_to_dict(instance, opts.fields, opts.exclude)
         del initial["evaluation"]
         initial["does_not_contribute"] = not instance.questionnaires.exists()
     super().__init__(data, initial=initial, instance=copied_instance, evaluation=evaluation, **kwargs)
示例#9
0
文件: views.py 项目: lmm-git/EvaP
def questionnaire_view(request, questionnaire_id):
    questionnaire = get_object_or_404(Questionnaire, id=questionnaire_id)

    # build forms
    contribution = Contribution(contributor=request.user)
    form = QuestionsForm(request.POST or None,
                         contribution=contribution,
                         questionnaire=questionnaire)

    return render(request, "staff_questionnaire_view.html",
                  dict(forms=[form], questionnaire=questionnaire))
示例#10
0
文件: tests.py 项目: rschwanhold/EvaP
    def setUpTestData(cls):
        mommy.make(UserProfile,
                   username="******",
                   groups=[Group.objects.get(name="Grade publisher")])
        mommy.make(UserProfile,
                   username="******",
                   email="*****@*****.**")
        mommy.make(UserProfile,
                   username="******",
                   email="*****@*****.**")
        mommy.make(UserProfile,
                   username="******",
                   email="*****@*****.**")
        responsible = mommy.make(UserProfile,
                                 username="******",
                                 email="*****@*****.**")

        cls.course = mommy.make(
            Course,
            name_en="Test",
            vote_start_date=datetime.date.today(),
            participants=[
                UserProfile.objects.get(username="******"),
                UserProfile.objects.get(username="******"),
                UserProfile.objects.get(username="******"),
            ],
            voters=[
                UserProfile.objects.get(username="******"),
                UserProfile.objects.get(username="******"),
            ])
        contribution = Contribution(
            course=cls.course,
            contributor=responsible,
            responsible=True,
            can_edit=True,
            comment_visibility=Contribution.ALL_COMMENTS)
        contribution.save()
        contribution.questionnaires = [
            mommy.make(Questionnaire, is_for_contributors=True)
        ]

        cls.course.general_contribution.questionnaires = [
            mommy.make(Questionnaire)
        ]

        cls.activation = SemesterGradeDownloadActivation.objects.create(
            semester=cls.course.semester, is_active=True)
示例#11
0
文件: forms.py 项目: rschwanhold/EvaP
    def save(self, *args, **kw):
        user = kw.pop("user")
        self.instance.last_modified_user = user
        self.instance.vote_start_date = self.cleaned_data['event_date']
        self.instance.vote_end_date = self.cleaned_data['event_date']
        self.instance.is_graded = False
        super().save(*args, **kw)

        single_result_questionnaire = Questionnaire.single_result_questionnaire(
        )
        single_result_question = single_result_questionnaire.question_set.first(
        )

        if not Contribution.objects.filter(course=self.instance,
                                           responsible=True).exists():
            contribution = Contribution(
                course=self.instance,
                contributor=self.cleaned_data['responsible'],
                responsible=True,
                can_edit=True,
                comment_visibility=Contribution.ALL_COMMENTS)
            contribution.save()
            contribution.questionnaires.add(single_result_questionnaire)

        # set answers
        contribution = Contribution.objects.get(course=self.instance,
                                                responsible=True)
        total_votes = 0
        for i in range(1, 6):
            count = self.cleaned_data['answer_' + str(i)]
            total_votes += count
            RatingAnswerCounter.objects.update_or_create(
                contribution=contribution,
                question=single_result_question,
                answer=i,
                defaults={'count': count})
        self.instance._participant_count = total_votes
        self.instance._voter_count = total_votes

        # change state to "reviewed"
        # works only for single_results so the course and its contribution must be saved first
        self.instance.single_result_created()
        self.instance.save()
示例#12
0
    def setUpTestData(cls):
        mommy.make(UserProfile,
                   username="******",
                   groups=[Group.objects.get(name="Grade publisher")])
        cls.student = mommy.make(UserProfile,
                                 username="******",
                                 email="*****@*****.**")
        cls.student2 = mommy.make(UserProfile,
                                  username="******",
                                  email="*****@*****.**")
        cls.student3 = mommy.make(UserProfile,
                                  username="******",
                                  email="*****@*****.**")
        responsible = mommy.make(UserProfile,
                                 username="******",
                                 email="*****@*****.**")

        cls.course = mommy.make(
            Course,
            name_en="Test",
            vote_start_datetime=datetime.now() - timedelta(10),
            vote_end_date=datetime.now() + timedelta(10),
            participants=[cls.student, cls.student2, cls.student3],
            voters=[cls.student, cls.student2],
        )
        contribution = Contribution(
            course=cls.course,
            contributor=responsible,
            responsible=True,
            can_edit=True,
            comment_visibility=Contribution.ALL_COMMENTS)
        contribution.save()
        contribution.questionnaires.set(
            [mommy.make(Questionnaire, is_for_contributors=True)])

        cls.course.general_contribution.questionnaires.set(
            [mommy.make(Questionnaire)])

        cls.activation = SemesterGradeDownloadActivation.objects.create(
            semester=cls.course.semester, is_active=True)