diff --git a/ref-test/admin/models/tests.py b/ref-test/admin/models/tests.py index 6605ea8..656c424 100644 --- a/ref-test/admin/models/tests.py +++ b/ref-test/admin/models/tests.py @@ -64,6 +64,10 @@ class Test: return test_code.replace('—', '') def delete(self): + test = db.tests.find_one({'_id': self._id}) + if 'entries' in test: + if test['entries']: + return jsonify({'error': 'Cannot delete an exam that has entries submitted to it.'}), 400 if self.dataset is None: self.dataset = db.tests.find_one({'_id': self._id})['dataset'] if db.tests.delete_one({'_id': self._id}): diff --git a/ref-test/admin/static/css/style.css b/ref-test/admin/static/css/style.css index 6672d33..8107688 100644 --- a/ref-test/admin/static/css/style.css +++ b/ref-test/admin/static/css/style.css @@ -214,6 +214,11 @@ table.dataTable { font-size: 14pt; } +.result-action-buttons { + margin: 5px auto; + width: fit-content; +} + /* Fallback for Edge -------------------------------------------------- */ @supports (-ms-ime-align: auto) { diff --git a/ref-test/admin/static/js/script.js b/ref-test/admin/static/js/script.js index 23cfe3c..d3362b5 100644 --- a/ref-test/admin/static/js/script.js +++ b/ref-test/admin/static/js/script.js @@ -153,4 +153,43 @@ $('#dismiss-cookie-alert').click(function(event){ event.preventDefault(); -}) \ No newline at end of file +}) + +// Script for Resutlt Actions +$('.result-action-buttons').click(function(event){ + + var _id = $(this).data('_id') + + if ($(this).data('result-action') == 'generate') { + $.ajax({ + url: '/admin/certificate/', + type: 'POST', + data: JSON.stringify({'_id': _id}), + contentType: 'application/json', + dataType: 'html', + success: function(response) { + var display_window = window.open(); + display_window.document.write(response); + }, + error: function(response){ + error_response(response); + }, + }); + } else { + var action = $(this).data('result-action') + $.ajax({ + url: window.location.href, + type: 'POST', + data: JSON.stringify({'_id': _id, 'action': action}), + contentType: 'application/json', + success: function(response) { + if (action == 'delete') { + window.location.href = '/admin/results/'; + } else window.location.reload(); + }, + error: function(response){ + error_response(response); + }, + }); + } +}); \ No newline at end of file diff --git a/ref-test/admin/templates/admin/components/base.html b/ref-test/admin/templates/admin/components/base.html index c871c41..a635b8e 100644 --- a/ref-test/admin/templates/admin/components/base.html +++ b/ref-test/admin/templates/admin/components/base.html @@ -32,8 +32,10 @@ {% block content %}{% endblock %} -