From 1d42d94ef2ac86872d8c3fd2431e6e60d222c048 Mon Sep 17 00:00:00 2001 From: Vivek Santayana Date: Tue, 7 Dec 2021 00:08:01 +0000 Subject: [PATCH] Better precision in expiring quizzes --- ref-test/admin/static/js/script.js | 1 + ref-test/admin/views.py | 12 ++++++------ ref-test/quiz/views.py | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ref-test/admin/static/js/script.js b/ref-test/admin/static/js/script.js index 08b5d5f..1e3a3ce 100644 --- a/ref-test/admin/static/js/script.js +++ b/ref-test/admin/static/js/script.js @@ -95,6 +95,7 @@ $('.test-action').click(function(event) { data: JSON.stringify({'_id': _id}), contentType: 'application/json', success: function(response) { + $(window).scrollTop(0); window.location.reload(); }, error: function(response){ diff --git a/ref-test/admin/views.py b/ref-test/admin/views.py index dfdd3c9..7d7cc19 100644 --- a/ref-test/admin/views.py +++ b/ref-test/admin/views.py @@ -81,9 +81,9 @@ def home(): from main import db tests = db.tests.find() results = decrypt_find(db.entries, {}) - current_tests = [ test for test in tests if test['expiry_date'].date() >= date.today() and test['start_date'].date() <= date.today() ] + current_tests = [ test for test in tests if test['expiry_date'] >= datetime.utcnow() and test['start_date'].date() <= date.today() ] current_tests.sort(key= lambda x: x['expiry_date'], reverse=True) - upcoming_tests = [ test for test in tests if test['start_date'].date() > date.today()] + upcoming_tests = [ test for test in tests if test['start_date'] > datetime.utcnow()] upcoming_tests.sort(key= lambda x: x['start_date']) recent_results = [result for result in results if 'submission_time' in result ] recent_results.sort(key= lambda x: x['submission_time'], reverse=True) @@ -348,11 +348,11 @@ def tests(filter=''): return render_template('/admin/tests.html', form = form, display_title=display_title, error_none=error_none, filter=filter) _tests = db.tests.find({}) if filter == 'active' or filter == '': - tests = [ test for test in _tests if test['expiry_date'].date() >= date.today() and test['start_date'].date() <= date.today() ] + tests = [ test for test in _tests if test['expiry_date'] >= datetime.utcnow() and test['start_date'].date() <= date.today() ] display_title = 'Active Exams' error_none = 'There are no exams that are currently active. You can create one using the Creat Exam form.' if filter == 'expired': - tests = [ test for test in _tests if test['expiry_date'].date() < date.today()] + tests = [ test for test in _tests if test['expiry_date'] < datetime.utcnow()] display_title = 'Expired Exams' error_none = 'There are no expired exams. Exams will appear in this category after their expiration date has passed.' if filter == 'scheduled': @@ -378,7 +378,7 @@ def create_test(): start_date = request.form.get('start_date') start_date = datetime.strptime(start_date, '%Y-%m-%d') expiry_date = request.form.get('expiry_date') - expiry_date = datetime.strptime(expiry_date, '%Y-%m-%d') + expiry_date = datetime.strptime(expiry_date, '%Y-%m-%d') + timedelta(days= 1) - timedelta(milliseconds = 1) dataset = request.form.get('dataset') errors = [] if start_date.date() < date.today(): @@ -422,7 +422,7 @@ def close_test(): from main import db _id = request.get_json()['_id'] if db.tests.find_one({'_id': _id}): - return Test(_id = _id, expiry_date= datetime.today() - timedelta(days=1)).update() + return Test(_id = _id, expiry_date= datetime.utcnow()).update() return jsonify({'error': 'Could not find the corresponding test to delete.'}), 404 @views.route('/test/<_id>/', methods=['GET','POST']) diff --git a/ref-test/quiz/views.py b/ref-test/quiz/views.py index 41d5a48..5f2e129 100644 --- a/ref-test/quiz/views.py +++ b/ref-test/quiz/views.py @@ -63,7 +63,7 @@ def start(): 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(): + if test['expiry_date'] < 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(): return jsonify({'error': f'The exam has not yet opened. Your exam code will be valid from {test["start_date"].strftime("%d %b %Y %H:%M")} UTC.'}), 400