From 173b1e329be19117e7cf94c598b71a89a3a89751 Mon Sep 17 00:00:00 2001 From: viveksantayana Date: Tue, 30 Nov 2021 18:16:52 +0000 Subject: [PATCH] Exam Code Time Controls --- ref-test/quiz/views.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ref-test/quiz/views.py b/ref-test/quiz/views.py index d7bf97f..c1fbf16 100644 --- a/ref-test/quiz/views.py +++ b/ref-test/quiz/views.py @@ -48,8 +48,13 @@ def start(): test_code = request.form.get('test_code').replace('—', '') user_code = request.form.get('user_code') user_code = None if user_code == '' else user_code - if not db.tests.find_one({'test_code': test_code}): + test = db.tests.find_one({'test_code': test_code}) + if not test: return jsonify({'error': 'The exam code you entered is invalid.'}), 400 + if test['expiry_date'] < datetime.utcnow(): + return jsonify({'error': f'The exam code you entered expired on {test["expiry_date"].strftime("%d %b %Y")}.'}), 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")}.'}), 400 entry = { '_id': uuid4().hex, 'name': encrypt(name),