Commit 07f070c4 by Afzal Wali Committed by Muhammad Shoaib

Remove exam attempt.

parent 494806f0
...@@ -306,6 +306,22 @@ def stop_exam_attempt(exam_id, user_id): ...@@ -306,6 +306,22 @@ def stop_exam_attempt(exam_id, user_id):
exam_attempt_obj.save() exam_attempt_obj.save()
return exam_attempt_obj.id return exam_attempt_obj.id
def remove_exam_attempt_by_code(attempt_code):
"""
Removes an exam attempt given the attempt code.
"""
existing_attempt = ProctoredExamStudentAttempt.get_exam_attempt_by_code(attempt_code)
if not existing_attempt:
err_msg = (
'Cannot remove attempt for attempt_code = {attempt_code} '
'because it does not exist!'
).format(attempt_code=attempt_code)
raise StudentExamAttemptDoesNotExistsException(err_msg)
existing_attempt.delete_exam_attempt()
def get_all_exams_for_course(course_id): def get_all_exams_for_course(course_id):
""" """
......
...@@ -202,6 +202,11 @@ class ProctoredExamStudentAttempt(TimeStampedModel): ...@@ -202,6 +202,11 @@ class ProctoredExamStudentAttempt(TimeStampedModel):
return cls.objects.filter(filtered_query) return cls.objects.filter(filtered_query)
def delete_exam_attempt(self):
"""
deletes the exam attempt object.
"""
self.delete()
class QuerySetWithUpdateOverride(models.query.QuerySet): class QuerySetWithUpdateOverride(models.query.QuerySet):
""" """
......
...@@ -8,7 +8,7 @@ var edx = edx || {}; ...@@ -8,7 +8,7 @@ var edx = edx || {};
edx.instructor_dashboard.proctoring = edx.instructor_dashboard.proctoring || {}; edx.instructor_dashboard.proctoring = edx.instructor_dashboard.proctoring || {};
edx.instructor_dashboard.proctoring.ProctoredExamAttemptModel = Backbone.Model.extend({ edx.instructor_dashboard.proctoring.ProctoredExamAttemptModel = Backbone.Model.extend({
url: '/api/edx_proctoring/v1/proctored_exam/allowance' url: '/api/edx_proctoring/v1/proctored_exam/attempt/'
}); });
this.edx.instructor_dashboard.proctoring.ProctoredExamAttemptModel = edx.instructor_dashboard.proctoring.ProctoredExamAttemptModel; this.edx.instructor_dashboard.proctoring.ProctoredExamAttemptModel = edx.instructor_dashboard.proctoring.ProctoredExamAttemptModel;
......
...@@ -8,6 +8,7 @@ $(function() { ...@@ -8,6 +8,7 @@ $(function() {
var proctored_exam_attempt_view = new edx.instructor_dashboard.proctoring.ProctoredExamAttemptView({ var proctored_exam_attempt_view = new edx.instructor_dashboard.proctoring.ProctoredExamAttemptView({
el: $('.student-proctored-exam-container'), el: $('.student-proctored-exam-container'),
template_url: '/static/proctoring/templates/student-proctored-exam-attempts.underscore', template_url: '/static/proctoring/templates/student-proctored-exam-attempts.underscore',
collection: new edx.instructor_dashboard.proctoring.ProctoredExamAttemptCollection() collection: new edx.instructor_dashboard.proctoring.ProctoredExamAttemptCollection(),
model: new edx.instructor_dashboard.proctoring.ProctoredExamAttemptModel()
}); });
}); });
...@@ -11,10 +11,12 @@ var edx = edx || {}; ...@@ -11,10 +11,12 @@ var edx = edx || {};
this.$el = options.el; this.$el = options.el;
this.collection = options.collection; this.collection = options.collection;
this.tempate_url = options.template_url; this.tempate_url = options.template_url;
this.model = options.model;
this.course_id = this.$el.data('course-id'); this.course_id = this.$el.data('course-id');
this.template = null; this.template = null;
this.initial_url = this.collection.url; this.initial_url = this.collection.url;
this.attempt_url = this.model.url;
this.collection.url = this.initial_url + this.course_id; this.collection.url = this.initial_url + this.course_id;
/* re-render if the model changes */ /* re-render if the model changes */
...@@ -24,7 +26,7 @@ var edx = edx || {}; ...@@ -24,7 +26,7 @@ var edx = edx || {};
this.loadTemplateData(); this.loadTemplateData();
}, },
events: { events: {
"click .remove-attempt": "onRemoveAttempt"
}, },
getCSRFToken: function () { getCSRFToken: function () {
var cookieValue = null; var cookieValue = null;
...@@ -75,6 +77,24 @@ var edx = edx || {}; ...@@ -75,6 +77,24 @@ var edx = edx || {};
this.$el.html(html); this.$el.html(html);
this.$el.show(); this.$el.show();
} }
},
onRemoveAttempt: function (event) {
event.preventDefault();
var $target = $(event.currentTarget);
var attemptId = $target.data("attemptId");
var self = this;
self.model.url = this.attempt_url + attemptId;
self.model.fetch( {
headers: {
"X-CSRFToken": this.getCSRFToken()
},
type: 'DELETE',
success: function () {
// fetch the attempts again.
self.hydrate();
}
});
} }
}); });
this.edx.instructor_dashboard.proctoring.ProctoredExamAttemptView = edx.instructor_dashboard.proctoring.ProctoredExamAttemptView; this.edx.instructor_dashboard.proctoring.ProctoredExamAttemptView = edx.instructor_dashboard.proctoring.ProctoredExamAttemptView;
......
...@@ -43,10 +43,7 @@ ...@@ -43,10 +43,7 @@
N/A N/A
<% } %> <% } %>
<td> <td>
<% if (proctored_exam_attempt.status){ %> <button type="button" class="remove-attempt blue-button" data-attempt-id="<%= proctored_exam_attempt.id %>" ><%- gettext("Remove") %></button>
<% } else { %>
N/A
<% } %>
</td> </td>
</tr> </tr>
<% }); %> <% }); %>
......
...@@ -311,6 +311,36 @@ class StudentProctoredExamAttempt(AuthenticatedAPIView): ...@@ -311,6 +311,36 @@ class StudentProctoredExamAttempt(AuthenticatedAPIView):
data={"detail": str(ex)} data={"detail": str(ex)}
) )
@method_decorator(require_staff)
def delete(self, request, attempt_id):
"""
HTTP DELETE handler. Removes an exam attempt.
"""
try:
attempt = get_exam_attempt_by_id(attempt_id)
if not attempt:
err_msg = (
'Attempted to access attempt_id {attempt_id} but '
'it does not exist.'.format(
attempt_id=attempt_id
)
)
raise StudentExamAttemptDoesNotExistsException(err_msg)
exam_attempt_id = stop_exam_attempt(
exam_id=attempt['proctored_exam']['id'],
user_id=request.user.id
)
return Response({"exam_attempt_id": exam_attempt_id})
except ProctoredBaseException, ex:
return Response(
status=status.HTTP_400_BAD_REQUEST,
data={"detail": str(ex)}
)
class StudentProctoredExamAttemptCollection(AuthenticatedAPIView): class StudentProctoredExamAttemptCollection(AuthenticatedAPIView):
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment