Repository: e-valuation/EvaP

Issue:
Refactor Evaluation state transition names
As a followup to #1310, we became aware that the evaluation state transition function's names aren't quite consistent along themselves. Also, naming could be improved throughout the whole project. For example from #1310, there is a name mismatch with

* `MoveToPreparedOperation` and `evaluation.ready_for_editors`
* `StartEvaluationOperation` and `evaluation.evaluation_begin`
* `RevertToReviewedOperation` and `evaluation.unpublish`


Discussion:
I would also propose `evaluation_begin` ->`begin_evaluation` (or `start_evaluation`), also `evaluation_end` -> `end_evaluation`.

I also thought about `review_finished`. While it accurately describes what has happened for the transition to occur, I think it should rather describe the transition itself. so `finish_review` might be better, or actually I don't see any reason to not call it `end_review` to be in line with `end_evaluation`.




Resolving patch:
diff --git a/evap/evaluation/models.py b/evap/evaluation/models.py
--- a/evap/evaluation/models.py
+++ b/evap/evaluation/models.py
@@ -605,7 +605,7 @@ def revert_to_new(self):
         pass
 
     @transition(field=state, source='approved', target='in_evaluation', conditions=[lambda self: self.is_in_evaluation_period])
-    def evaluation_begin(self):
+    def begin_evaluation(self):
         pass
 
     @transition(field=state, source=['evaluated', 'reviewed'], target='in_evaluation', conditions=[lambda self: self.is_in_evaluation_period])
@@ -613,15 +613,15 @@ def reopen_evaluation(self):
         pass
 
     @transition(field=state, source='in_evaluation', target='evaluated')
-    def evaluation_end(self):
+    def end_evaluation(self):
         pass
 
     @transition(field=state, source='evaluated', target='reviewed', conditions=[lambda self: self.is_fully_reviewed])
-    def review_finished(self):
+    def end_review(self):
         pass
 
     @transition(field=state, source=['new', 'reviewed'], target='reviewed', conditions=[lambda self: self.is_single_result])
-    def single_result_created(self):
+    def skip_review_single_result(self):
         pass
 
     @transition(field=state, source='reviewed', target='evaluated', conditions=[lambda self: not self.is_fully_reviewed])
@@ -776,13 +776,13 @@ def update_evaluations(cls):
         for evaluation in cls.objects.all():
             try:
                 if evaluation.state == "approved" and evaluation.vote_start_datetime <= datetime.now():
-                    evaluation.evaluation_begin()
+                    evaluation.begin_evaluation()
                     evaluation.save()
                     evaluations_new_in_evaluation.append(evaluation)
                 elif evaluation.state == "in_evaluation" and datetime.now() >= evaluation.vote_end_datetime:
-                    evaluation.evaluation_end()
+                    evaluation.end_evaluation()
                     if evaluation.is_fully_reviewed:
-                        evaluation.review_finished()
+                        evaluation.end_review()
                         if evaluation.grading_process_is_finished:
                             evaluation.publish()
                             evaluation_results_evaluations.append(evaluation)
diff --git a/evap/staff/forms.py b/evap/staff/forms.py
--- a/evap/staff/forms.py
+++ b/evap/staff/forms.py
@@ -388,7 +388,7 @@ def save(self, *args, **kw):
 
         # change state to "reviewed"
         # works only for single_results so the evaluation and its contribution must be saved first
-        evaluation.single_result_created()
+        evaluation.skip_review_single_result()
         evaluation.save()
 
         if hasattr(self.instance, 'old_course'):
diff --git a/evap/staff/views.py b/evap/staff/views.py
--- a/evap/staff/views.py
+++ b/evap/staff/views.py
@@ -189,7 +189,7 @@ def apply(request, evaluations, email_template=None, email_template_contributor=
             "Successfully reverted {} evaluations to in preparation.", len(evaluations)).format(len(evaluations)))
 
 
-class MoveToPreparedOperation(EvaluationOperation):
+class ReadyForEditorsOperation(EvaluationOperation):
     email_template_name = EmailTemplate.EDITOR_REVIEW_NOTICE
     confirmation_message = gettext_lazy("Do you want to send the following evaluations to editor review?")
 
@@ -230,7 +230,7 @@ def apply(request, evaluations, email_template=None, email_template_contributor=
                                             use_cc=True, additional_cc_users=editors, request=request)
 
 
-class StartEvaluationOperation(EvaluationOperation):
+class BeginEvaluationOperation(EvaluationOperation):
     email_template_name = EmailTemplate.EVALUATION_STARTED
     confirmation_message = gettext_lazy("Do you want to immediately start the following evaluations?")
 
@@ -250,7 +250,7 @@ def apply(request, evaluations, email_template=None, email_template_contributor=
 
         for evaluation in evaluations:
             evaluation.vote_start_datetime = datetime.now()
-            evaluation.evaluation_begin()
+            evaluation.begin_evaluation()
             evaluation.save()
         messages.success(request, ngettext("Successfully started {} evaluation.",
             "Successfully started {} evaluations.", len(evaluations)).format(len(evaluations)))
@@ -258,7 +258,7 @@ def apply(request, evaluations, email_template=None, email_template_contributor=
             email_template.send_to_users_in_evaluations(evaluations, [EmailTemplate.Recipients.ALL_PARTICIPANTS], use_cc=False, request=request)
 
 
-class RevertToReviewedOperation(EvaluationOperation):
+class UnpublishOperation(EvaluationOperation):
     confirmation_message = gettext_lazy("Do you want to unpublish the following evaluations?")
 
     @staticmethod
@@ -314,9 +314,9 @@ def apply(request, evaluations, email_template=None, email_template_contributor=
 
 EVALUATION_OPERATIONS = {
         'new': RevertToNewOperation,
-        'prepared': MoveToPreparedOperation,
-        'in_evaluation': StartEvaluationOperation,
-        'reviewed': RevertToReviewedOperation,
+        'prepared': ReadyForEditorsOperation,
+        'in_evaluation': BeginEvaluationOperation,
+        'reviewed': UnpublishOperation,
         'published': PublishOperation,
 }
 
@@ -1149,7 +1149,7 @@ def evaluation_textanswers_update_publish(request):
     answer.save()
 
     if evaluation.state == "evaluated" and evaluation.is_fully_reviewed:
-        evaluation.review_finished()
+        evaluation.end_review()
         evaluation.save()
     if evaluation.state == "reviewed" and not evaluation.is_fully_reviewed:
         evaluation.reopen_review()


Test patch:
diff --git a/evap/evaluation/tests/test_models.py b/evap/evaluation/tests/test_models.py
--- a/evap/evaluation/tests/test_models.py
+++ b/evap/evaluation/tests/test_models.py
@@ -110,7 +110,7 @@ def test_evaluation_ended(self):
         baker.make(Evaluation, course=course_2, state='in_evaluation', vote_start_datetime=datetime.now() - timedelta(days=2),
                    vote_end_date=date.today(), wait_for_grade_upload_before_publishing=False)
 
-        with patch('evap.evaluation.models.Evaluation.evaluation_end') as mock:
+        with patch('evap.evaluation.models.Evaluation.end_evaluation') as mock:
             Evaluation.update_evaluations()
 
         self.assertEqual(mock.call_count, 1)
@@ -173,7 +173,7 @@ def test_single_result_can_be_deleted_only_in_reviewed(self):
             textanswer_visibility=Contribution.TextAnswerVisibility.GENERAL_TEXTANSWERS,
         )
         baker.make(RatingAnswerCounter, answer=1, count=1, question=Questionnaire.single_result_questionnaire().questions.first(), contribution=contribution)
-        evaluation.single_result_created()
+        evaluation.skip_review_single_result()
         evaluation.publish()
         evaluation.save()
 
@@ -202,7 +202,7 @@ def test_single_result_can_be_published():
         )
         baker.make(RatingAnswerCounter, answer=1, count=1, question=Questionnaire.single_result_questionnaire().questions.first(), contribution=contribution)
 
-        single_result.single_result_created()
+        single_result.skip_review_single_result()
         single_result.publish()  # used to crash
 
     def test_second_vote_sets_can_publish_text_results_to_true(self):
@@ -354,7 +354,7 @@ def test_textanswer_review_state(self):
             evaluation.TextAnswerReviewState.REVIEW_NEEDED,
         )
 
-        evaluation.evaluation_end()
+        evaluation.end_evaluation()
         evaluation.save()
 
         self.assert_textanswer_review_state(
diff --git a/evap/grades/tests.py b/evap/grades/tests.py
--- a/evap/grades/tests.py
+++ b/evap/grades/tests.py
@@ -114,17 +114,17 @@ def test_upload_final_grades(self):
         self.helper_check_final_grade_upload(course, 0)
 
         # state: in_evaluation
-        evaluation.evaluation_begin()
+        evaluation.begin_evaluation()
         evaluation.save()
         self.helper_check_final_grade_upload(course, 0)
 
         # state: evaluated
-        evaluation.evaluation_end()
+        evaluation.end_evaluation()
         evaluation.save()
         self.helper_check_final_grade_upload(course, 0)
 
         # state: reviewed
-        evaluation.review_finished()
+        evaluation.end_review()
         evaluation.save()
         self.helper_check_final_grade_upload(
             course, evaluation.num_participants + evaluation.contributions.exclude(contributor=None).count())
@@ -137,9 +137,9 @@ def test_upload_final_grades(self):
     def test_toggle_no_grades(self):
         evaluation = self.evaluation
         evaluation.manager_approve()
-        evaluation.evaluation_begin()
-        evaluation.evaluation_end()
-        evaluation.review_finished()
+        evaluation.begin_evaluation()
+        evaluation.end_evaluation()
+        evaluation.end_review()
         evaluation.save()
 
         self.assertFalse(evaluation.course.gets_no_grade_documents)
diff --git a/evap/results/tests/test_tools.py b/evap/results/tests/test_tools.py
--- a/evap/results/tests/test_tools.py
+++ b/evap/results/tests/test_tools.py
@@ -30,7 +30,7 @@ def test_caching_lifecycle(self):
 
         self.assertIsNone(caches['results'].get(get_results_cache_key(evaluation)))
 
-        evaluation.evaluation_end()
+        evaluation.end_evaluation()
         evaluation.save()
 
         self.assertIsNotNone(caches['results'].get(get_results_cache_key(evaluation)))
@@ -45,8 +45,8 @@ def test_caching_works_after_multiple_transitions(self):
 
         self.assertIsNone(caches['results'].get(get_results_cache_key(evaluation)))
 
-        evaluation.evaluation_end()
-        evaluation.review_finished()
+        evaluation.end_evaluation()
+        evaluation.end_review()
         evaluation.publish()
         evaluation.save()
 
diff --git a/evap/results/tests/test_views.py b/evap/results/tests/test_views.py
--- a/evap/results/tests/test_views.py
+++ b/evap/results/tests/test_views.py
@@ -335,8 +335,8 @@ def helper_test_answer_visibility_two_voters(self, user_email):
 
     def test_answer_visibility_one_voter(self):
         let_user_vote_for_evaluation(self.app, self.student1, self.evaluation)
-        self.evaluation.evaluation_end()
-        self.evaluation.review_finished()
+        self.evaluation.end_evaluation()
+        self.evaluation.end_review()
         self.evaluation.publish()
         self.evaluation.save()
         self.assertEqual(self.evaluation.voters.count(), 1)
@@ -349,8 +349,8 @@ def test_answer_visibility_one_voter(self):
     def test_answer_visibility_two_voters(self):
         let_user_vote_for_evaluation(self.app, self.student1, self.evaluation)
         let_user_vote_for_evaluation(self.app, self.student2, self.evaluation)
-        self.evaluation.evaluation_end()
-        self.evaluation.review_finished()
+        self.evaluation.end_evaluation()
+        self.evaluation.end_review()
         self.evaluation.publish()
         self.evaluation.save()
         self.assertEqual(self.evaluation.voters.count(), 2)
diff --git a/evap/staff/tests/test_views.py b/evap/staff/tests/test_views.py
--- a/evap/staff/tests/test_views.py
+++ b/evap/staff/tests/test_views.py
@@ -2366,7 +2366,7 @@ def test_review_actions(self):
 
     def test_finishing_review_updates_results(self):
         let_user_vote_for_evaluation(self.app, self.student2, self.evaluation)
-        self.evaluation.evaluation_end()
+        self.evaluation.end_evaluation()
         self.evaluation.can_publish_text_results = True
         self.evaluation.save()
         results = get_results(self.evaluation)
@@ -2376,7 +2376,7 @@ def test_finishing_review_updates_results(self):
         textanswer = self.evaluation.unreviewed_textanswer_set[0]
         textanswer.state = TextAnswer.State.PUBLISHED
         textanswer.save()
-        self.evaluation.review_finished()
+        self.evaluation.end_review()
         self.evaluation.save()
         results = get_results(self.evaluation)