Commit c7bb88a1 by Muhammad Shoaib

added the collection for the allowances data.

parent 1712b42b
...@@ -135,6 +135,14 @@ def add_allowance_for_user(exam_id, user_id, key, value): ...@@ -135,6 +135,14 @@ def add_allowance_for_user(exam_id, user_id, key, value):
ProctoredExamStudentAllowance.add_allowance_for_user(exam_id, user_id, key, value) ProctoredExamStudentAllowance.add_allowance_for_user(exam_id, user_id, key, value)
def get_allowances_for_course(course_id):
"""
Get all the allowances for the course.
"""
student_allowances = ProctoredExamStudentAllowance.get_allowances_for_course(course_id)
return [ProctoredExamStudentAllowanceSerializer(allowance).data for allowance in student_allowances]
def remove_allowance_for_user(exam_id, user_id, key): def remove_allowance_for_user(exam_id, user_id, key):
""" """
Deletes an allowance for a user within a given exam. Deletes an allowance for a user within a given exam.
......
...@@ -201,6 +201,13 @@ class ProctoredExamStudentAllowance(TimeStampedModel): ...@@ -201,6 +201,13 @@ class ProctoredExamStudentAllowance(TimeStampedModel):
verbose_name = 'proctored allowance' verbose_name = 'proctored allowance'
@classmethod @classmethod
def get_allowances_for_course(cls, course_id):
"""
Returns all the allowances for a course.
"""
return cls.objects.filter(proctored_exam__course_id=course_id)
@classmethod
def get_allowance_for_user(cls, exam_id, user_id, key): def get_allowance_for_user(cls, exam_id, user_id, key):
""" """
Returns an allowance for a user within a given exam Returns an allowance for a user within a given exam
......
...@@ -6,9 +6,11 @@ $(function() { ...@@ -6,9 +6,11 @@ $(function() {
}); });
proctored_exam_view.render(); proctored_exam_view.render();
var container = $(".special-allowance-container");
var course_id = container.data('course-id');
var proctored_exam_allowance_view = new edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView({ var proctored_exam_allowance_view = new edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView({
el: $(".special-allowance-container"), el: container,
allowance_template_url: '/static/proctoring/templates/add-allowance.underscore', allowance_template_url: '/static/proctoring/templates/add-allowance.underscore',
model: new ProctoredExamAllowanceModel() course_id: course_id
}); });
}); });
var edx = edx || {};
(function(Backbone) {
edx.instructor_dashboard = edx.instructor_dashboard || {};
edx.instructor_dashboard.proctoring = edx.instructor_dashboard.proctoring || {};
edx.instructor_dashboard.proctoring.ProctoredExamAllowanceCollection = Backbone.Collection.extend({
/* model for a collection of ProctoredExamAllowance */
model: edx.instructor_dashboard.proctoring.ProctoredExamAllowanceModel,
url: '/api/edx_proctoring/v1/proctored_exam/allowance'
});
this.edx.instructor_dashboard.proctoring.ProctoredExamAllowanceCollection = edx.instructor_dashboard.proctoring.ProctoredExamAllowanceCollection;
}).call(this, Backbone);
\ No newline at end of file
var edx = edx || {};
(function(Backbone) { (function(Backbone) {
var ProctoredExamAllowanceModel = Backbone.Model.extend({
'use strict';
edx.instructor_dashboard = edx.instructor_dashboard || {};
edx.instructor_dashboard.proctoring = edx.instructor_dashboard.proctoring || {};
edx.instructor_dashboard.proctoring.ProctoredExamAllowanceModel = Backbone.Model.extend({
/* we should probably pull this from a data attribute on the HTML */ /* we should probably pull this from a data attribute on the HTML */
url: '/api/edx_proctoring/v1/proctored_exam/allowance', url: '/api/edx_proctoring/v1/proctored_exam/allowance',
...@@ -7,6 +15,5 @@ ...@@ -7,6 +15,5 @@
} }
}); });
this.edx.instructor_dashboard.proctoring.ProctoredExamAllowanceModel = edx.instructor_dashboard.proctoring.ProctoredExamAllowanceModel;
this.ProctoredExamAllowanceModel = ProctoredExamAllowanceModel;
}).call(this, Backbone); }).call(this, Backbone);
...@@ -4,23 +4,26 @@ var edx = edx || {}; ...@@ -4,23 +4,26 @@ var edx = edx || {};
'use strict'; 'use strict';
edx.instructor_dashboard = edx.instructor_dashboard || {}; edx.instructor_dashboard = edx.instructor_dashboard || {};
edx.instructor_dashboard.proctoring = {}; edx.instructor_dashboard.proctoring = edx.instructor_dashboard.proctoring || {};
edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView = Backbone.View.extend({ edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView = Backbone.View.extend({
initialize: function (options) { initialize: function (options) {
this.$el = options.el; this.$el = options.el;
this.model = options.model; this.collection = new edx.instructor_dashboard.proctoring.ProctoredExamAllowanceCollection();
this.course_id = options.course_id;
this.temPlateUrl = options.allowance_template_url; this.temPlateUrl = options.allowance_template_url;
this.template = null; this.template = null;
/* re-render if the model changes */ /* re-render if the model changes */
this.listenTo(this.model,'change', this.modelChanged); this.listenTo(this.collection, 'change', this.collectionChanged);
/* make the async call to the backend REST API */ /* make the async call to the backend REST API */
/* after it loads, the listenTo event will file and */ /* after it loads, the listenTo event will file and */
/* will call into the rendering */ /* will call into the rendering */
//this.model.fetch();
this.loadTemplateData(); this.loadTemplateData();
this.collection.url = this.collection.url + '/' + this.course_id;
}, },
loadTemplateData: function(){ loadTemplateData: function(){
var self = this; var self = this;
...@@ -30,19 +33,31 @@ var edx = edx || {}; ...@@ -30,19 +33,31 @@ var edx = edx || {};
}) })
.done(function(template_data) { .done(function(template_data) {
self.template = _.template(template_data); self.template = _.template(template_data);
self.render() self.hydrate();
});
},
hydrate: function() {
/* This function will load the bound collection */
/* add and remove a class when we do the initial loading */
/* we might - at some point - add a visual element to the */
/* loading, like a spinner */
var self = this;
this.collection.fetch({
success: function(){
self.render();
}
}); });
}, },
modelChanged: function() { collectionChanged: function() {
//this.render(); this.hydrate();
}, },
render: function () { render: function () {
if (this.template !== null) { if (this.template !== null) {
var html = this.template(); var html = this.template(this.collection.toJSON());
this.$el.html(html); this.$el.html(html);
this.$el.show(); this.$el.show();
} }
return this;
} }
}); });
this.edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView = edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView; this.edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView = edx.instructor_dashboard.proctoring.ProctoredExamAllowanceView;
......
...@@ -30,6 +30,11 @@ urlpatterns = patterns( # pylint: disable=invalid-name ...@@ -30,6 +30,11 @@ urlpatterns = patterns( # pylint: disable=invalid-name
name='edx_proctoring.proctored_exam.attempt' name='edx_proctoring.proctored_exam.attempt'
), ),
url( url(
r'edx_proctoring/v1/proctored_exam/allowance/{}$'.format(settings.COURSE_ID_PATTERN),
views.ExamAllowanceView.as_view(),
name='edx_proctoring.proctored_exam.allowance'
),
url(
r'edx_proctoring/v1/proctored_exam/allowance$', r'edx_proctoring/v1/proctored_exam/allowance$',
views.ExamAllowanceView.as_view(), views.ExamAllowanceView.as_view(),
name='edx_proctoring.proctored_exam.allowance' name='edx_proctoring.proctored_exam.allowance'
......
...@@ -20,8 +20,8 @@ from edx_proctoring.api import ( ...@@ -20,8 +20,8 @@ from edx_proctoring.api import (
add_allowance_for_user, add_allowance_for_user,
remove_allowance_for_user, remove_allowance_for_user,
get_active_exams_for_user, get_active_exams_for_user,
create_exam_attempt create_exam_attempt,
) get_allowances_for_course)
from edx_proctoring.exceptions import ( from edx_proctoring.exceptions import (
ProctoredBaseException, ProctoredBaseException,
ProctoredExamNotFoundException, ProctoredExamNotFoundException,
...@@ -358,6 +358,14 @@ class ExamAllowanceView(AuthenticatedAPIView): ...@@ -358,6 +358,14 @@ class ExamAllowanceView(AuthenticatedAPIView):
**Response Values** **Response Values**
* returns Nothing. deletes the allowance for the user proctored exam. * returns Nothing. deletes the allowance for the user proctored exam.
""" """
def get(self, request, course_id):
"""
HTTP GET handler. Get all allowances for a course.
"""
return Response(get_allowances_for_course(
course_id=course_id
))
@method_decorator(require_staff) @method_decorator(require_staff)
def put(self, request): def put(self, request):
""" """
......
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