diff --git a/ref-test/admin/models/tests.py b/ref-test/admin/models/tests.py
index a1b3397..edaaa70 100644
--- a/ref-test/admin/models/tests.py
+++ b/ref-test/admin/models/tests.py
@@ -41,18 +41,17 @@ class Test:
return jsonify({'error': f'Could not create exam. An error occurred.'}), 400
def add_time_adjustment(self, time_adjustment):
+ user_code = secrets.token_hex(3).upper()
adjustment = {
- '_id': uuid4().hex,
- 'user_code': secrets.token_hex(3).upper(),
- 'time_adjustment': time_adjustment
+ user_code: time_adjustment
}
- if db.tests.find_one_and_update({'_id': self._id}, {'$push': {'time_adjustments': adjustment}},upsert=False):
- flash(f'Time adjustment for {adjustment["time_adjustment"]} minutes has been added. This can be enabled using the user code {adjustment["user_code"]}.')
+ if db.tests.find_one_and_update({'_id': self._id}, {'$set': {'time_adjustments': adjustment}},upsert=False):
+ flash(f'Time adjustment for {time_adjustment} minutes has been added. This can be enabled using the user code {user_code}.')
return jsonify({'success': adjustment})
return jsonify({'error': 'Failed to add the time adjustment. An error occurred.'}), 400
- def remove_time_adjustment(self, _id):
- if db.tests.find_one_and_update({'_id': self._id}, {'$pull': {'time_adjustments': {'_id': _id} }}):
+ def remove_time_adjustment(self, user_code):
+ if db.tests.find_one_and_update({'_id': self._id}, {'$unset': {f'time_adjustments.{user_code}': {}}}):
message = 'Time adjustment has been deleted.'
flash(message, 'success')
return jsonify({'success': message})
diff --git a/ref-test/admin/static/js/script.js b/ref-test/admin/static/js/script.js
index 184374a..00c3b45 100644
--- a/ref-test/admin/static/js/script.js
+++ b/ref-test/admin/static/js/script.js
@@ -126,14 +126,16 @@ function error_response(response) {
`);
} else if (response.responseJSON.error instanceof Array) {
+ var output = ''
for (var i = 0; i < response.responseJSON.error.length; i ++) {
- $alert.html(`
+ output += `
${response.responseJSON.error}
@@ -49,14 +49,16 @@ function error_response(response) {
`);
} else if (response.responseJSON.error instanceof Array) {
+ var output = ''
for (var i = 0; i < response.responseJSON.error.length; i ++) {
- alert.html(`
+ output += `