From b0d3ff3fc186383d1a0fb804169aadfc0fad7f64 Mon Sep 17 00:00:00 2001 From: viveksantayana Date: Mon, 6 Dec 2021 23:16:33 +0000 Subject: [PATCH] Close Quiz function --- ref-test/admin/static/js/script.js | 13 +++++++++++++ ref-test/admin/templates/admin/test.html | 14 +++++++++----- ref-test/admin/views.py | 12 +++++++++++- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/ref-test/admin/static/js/script.js b/ref-test/admin/static/js/script.js index d950bc3..08b5d5f 100644 --- a/ref-test/admin/static/js/script.js +++ b/ref-test/admin/static/js/script.js @@ -88,6 +88,19 @@ $('.test-action').click(function(event) { }); } else if (action == 'edit') { window.location.href = `/admin/test/${_id}/` + } else if (action == 'close'){ + $.ajax({ + url: `/admin/tests/close/`, + type: 'POST', + data: JSON.stringify({'_id': _id}), + contentType: 'application/json', + success: function(response) { + window.location.reload(); + }, + error: function(response){ + error_response(response); + }, + }); } event.preventDefault(); diff --git a/ref-test/admin/templates/admin/test.html b/ref-test/admin/templates/admin/test.html index ff845a9..a308f13 100644 --- a/ref-test/admin/templates/admin/test.html +++ b/ref-test/admin/templates/admin/test.html @@ -167,11 +167,15 @@ {% include "admin/components/client-alerts.html" %}
-
diff --git a/ref-test/admin/views.py b/ref-test/admin/views.py index 54a4108..bdb223c 100644 --- a/ref-test/admin/views.py +++ b/ref-test/admin/views.py @@ -1,7 +1,7 @@ from flask import Blueprint, render_template, flash, redirect, request, jsonify, abort, session from flask.helpers import url_for from functools import wraps -from datetime import datetime +from datetime import datetime, timedelta import os from glob import glob @@ -415,6 +415,16 @@ def delete_test(): return Test(_id = _id).delete() return jsonify({'error': 'Could not find the corresponding test to delete.'}), 404 +@views.route('/tests/close/', methods=['POST']) +@admin_account_required +@login_required +def delete_test(): + from main import db + _id = request.get_json()['_id'] + if db.tests.find_one_and_update({'_id': _id}, {'$set': {'expiry_date': datetime.today() - timedelta(days=1) }}): + return Test(_id = _id).delete() + return jsonify({'error': 'Could not find the corresponding test to delete.'}), 404 + @views.route('/test/<_id>/', methods=['GET','POST']) @admin_account_required @login_required