Close Quiz function
This commit is contained in:
parent
fe5cf189cc
commit
46cef8cd1e
@ -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();
|
||||||
|
@ -167,11 +167,15 @@
|
|||||||
{% include "admin/components/client-alerts.html" %}
|
{% include "admin/components/client-alerts.html" %}
|
||||||
</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-danger test-action" data-action="delete" data-_id="{{ test._id }}">
|
<a href="#" class="btn btn-warning test-action" data-action="close" data-_id="{{ test._id }}">
|
||||||
<i class="bi bi-file-earmark-excel-fill button-icon"></i>
|
<i class="bi bi-hourglass button-icon"></i>
|
||||||
Delete Exam
|
Close Exam
|
||||||
</a>
|
</a>
|
||||||
|
<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>
|
||||||
|
Delete Exam
|
||||||
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user