Completed client side time adjustment handling

Corrected error display bug
Removed redundant auth and models in quiz client app
This commit is contained in:
2021-12-04 17:14:28 +00:00
parent c71e91326f
commit 9a2d738653
12 changed files with 64 additions and 54 deletions

View File

@ -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})