def save_progress(): """ Save progress snapshot (for loading purposes), update the answer log, set the status of the submission """ # Load submission entry progress_snapshot = request.json['progress_snapshot'] answer_log = request.json['answer_log'] homework_id = id_mask(request.json['homework_id'], method='decrypt') question_time_taken = request.json['question_time_taken'] debug("We got this progress snapshot:") debug(progress_snapshot) submission = mongo.load_by_arbitrary( {'user_id':USER.get_id(), 'homework_id':homework_id}, 'submissions') # Set the progress snapshot to show latest progress (for when we next want to load) submission.set_progress_snapshot(progress_snapshot) # If this is the actual homework, add answer to the log if submission.get_status() != 'complete': submission.update_answer_logs(answer_log) # Update the status to 'in_progress' or 'complete' submission.update_status() if submission.get_status() == 'complete': print "Homework is now complete, do stuff here that needs to be done (e.g. updating other records)" # Save to database mongo.save_object(submission, 'submissions') return_data = {'message':'Saved data successfully.'} return json.dumps({'status':1, 'data':return_data})
def exercise(homework_id): """ Load the exercise (by homework id) Retrieve level list from homework id and send to javascript via jinja The html will then run the level page from there (by loading each level one by one) """ # Load submission entry to find status of submission (not started, in progress, complete (i.e. practice)) submission = mongo.load_by_arbitrary( {'user_id':USER.get_id(), 'homework_id':homework_id}, 'submissions') status = submission.get_status() progress_snapshot = submission.get_progress_snapshot() level_hash_list = submission.get_level_hash_list() exercise_title_visible = submission.get_exercise_title_visible() exercise_description_visible = submission.get_exercise_description_visible() question_attempts_required = submission.get_question_attempts_required() # If hasn't started, load page as homework submission with no progress if status=='not_started': exercise_status = 'submission' # If in progress, load page as homework submission passing latest progress elif status=='in_progress': exercise_status = 'submission' # If revision, load page as practice, passing latest progress elif status=='complete': exercise_status = 'revision' else: print "Unrecognised status!" return render_template('level_tester_full_exercise.html', level_hash_list = level_hash_list, exercise_status = exercise_status, progress_snapshot = progress_snapshot, homework_id = id_mask(homework_id, method='encrypt'), exercise_title_visible = exercise_title_visible, exercise_description_visible = exercise_description_visible, question_attempts_required = question_attempts_required, USER=USER)