Better precision in expiring quizzes
This commit is contained in:
		@@ -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){
 | 
			
		||||
 
 | 
			
		||||
@@ -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'])
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user