This commit is contained in:
Ross
2024-11-04 14:09:33 +00:00
parent d8b07449a4
commit eab6fc9d7e
8 changed files with 35 additions and 10 deletions
+4 -2
View File
@@ -34,7 +34,7 @@ APP_NAME = "anatomy"
def create_exam(db):
exam: Exam = AnatomyExamViews.Exam.objects.create(
name="Cid Exam", exam_mode=True, active=True
name="Cid Exam", exam_mode=True, active=True, open_access=False, exam_open_access=False
)
group1: CidUserGroup = CidUserGroup.objects.get(name="Group1")
@@ -194,6 +194,8 @@ def test_exams(db, client):
exam.save()
res = client.get(exam_metadata["url"])
print("PRE ERRER", exam_metadata["url"])
print(res.content)
assert res.status_code == 404
exam.active = True
@@ -365,7 +367,7 @@ def test_exams(db, client):
cid_exam_scores_soup = BeautifulSoup(cid_exam_scores_res.content, "html.parser")
# Check that we have an alert that exams are not published
alert = cid_exam_scores_soup.find("div", {"class": "alert"})
alert = cid_exam_scores_soup.find("div", {"class": "no-results"})
assert "Results are not currently published." in str(alert)
answer_lis = cid_exam_scores_soup.find(
+2 -1
View File
@@ -702,7 +702,7 @@ class ExamOrCollectionGenericBase(models.Model, AuthorMixin):
allow_authors: bool = True,
):
"""Checks if a user (cid or otherwise) is allowed to access (and take) the exam"""
print(f"Check cid user: {cid=}, {passcode=}, exam_id={self.pk}")
print(f"Check cid user: {cid=}, {passcode=}, exam_id={self.pk}, {user=}, {user_id=}, {allow_authors=}")
if user is not None and user.is_superuser:
return True
@@ -724,6 +724,7 @@ class ExamOrCollectionGenericBase(models.Model, AuthorMixin):
return False
# Start by checking if the logged in user can access
if user_id is not None:
if self.valid_user_users.filter(pk=user_id).exists():
@@ -28,6 +28,11 @@
{% endif %}
{% endif %}
{% if exam.archive %}
<div class="alert alert-info" role="alert">
This exam is archived. Results and submitted answers will not be available to candidates. They can still be viewed by supervisors.
</div>
{% endif %}
This exam has {{question_number}} questions.
<span title="Time per question: {% widthratio exam.time_limit question_number 1 %} seconds">Time limit: {{exam.time_limit}} seconds [{{exam.get_time_limit}}]
@@ -101,7 +106,7 @@ Open access: {{ exam.open_access }}<br />
id="exam-publish-results-switch" data-posturl="{% url exam.get_app_name|add:':exam_toggle_results_published' pk=exam.pk %}"
{% if exam.publish_results %}checked{% endif %}> <span class="help-text">[When checked the exam results will be available to users on this site]</span>
</div>
{% if exam.get_app_name == "anatomy" or exam.get_app_name == "rapids" or exam.get_app_name == "longs" %}
{% if exam.get_app_name == "anatomy" or exam.get_app_name == "longs" %}
<p><a href="{% url exam.get_app_name|add:':mark_overview' pk=exam.pk %}"><button>Mark exam</button></a></p>
{% endif %}
{% endif %}
+7 -2
View File
@@ -184,6 +184,7 @@ def get_user_exams(user, supervisor_view=False):
if supervisor_view:
kwargs["results_supervisor_visible"] = True
del kwargs["archive"]
exams = []
for exam_type in EXAM_ANSWER_MAP:
@@ -527,7 +528,7 @@ class ExamViews(View, LoginRequiredMixin):
if (exam.open_access and exam.active) or user in exam.get_author_objects():
return True
if exam.cid_user_exam.filter(user_user=user):
if user.is_authenticated and exam.active and exam.cid_user_exam.filter(user_user=user):
return True
if marker and user in exam.markers.all():
@@ -1914,10 +1915,12 @@ class ExamViews(View, LoginRequiredMixin):
user_id = None
else:
user_id = request.user.pk
print(0)
if exam.exam_mode and not exam.check_cid_user(
cid, passcode, request.user, user_id
):
raise Http404("No available exam")
print(1)
# exam_json_cache = cache.get("{}_exam_json_{}".format(self.app_name, pk))
@@ -2116,10 +2119,10 @@ class ExamViews(View, LoginRequiredMixin):
# check for supervisor access
raise Http404("Error accessing exam")
view_all_results = True
else:
if user is None:
raise Exception("user must be defined")
view_all_results = True
if user is not None:
request.user = user
@@ -3853,6 +3856,8 @@ def supervisor_trainee(request, pk, trainee_id):
exams = get_user_exams(trainee, supervisor_view=True)
print(exams)
print(trainee)
return render(
@@ -10,6 +10,7 @@
<div class="rapids">
{% if exam.exam_mode %}
<a href="{% url exam.get_app_name|add:':mark_overview' pk=exam.pk %}"><button>Mark exam</button></a>
<a href="{% url 'rapids:mark_review' exam_pk=exam.pk sk=0 %}"><button>Review exam</button></a></p>
{% endif %}
+13 -2
View File
@@ -20,16 +20,16 @@
<ul class="score-answer-list">
{% for ans, score, correct_answer in answers_and_marks %}
<li class="user-answer-li" data-question-number="{{forloop.counter}}">Question {{forloop.counter}} - Correct answer: {% if exam.publish_results %}<span class="correct-answer">{{correct_answer}}</span>{% endif %}
<span class="view-question-link" data-qn={{forloop.counter0}}>View</span>
<br/>
<span class="user-answer-score user-answer-score-{{score}}">
<span class="submitted-user-answer">
<pre>{{ans}}</pre>
</span>
{% if exam.publish_results or view_all_results%}
<span class="answer-score">{{score}}</span>
<span class="answer-score">Score: {{score}}</span>
{% endif %}
</span>
<span class="view-question-link" data-qn={{forloop.counter0}}>View</span>
</li>
{% endfor %}
</ul>
@@ -90,3 +90,14 @@
});
</script>
{% endblock %}
{% block css %}
<style>
.answer-score {
float: right;
}
</style>
{% endblock css %}
+1 -1
View File
@@ -306,7 +306,7 @@ def test_supervisor_management(db, faker, client, create_cid_manager, django_use
assert response.status_code == 200
soup = BeautifulSoup(response.content, "html.parser")
assert len(soup.find(id="supervisor-list").find_all("li")) == 2
assert len(soup.find(id="tbody").find_all("tr")) == 2
response = client.get(reverse(f"generic:supervisor_detail", kwargs={"pk": s1.pk}))
soup = BeautifulSoup(response.content, "html.parser")
+1 -1
View File
@@ -22,7 +22,7 @@
</div>
{% else %}
{% if not exam.publish_results %}
<div class="alert alert-info" role="alert">Results are not currently published. You can see your own answers below.</a></div>
<div class="alert alert-info no-results" role="alert">Results are not currently published. You can see your own answers below.</a></div>
{% endif %}
{% endif %}