Close Quiz function

This commit is contained in:
Vivek Santayana 2021-12-06 23:16:33 +00:00
parent 792053e886
commit a8d7d35c12
3 changed files with 33 additions and 6 deletions

View File

@ -88,6 +88,19 @@ $('.test-action').click(function(event) {
}); });
} else if (action == 'edit') { } else if (action == 'edit') {
window.location.href = `/admin/test/${_id}/` window.location.href = `/admin/test/${_id}/`
} else if (action == 'close'){
$.ajax({
url: `/admin/tests/close/`,
type: 'POST',
data: JSON.stringify({'_id': _id}),
contentType: 'application/json',
success: function(response) {
window.location.reload();
},
error: function(response){
error_response(response);
},
});
} }
event.preventDefault(); event.preventDefault();

View File

@ -168,6 +168,10 @@
</div> </div>
<div class="container justify-content-center"> <div class="container justify-content-center">
<div class="row"> <div class="row">
<a href="#" class="btn btn-warning test-action" data-action="close" data-_id="{{ test._id }}">
<i class="bi bi-hourglass button-icon"></i>
Close Exam
</a>
<a href="#" class="btn btn-danger test-action" data-action="delete" data-_id="{{ test._id }}"> <a href="#" class="btn btn-danger test-action" data-action="delete" data-_id="{{ test._id }}">
<i class="bi bi-file-earmark-excel-fill button-icon"></i> <i class="bi bi-file-earmark-excel-fill button-icon"></i>
Delete Exam Delete Exam

View File

@ -1,7 +1,7 @@
from flask import Blueprint, render_template, flash, redirect, request, jsonify, abort, session from flask import Blueprint, render_template, flash, redirect, request, jsonify, abort, session
from flask.helpers import url_for from flask.helpers import url_for
from functools import wraps from functools import wraps
from datetime import datetime from datetime import datetime, timedelta
import os import os
from glob import glob from glob import glob
@ -415,6 +415,16 @@ def delete_test():
return Test(_id = _id).delete() return Test(_id = _id).delete()
return jsonify({'error': 'Could not find the corresponding test to delete.'}), 404 return jsonify({'error': 'Could not find the corresponding test to delete.'}), 404
@views.route('/tests/close/', methods=['POST'])
@admin_account_required
@login_required
def delete_test():
from main import db
_id = request.get_json()['_id']
if db.tests.find_one_and_update({'_id': _id}, {'$set': {'expiry_date': datetime.today() - timedelta(days=1) }}):
return Test(_id = _id).delete()
return jsonify({'error': 'Could not find the corresponding test to delete.'}), 404
@views.route('/test/<_id>/', methods=['GET','POST']) @views.route('/test/<_id>/', methods=['GET','POST'])
@admin_account_required @admin_account_required
@login_required @login_required