Skip to content

Commit

Permalink
Made button work. Now need a check that the exam is not already there…
Browse files Browse the repository at this point in the history
… and teeeeeeeeeeeeeeeeeeeeeeeeeests
  • Loading branch information
FSadrieh committed Nov 6, 2023
1 parent 7f675f6 commit b5211af
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 40 deletions.
25 changes: 9 additions & 16 deletions evap/staff/templates/staff_semester_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ <h3>
<col />
<col style="width: 14em" />
<col style="width: 12em" />
<col style="width: 12.9em" />
<col style="width: 9em" />
</colgroup>
<thead>
<tr>
Expand Down Expand Up @@ -407,23 +407,17 @@ <h3>
<a class="btn btn-sm btn-dark" data-bs-toggle="tooltip"
href="{% url 'staff:evaluation_create_for_course' course.id %}"
title="{% trans 'Create evaluation for this course' %}">
<span class="fas fa-clipboard-check fa-fw"></span>
<span class="fas fa-clipboard-check"></span>
</a>
<a class="btn btn-sm btn-dark" data-bs-toggle="tooltip"
href="{% url 'staff:single_result_create_for_course' course.id %}"
title="{% trans 'Create single result for this course' %}">
<span class="fas fa-square-poll-vertical fa-fw"></span>
</a>
<a class="btn btn-sm btn-dark" data-bs-toggle="tooltip"
href="{% url 'staff:course_copy' course.id %}"
title="{% trans 'Copy course' %}">
<span class="fas fa-copy fa-fw"></span>
</a>
<a class="btn btn-sm btn-dark" data-bs-toggle="tooltip"
onclick="createExamEvaluationShow({{ course.id }}, '{{ course.name|escapejs }}');"
title="{% trans 'Create exam evaluation' %}">
<span class="fas fa-file-pen fa-fw"></span>
</a>
<span class="fas fa-square-poll-vertical"></span>
</a>
<a class="btn btn-sm btn-dark" data-bs-toggle="tooltip"
href="{% url 'staff:course_copy' course.id %}"
title="{% trans 'Copy course' %}">
<span class="fas fa-copy"></span> </a>
{% endif %}
{% if course.can_be_deleted_by_manager %}
<button type="button" onclick="deleteCourseModalShow({{ course.id }}, '{{ course.name|escapejs }}');" class="btn btn-sm btn-outline-danger" data-bs-toggle="tooltip" data-bs-placement="top" title="{% trans 'Delete' %}">
Expand Down Expand Up @@ -584,9 +578,8 @@ <h3>
{% include 'confirmation_modal.html' with modal_id='createExamEvaluation' title=title question=question action_text=action_text btn_type='danger' %}
<script type="text/javascript">
function createExamEvaluationAction(dataId) {
alert(dataId);
fetch("{% url 'staff:create_exam_evaluation' %}", {
body: new URLSearchParams({course_id: dataId}),
body: new URLSearchParams({evaluation_id: dataId}),
headers: CSRF_HEADERS,
method: "POST",
}).then(response => {
Expand Down
7 changes: 6 additions & 1 deletion evap/staff/templates/staff_semester_view_evaluation.html
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,14 @@
<td class="icon-buttons">
{% if not info_only %}
{% if not evaluation.is_single_result and request.user.is_manager %}
<a href="{% url 'staff:evaluation_copy' evaluation.id %}" class="btn btn-sm btn-light" data-bs-toggle="tooltip" title="{% trans "Copy" %}">
<a href="{% url 'staff:evaluation_copy' evaluation.id %}" class="btn btn-sm btn-dark" data-bs-toggle="tooltip" title="{% trans "Copy" %}">
<span class="fas fa-copy"></span>
</a>
<a class="btn btn-sm btn-dark" data-bs-toggle="tooltip"
onclick="createExamEvaluationShow({{ evaluation.id }}, '{{ course.name|escapejs }}');"
title="{% trans 'Create exam evaluation' %}">
<span class="fas fa-file-pen fa-fw"></span>
</a>
{% endif %}
{% if request.user.is_manager %}
<a href="{% url 'staff:evaluation_email' evaluation.id %}" class="btn btn-sm btn-light" data-bs-toggle="tooltip" data-bs-placement="top" title="{% trans 'Send email' %}">
Expand Down
35 changes: 12 additions & 23 deletions evap/staff/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from collections import OrderedDict, defaultdict, namedtuple
from collections.abc import Container
from dataclasses import dataclass
from datetime import date, datetime, timedelta
from datetime import date, datetime, timedelta
from typing import Any, cast

import openpyxl
Expand Down Expand Up @@ -1039,47 +1039,36 @@ def course_copy(request, course_id):
},
)


@require_POST
@manager_required
def create_exam_evaluation(request):
print(request.POST)
evaluation = get_object_from_dict_pk_entry_or_logged_40x(Evaluation, request.POST, "course_id")
date = datetime.date(2023, 10, 30) #request.POST.get("date")
#TODO:
# The weight of the evaluation at which the button was pressed (original evaluation) will be set to 9. If the evaluation has already been published, an error message is displayed (and nothing happens).
evaluation = get_object_from_dict_pk_entry_or_logged_40x(Evaluation, request.POST, "evaluation_id")
exam_date = datetime.today() # request.POST.get("date")

Check warning on line 1047 in evap/staff/views.py

View check run for this annotation

Codecov / codecov/patch

evap/staff/views.py#L1046-L1047

Added lines #L1046 - L1047 were not covered by tests
if evaluation.is_single_result:
raise SuspiciousOperation("Creating an exam evaluation for a single result evaluation is not allowed")
evaluation.weight = 9

Check warning on line 1050 in evap/staff/views.py

View check run for this annotation

Codecov / codecov/patch

evap/staff/views.py#L1049-L1050

Added lines #L1049 - L1050 were not covered by tests

# If the original evaluation has not yet ended, the evaluation period end date will be set to the day before the one selected in the modal. If this date is before the start date, an error message is displayed (and nothing happens).
course_evaluation_end_date = date - timedelta(days=1)
course_evaluation_end_date = exam_date - timedelta(days=1)

Check warning on line 1052 in evap/staff/views.py

View check run for this annotation

Codecov / codecov/patch

evap/staff/views.py#L1052

Added line #L1052 was not covered by tests
if evaluation.vote_start_datetime > course_evaluation_end_date:
raise SuspiciousOperation("The selected date is before the start date")
evaluation.vote_end_date = course_evaluation_end_date

Check warning on line 1055 in evap/staff/views.py

View check run for this annotation

Codecov / codecov/patch

evap/staff/views.py#L1054-L1055

Added lines #L1054 - L1055 were not covered by tests

# A new evaluation will be created for the same course as the original evaluation (exam evaluation), will be named "Klausur/Exam", have a weight of 1, and be unrewarded.
exam_evaluation = Evaluation(course=evaluation.course, name="Klausur/Exam", weight=1, is_rewarded=False)
# The start datetime of the exam evaluation is 08:00 on the day after the exam date defined in the modal.
exam_evaluation.vote_start_datetime = date + timedelta(days=1)
# The end date of the exam evaluation is the third day after the exam date defined in the modal.
exam_evaluation.vote_end_date = date + timedelta(days=3)
# All participants from the original evaluation will be copied to the exam evaluation.
exam_evaluation = Evaluation(

Check warning on line 1057 in evap/staff/views.py

View check run for this annotation

Codecov / codecov/patch

evap/staff/views.py#L1057

Added line #L1057 was not covered by tests
course=evaluation.course, name_de="Klausur", name_en="Exam", weight=1, is_rewarded=False
)
exam_evaluation.vote_start_datetime = exam_date + timedelta(days=1)
exam_evaluation.vote_end_date = exam_date + timedelta(days=3)
exam_evaluation.save()
exam_evaluation.participants.set(evaluation.participants.all())

Check warning on line 1063 in evap/staff/views.py

View check run for this annotation

Codecov / codecov/patch

evap/staff/views.py#L1060-L1063

Added lines #L1060 - L1063 were not covered by tests
# All contributors from the original evaluation will be copied to the exam evaluation without any assigned questionnaires.
for contribution in evaluation.contributions.all():
for contribution in evaluation.contributions.all().filter(contributor__isnull=False):
exam_evaluation.contributions.create(contributor=contribution.contributor)
# All questionnaires listed in a new settings variable EXAM_QUESTIONNAIRES (initially set to contain the id of the "Miscellaneous" questionnaire) will be added to the exam evaluation as general questionnaires.
exam_evaluation.general_contribution.questionnaires.set([Questionnaire.objects.get(id=1)])

Check warning on line 1066 in evap/staff/views.py

View check run for this annotation

Codecov / codecov/patch

evap/staff/views.py#L1065-L1066

Added lines #L1065 - L1066 were not covered by tests

exam_evaluation.save()
evaluation.save()
return HttpResponse() # 200 OK

Check warning on line 1069 in evap/staff/views.py

View check run for this annotation

Codecov / codecov/patch

evap/staff/views.py#L1068-L1069

Added lines #L1068 - L1069 were not covered by tests






@manager_required
class CourseEditView(SuccessMessageMixin, UpdateView):
model = Course
Expand Down

0 comments on commit b5211af

Please sign in to comment.