Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds shortcut button to add exam evaluation #2050

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refactor exam evaluation generation
  • Loading branch information
FSadrieh committed Apr 22, 2024
commit f075998c712eed99e380268261924cb0e163429e
15 changes: 14 additions & 1 deletion evap/evaluation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import uuid
from collections import defaultdict
from dataclasses import dataclass
from datetime import date, datetime, timedelta
from datetime import date, datetime, time, timedelta
from enum import Enum, auto
from numbers import Real

Expand Down Expand Up @@ -443,6 +443,19 @@ class State:
verbose_name=_("wait for grade upload before publishing"), default=True
)

@property
def has_exam(self):
return self.course.evaluations.filter(name_de="Klausur", name_en="Exam").exists()

def make_exam_evaluation(self, exam_date: date, participants, eval_contributions):
self.vote_start_datetime = datetime.combine(exam_date + timedelta(days=1), time(8, 0))
self.vote_end_date = exam_date + timedelta(days=3)
self.save()
self.participants.set(participants)
for contribution in eval_contributions:
self.contributions.create(contributor=contribution.contributor)
self.general_contribution.questionnaires.set(settings.EXAM_QUESTIONNAIRES)

class TextAnswerReviewState(Enum):
do_not_call_in_templates = True # pylint: disable=invalid-name
NO_TEXTANSWERS = auto()
Expand Down
2 changes: 1 addition & 1 deletion evap/staff/templates/staff_semester_view_evaluation.html
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
<a href="{% url 'staff:evaluation_copy' evaluation.id %}" class="btn btn-sm btn-light" data-bs-toggle="tooltip" title="{% translate "Copy" %}">
<span class="fas fa-copy"></span>
</a>
{% if evaluation.has_exam%}
{% if not evaluation.has_exam%}
<a class="btn btn-sm btn-dark" data-bs-toggle="tooltip"
onclick="createExamEvaluationShow({{ evaluation.id }}, '{{ course.name|escapejs }}');"
title="{% trans 'Create exam evaluation' %}">
Expand Down
18 changes: 7 additions & 11 deletions evap/staff/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,6 @@ class Stats:
degree_stats_with_total = cast(dict[Degree | str, Stats], degree_stats)
degree_stats_with_total["total"] = total_stats

for evaluation in evaluations:
evaluation.has_exam = evaluation.course.evaluations.filter(name_de="Klausur", name_en="Exam").exists()

template_data = {
"semester": semester,
"evaluations": evaluations,
Expand Down Expand Up @@ -1066,23 +1063,22 @@ def create_exam_evaluation(request):
if evaluation.course.evaluations.filter(name_de="Klausur", name_en="Exam").exists():
raise SuspiciousOperation("An exam evaluation already exists for this course.")
FSadrieh marked this conversation as resolved.
Show resolved Hide resolved

evaluation.weight = 9
evaluation_end_date = exam_date - timedelta(days=1)
if evaluation.vote_start_datetime > evaluation_end_date:
raise SuspiciousOperation("The exam date is before the start date of the main evaluation")
FSadrieh marked this conversation as resolved.
Show resolved Hide resolved

evaluation.weight = 9
evaluation.vote_end_date = evaluation_end_date
evaluation.save()

exam_evaluation = Evaluation(
course=evaluation.course, name_de="Klausur", name_en="Exam", weight=1, is_rewarded=False
)
exam_evaluation.vote_start_datetime = datetime.combine(exam_date + timedelta(days=1), time(8, 0))
exam_evaluation.vote_end_date = exam_date + timedelta(days=3)
exam_evaluation.save()
exam_evaluation.participants.set(evaluation.participants.all())
for contribution in evaluation.contributions.exclude(contributor=None):
exam_evaluation.contributions.create(contributor=contribution.contributor)
exam_evaluation.general_contribution.questionnaires.set(settings.EXAM_QUESTIONNAIRES)
exam_evaluation.make_exam_evaluation(
exam_date=exam_date,
participants=evaluation.participants.all(),
eval_contributions=evaluation.contributions.exclude(contributor=None),
)
messages.success(request, _("Successfully created exam evaluation."))
return HttpResponse() # 200 OK

Expand Down