From 048d06ca1455b8081129832b2eebe5c26ac29345 Mon Sep 17 00:00:00 2001 From: viveksantayana Date: Sat, 4 Dec 2021 12:20:03 +0000 Subject: [PATCH] Added results CRUD and result detailed view --- ref-test/admin/models/tests.py | 4 + ref-test/admin/static/css/style.css | 5 + ref-test/admin/static/js/script.js | 41 +++- .../templates/admin/components/base.html | 8 +- .../admin/components/certificate.html | 84 +++++++++ .../templates/admin/components/datatable.html | 3 +- .../admin/templates/admin/result-detail.html | 175 ++++++++++++++++++ ref-test/admin/templates/admin/results.html | 139 +++++++++++++- .../templates/admin/settings/questions.html | 2 +- ref-test/admin/templates/admin/tests.html | 3 +- ref-test/admin/views.py | 59 +++++- ref-test/quiz/static/css/style.css | 5 + ref-test/quiz/static/js/quiz.js | 2 +- ref-test/quiz/templates/quiz/index.html | 5 +- .../quiz/templates/quiz/instructions.html | 5 +- ref-test/quiz/templates/quiz/result.html | 6 +- ref-test/quiz/templates/quiz/start-quiz.html | 5 +- ref-test/quiz/views.py | 84 +++++---- 18 files changed, 576 insertions(+), 59 deletions(-) create mode 100644 ref-test/admin/templates/admin/components/certificate.html create mode 100644 ref-test/admin/templates/admin/result-detail.html 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 %} -