diff --git a/evap/evaluation/models.py b/evap/evaluation/models.py index 00a8f2799..dd6acd6f5 100644 --- a/evap/evaluation/models.py +++ b/evap/evaluation/models.py @@ -256,7 +256,9 @@ def is_below_contributors(self): return self.type == self.Type.BOTTOM @property - def can_be_edited_by_manager(self): # TODO@Felix: modify this to also work for dropout questionnaires? or change code + def can_be_edited_by_manager( + self, + ): # TODO@Felix: modify this to also work for dropout questionnaires? or change code if is_prefetched(self, "contributions"): if all(is_prefetched(contribution, "evaluation") for contribution in self.contributions.all()): return all( diff --git a/evap/evaluation/tests/test_models.py b/evap/evaluation/tests/test_models.py index 0bdf658a4..8758f4be2 100644 --- a/evap/evaluation/tests/test_models.py +++ b/evap/evaluation/tests/test_models.py @@ -463,12 +463,12 @@ def test_publishing_and_unpublishing_effect_on_template_cache(self): ) def assert_textanswer_review_state( - self, - evaluation, - expected_default_value, - expected_value_with_gets_no_grade_documents, - expected_value_with_wait_for_grade_upload_before_publishing, - expected_value_after_grade_upload, + self, + evaluation, + expected_default_value, + expected_value_with_gets_no_grade_documents, + expected_value_with_wait_for_grade_upload_before_publishing, + expected_value_after_grade_upload, ): self.assertEqual(evaluation.textanswer_review_state, expected_default_value) diff --git a/evap/staff/views.py b/evap/staff/views.py index f7c878680..e8585a74d 100644 --- a/evap/staff/views.py +++ b/evap/staff/views.py @@ -1801,7 +1801,9 @@ def questionnaire_index(request): prefetch_list = ("questions", "contributions__evaluation") general_questionnaires = Questionnaire.objects.general_questionnaires().prefetch_related(*prefetch_list) contributor_questionnaires = Questionnaire.objects.contributor_questionnaires().prefetch_related(*prefetch_list) - dropout_questionnaires = Questionnaire.objects.dropout_questionnaires().prefetch_related(*prefetch_list) # TODO@Felix: is prefetch related needed? + dropout_questionnaires = Questionnaire.objects.dropout_questionnaires().prefetch_related( + *prefetch_list + ) # TODO@Felix: is prefetch related needed? if filter_questionnaires: general_questionnaires = general_questionnaires.exclude(visibility=Questionnaire.Visibility.HIDDEN) @@ -2068,6 +2070,7 @@ def questionnaire_set_locked(request): questionnaire.save() return HttpResponse() + @require_POST @manager_required def questionnaire_set_active_dropout(request): diff --git a/evap/student/views.py b/evap/student/views.py index 3eccce1fa..dc460d192 100644 --- a/evap/student/views.py +++ b/evap/student/views.py @@ -20,10 +20,10 @@ NO_ANSWER, Contribution, Evaluation, + Questionnaire, RatingAnswerCounter, Semester, TextAnswer, - Questionnaire, VoteTimestamp, ) from evap.results.tools import ( @@ -214,7 +214,13 @@ def get_vote_page_form_groups( return form_groups -def render_vote_page(request: HttpRequest, evaluation: Evaluation, preview: bool, for_rendering_in_modal: bool = False, show_dropout_questionnaire: bool = False): +def render_vote_page( + request: HttpRequest, + evaluation: Evaluation, + preview: bool, + for_rendering_in_modal: bool = False, + show_dropout_questionnaire: bool = False, +): form_groups = get_vote_page_form_groups(request, evaluation, preview) assert preview or not all(form.is_valid() for form_group in form_groups.values() for form in form_group) @@ -249,14 +255,20 @@ def render_vote_page(request: HttpRequest, evaluation: Evaluation, preview: bool if show_dropout_questionnaire: dropout_questionnaire = Questionnaire.objects.active_dropout_questionnaire().first() - evaluation_form_group_top.insert(0, QuestionnaireVotingForm(request.POST or None, - contribution=evaluation.general_contribution, - questionnaire=dropout_questionnaire)) + if dropout_questionnaire: + evaluation_form_group_top.insert( + 0, + QuestionnaireVotingForm( + request.POST or None, + contribution=evaluation.general_contribution, + questionnaire=dropout_questionnaire, + ), + ) # TODO@felix: also set contributor questionnaires to default for form in evaluation_form_group_top + evaluation_form_group_bottom: - for (name, field) in form.fields.items(): - if hasattr(field, 'choices'): - field.value = field.choices[-1] # TODO@Felix: better way to do this? + for name, field in form.fields.items(): + if hasattr(field, "choices"): + field.value = field.choices[-1] # TODO@Felix: tried doing this with NO_ANSWER, but that didnt work template_data = { "contributor_errors_exist": contributor_errors_exist, @@ -336,9 +348,9 @@ def vote(request: HttpRequest, evaluation_id: int): # noqa: PLR0912 if not evaluation.can_publish_text_results: # enable text result publishing if first user confirmed that publishing is okay or second user voted if ( - request.POST.get("text_results_publish_confirmation_top") == "on" - or request.POST.get("text_results_publish_confirmation_bottom") == "on" - or evaluation.voters.count() >= 2 + request.POST.get("text_results_publish_confirmation_top") == "on" + or request.POST.get("text_results_publish_confirmation_bottom") == "on" + or evaluation.voters.count() >= 2 ): evaluation.can_publish_text_results = True evaluation.save()