Skip to content

Commit

Permalink
manage.py formati
Browse files Browse the repository at this point in the history
  • Loading branch information
fekoch committed Nov 11, 2024
1 parent 35d9fb3 commit 7c27940
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 19 deletions.
4 changes: 3 additions & 1 deletion evap/evaluation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions evap/evaluation/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
5 changes: 4 additions & 1 deletion evap/staff/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -2068,6 +2070,7 @@ def questionnaire_set_locked(request):
questionnaire.save()
return HttpResponse()


@require_POST
@manager_required
def questionnaire_set_active_dropout(request):
Expand Down
34 changes: 23 additions & 11 deletions evap/student/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
NO_ANSWER,
Contribution,
Evaluation,
Questionnaire,
RatingAnswerCounter,
Semester,
TextAnswer,
Questionnaire,
VoteTimestamp,
)
from evap.results.tools import (
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 7c27940

Please sign in to comment.