Commit 4936f7a7 by Afzal Wali Committed by Muhammad Shoaib

returned formatted time allowed and the datetimes

parent be0b4208
......@@ -2,6 +2,9 @@
from rest_framework import serializers
from django.contrib.auth.models import User
from edx_proctoring.models import ProctoredExam, ProctoredExamStudentAttempt, ProctoredExamStudentAllowance
from edx_proctoring.utils import humanized_time
DATETIME_FORMAT = "%b %d, %Y %I:%M %p" # "MMMM dd, yyyy HH:MM"
class StrictBooleanField(serializers.BooleanField):
......@@ -68,6 +71,18 @@ class ProctoredExamStudentAttemptSerializer(serializers.ModelSerializer):
"""
proctored_exam = ProctoredExamSerializer()
user = UserSerializer()
allowed_time_limit_mins = serializers.SerializerMethodField(method_name="get_allowed_time_limit_mins")
started_at = serializers.SerializerMethodField(method_name="get_started_at")
completed_at = serializers.SerializerMethodField(method_name="get_completed_at")
def get_allowed_time_limit_mins(self, obj):
return humanized_time(obj.allowed_time_limit_mins)
def get_started_at(self, obj):
return obj.started_at.strftime(DATETIME_FORMAT) if obj.started_at else "N/A"
def get_completed_at(self, obj):
return obj.completed_at.strftime(DATETIME_FORMAT) if obj.completed_at else "N/A"
class Meta:
"""
......
......@@ -102,66 +102,11 @@ var edx = edx || {};
collectionChanged: function () {
this.hydrate();
},
humanized_time: function(time_in_minutes) {
var hours = parseInt(time_in_minutes / 60);
var minutes = time_in_minutes % 60;
var hours_present = false;
if (hours == 0) {
hours_present = false;
var template = ""
}
else if (hours == 1) {
template = hours + " Hour ";
hours_present = true;
}
else if (hours >= 2) {
console.log(hours);
template = hours + " Hours ";
hours_present = true
}
else {
template = "error";
}
if (template !== "error") {
if (minutes == 0) {
if (!hours_present) {
template = minutes + " Minutes";
}
}
else if ( minutes == 1 ) {
if (hours_present) {
template = template + " and " +minutes + " Minute";
}
else {
template = template + minutes + " Minute";
}
}
else {
if (hours_present) {
template = template + " and " + minutes + " Minutes";
}
else {
template = template + minutes + " Minutes";
}
}
}
return template;
},
render: function () {
if (this.template !== null) {
var attempts = this.collection.toJSON()[0].proctored_exam_attempts;
var proctored_attempts = [];
var self = this;
$.each( attempts, function( index, attempt ){
attempt.allowed_time_limit_mins = self.humanized_time(attempt.allowed_time_limit_mins);
proctored_attempts.push(attempt);
});
var html = this.template({
proctored_exam_attempts: proctored_attempts,
proctored_exam_attempts: this.collection.toJSON()[0].proctored_exam_attempts,
pagination_info: this.collection.toJSON()[0].pagination_info,
attempt_url: this.collection.toJSON()[0].attempt_url,
inSearchMode: this.inSearchMode,
......
......@@ -81,7 +81,7 @@
<th class="username"><%- gettext("Username") %></th>
<th class="exam-name"><%- gettext("Exam Name") %></th>
<th class="attempt-allowed-time"><%- gettext("Allowed Time for Student") %> </th>
<th class="attempt-started-at"><%- gettext("started At") %></th>
<th class="attempt-started-at"><%- gettext("Started At") %></th>
<th class="attempt-completed-at"><%- gettext("Completed At") %> </th>
<th class="attempt-status"><%- gettext("Status") %> </th>
<th class="c_action"><%- gettext("Action") %> </th>
......@@ -97,20 +97,8 @@
<%- interpolate(gettext(' %(exam_display_name)s '), { exam_display_name: proctored_exam_attempt.proctored_exam.exam_name }, true) %>
</td>
<td> <%= proctored_exam_attempt.allowed_time_limit_mins %></td>
<td>
<% if (proctored_exam_attempt.started_at){ %>
<%= new Date(proctored_exam_attempt.started_at).toString("MMMM dd, yyyy HH:MM") %>
<% } else { %>
N/A
<% } %>
</td>
<td>
<% if (proctored_exam_attempt.completed_at){ %>
<%= new Date(proctored_exam_attempt.completed_at).toString("MMMM dd, yyyy HH:MM") %>
<% } else { %>
N/A
<% } %>
<td>
<td> <%= proctored_exam_attempt.started_at %></td>
<td> <%= proctored_exam_attempt.completed_at %></td>
<% if (proctored_exam_attempt.status){ %>
<%= proctored_exam_attempt.status %> </td>
<% } else { %>
......
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