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
Fix
  • Loading branch information
Frederic Sadrieh committed Jun 10, 2024
commit 90e87a0c5754ce6ebe1194f9aa8357dbceb2aa5a
41 changes: 22 additions & 19 deletions evap/evaluation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
from django.core.exceptions import ValidationError
from django.core.mail import EmailMultiAlternatives
from django.db import IntegrityError, models, transaction
from django.db.models import CheckConstraint, Count, F, Manager, OuterRef, Q, Subquery, Value, query
from django.db.models import CheckConstraint, Count, F, Manager, OuterRef, Q, Subquery, Value
from django.db.models.functions import Coalesce, Lower, NullIf, TruncDate
from django.db.models.query import QuerySet
from django.dispatch import Signal, receiver
from django.template import Context, Template
from django.template.defaultfilters import linebreaksbr
Expand Down Expand Up @@ -447,33 +448,35 @@ class State:
def has_exam(self):
return self.course.evaluations.filter(name_de="Klausur", name_en="Exam").exists()

def make_exam_evaluation(
@transaction.atomic
def create_exam_evaluation(
self,
exam_date: datetime,
evaluation_end_date: datetime,
FSadrieh marked this conversation as resolved.
Show resolved Hide resolved
participants: query.QuerySet["UserProfile"],
eval_contributions: query.QuerySet["Contribution"],
):
def _set_exam_evaluation_attributes(
FSadrieh marked this conversation as resolved.
Show resolved Hide resolved
exam_evaluation: Evaluation,
exam_date: date,
participants: QuerySet["UserProfile"],
eval_contributions: QuerySet["Contribution"],
):
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(participants)
for contribution in eval_contributions:
exam_evaluation.contributions.create(contributor=contribution.contributor)
exam_evaluation.general_contribution.questionnaires.set(settings.EXAM_QUESTIONNAIRE_IDS)
exam_evaluation.save()

self.weight = 9
self.vote_end_date = evaluation_end_date
self.save()
participants = self.participants.all()
eval_contributions = self.contributions.exclude(contributor=None)
exam_evaluation = Evaluation(course=self.course, name_de="Klausur", name_en="Exam", weight=1, is_rewarded=False)
exam_evaluation.set_exam_evaluation_attributes(exam_date, participants, eval_contributions)
exam_evaluation.save()
_set_exam_evaluation_attributes(exam_evaluation, exam_date, participants, eval_contributions)

def set_exam_evaluation_attributes(
self,
exam_date: date,
participants: query.QuerySet["UserProfile"],
eval_contributions: query.QuerySet["Contribution"],
):
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_QUESTIONNAIRE_IDS)

class TextAnswerReviewState(Enum):
do_not_call_in_templates = True # pylint: disable=invalid-name
Expand Down
8 changes: 8 additions & 0 deletions evap/staff/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2011,6 +2011,14 @@ def test_exam_evaluation_with_wrong_date(self):
page, "The exam date is before the start date of the main evaluation. No exam evaluation was created."
)

def test_exam_evaluation_with_missing_date(self):
self.app.post(
self.url,
user=self.manager,
status=400,
params={"evaluation_id": self.evaluation.pk},
)


class TestCourseCopyView(WebTestStaffMode):
@classmethod
Expand Down
7 changes: 2 additions & 5 deletions evap/staff/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,6 @@ def course_copy(request, course_id):

@require_POST
@manager_required
@transaction.atomic
def create_exam_evaluation(request):
evaluation = get_object_from_dict_pk_entry_or_logged_40x(Evaluation, request.POST, "evaluation_id")
if evaluation.is_single_result:
Expand All @@ -1064,7 +1063,7 @@ def create_exam_evaluation(request):
try:
exam_datetime = request.POST.get("exam_date")
exam_datetime = datetime.combine(datetime.strptime(exam_datetime, "%Y-%m-%d"), datetime.min.time())
except ValueError:
except TypeError:
return HttpResponseBadRequest("Exam date missing or invalid.")

evaluation_end_date = exam_datetime - timedelta(days=1)
Expand All @@ -1074,10 +1073,8 @@ def create_exam_evaluation(request):
)
return HttpResponse()

evaluation.make_exam_evaluation(
evaluation.create_exam_evaluation(
exam_date=exam_datetime,
participants=evaluation.participants.all(),
eval_contributions=evaluation.contributions.exclude(contributor=None),
evaluation_end_date=evaluation_end_date,
)
messages.success(request, _("Successfully created exam evaluation."))
Expand Down
Loading