Completed client side time adjustment handling
Corrected error display bug Removed redundant auth and models in quiz client app
This commit is contained in:
@ -1,6 +0,0 @@
|
||||
from flask import Blueprint
|
||||
|
||||
auth = Blueprint(
|
||||
'quiz_auth',
|
||||
__name__,
|
||||
)
|
@ -163,6 +163,18 @@ $("#btn-start-quiz").click(function(event){
|
||||
time_remaining = get_time_remaining();
|
||||
clock = setInterval(timer, 1000);
|
||||
}
|
||||
if (response.time_adjustment > 0) {
|
||||
const $alert = $("#alert-box");
|
||||
$alert.html(
|
||||
`<div class="alert alert-primary alert-dismissible fade show" role="alert">
|
||||
<i class="bi bi-exclamation-triangle-fill" title="Alert"></i>
|
||||
User code validated. Extra time of ${response.time_adjustment} minutes added to the exam time limit.
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
`
|
||||
);
|
||||
$alert.focus();
|
||||
}
|
||||
},
|
||||
error: function(response) {
|
||||
error_response(response);
|
||||
@ -507,7 +519,7 @@ function timer() {
|
||||
if (time_remaining > 0) {
|
||||
var timer_display = '';
|
||||
if (hours > 0) {
|
||||
timer_display = `${hours.toString()}: `;
|
||||
timer_display = `${hours.toString()}:`;
|
||||
}
|
||||
if (minutes > 0 || hours > 0) {
|
||||
if (minutes < 10) {
|
||||
|
@ -37,11 +37,11 @@ $('form[name=form-quiz-start]').submit(function(event) {
|
||||
|
||||
function error_response(response) {
|
||||
|
||||
var alert = $("#alert-box");
|
||||
alert.html('');
|
||||
const $alert = $("#alert-box");
|
||||
$alert.html('');
|
||||
|
||||
if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) {
|
||||
alert.html(`
|
||||
$alert.html(`
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
<i class="bi bi-exclamation-triangle-fill" title="Danger"></i>
|
||||
${response.responseJSON.error}
|
||||
@ -49,14 +49,16 @@ function error_response(response) {
|
||||
</div>
|
||||
`);
|
||||
} else if (response.responseJSON.error instanceof Array) {
|
||||
var output = ''
|
||||
for (var i = 0; i < response.responseJSON.error.length; i ++) {
|
||||
alert.html(`
|
||||
output += `
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
<i class="bi bi-exclamation-triangle-fill" title="Danger"></i>
|
||||
${response.responseJSON.error[i]}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
`);
|
||||
`;
|
||||
$alert.html(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div id="alert-box" tabindex="-1"></div>
|
||||
<div class="container quiz-panel" id="quiz-settings" tabindex="-1">
|
||||
<h1>Adjust Display Settings</h1>
|
||||
<div class="container quiz-start-text">
|
||||
@ -255,7 +256,6 @@
|
||||
<a href="#" class="btn btn-success quiz-button-submit" title="Submit Exam">Submit Exam</a>
|
||||
</div>
|
||||
</div>
|
||||
<div id="alert-box"></div>
|
||||
{% endblock %}
|
||||
{% block script %}
|
||||
<script
|
||||
|
@ -36,7 +36,7 @@
|
||||
<div class="col text-center">
|
||||
<button class="btn btn-md btn-success btn-block" type="submit">
|
||||
<i class="bi bi-pencil-fill button-icon"></i>
|
||||
Start Exam
|
||||
Get Ready
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -55,10 +55,12 @@ def start():
|
||||
club = request.form.get('club')
|
||||
test_code = request.form.get('test_code').replace('—', '')
|
||||
user_code = request.form.get('user_code')
|
||||
user_code = None if user_code == '' else user_code
|
||||
user_code = None if user_code == '' else user_code.upper()
|
||||
test = db.tests.find_one({'test_code': test_code})
|
||||
if not test:
|
||||
return jsonify({'error': 'The exam code you entered is invalid.'}), 400
|
||||
if user_code and user_code not in test['time_adjustments']:
|
||||
return jsonify({'error': f'The user code you entered is not valid.'}), 400
|
||||
if test['expiry_date'] + timedelta(days=1) < datetime.utcnow():
|
||||
return jsonify({'error': f'The exam code you entered expired on {test["expiry_date"].strftime("%d %b %Y")} UTC.'}), 400
|
||||
if test['start_date'] > datetime.utcnow():
|
||||
@ -88,12 +90,16 @@ def fetch_questions():
|
||||
if not entry:
|
||||
return jsonify({'error': 'The data that the client sent to the server is invalid. This is possibly because you have already submitted your exam and have tried to access the page again.'}), 400
|
||||
test_code = entry['test_code']
|
||||
# user_code = entry['user_code'] TODO Implement functionality for adjustments
|
||||
|
||||
user_code = entry['user_code']
|
||||
test = db.tests.find_one({'test_code' : test_code})
|
||||
time_limit = test['time_limit']
|
||||
time_adjustment = 0
|
||||
if time_limit:
|
||||
_time_limit = int(time_limit)
|
||||
if user_code:
|
||||
time_adjustment = test['time_adjustments'][user_code]
|
||||
_time_limit += time_adjustment
|
||||
adjustment = True
|
||||
end_delta = timedelta(minutes=_time_limit)
|
||||
end_time = datetime.utcnow() + end_delta
|
||||
else:
|
||||
@ -113,14 +119,14 @@ def fetch_questions():
|
||||
return jsonify({
|
||||
'time_limit': end_time,
|
||||
'questions': questions,
|
||||
'start_time': entry['start_time']
|
||||
'start_time': entry['start_time'],
|
||||
'time_adjustment': time_adjustment
|
||||
})
|
||||
|
||||
@views.route('/test/')
|
||||
def start_quiz():
|
||||
_id = session.get('_id')
|
||||
if not _id or not db.entries.find_one({'_id': _id}):
|
||||
print('Foo')
|
||||
flash('Your log in was not recognised. Please sign in to the quiz again.', 'error')
|
||||
return redirect(url_for('quiz_views.start'))
|
||||
return render_template('quiz/client.html')
|
||||
|
Reference in New Issue
Block a user