コード例 #1
0
ファイル: app.py プロジェクト: abelmaths/flask_v1
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})
コード例 #2
0
ファイル: app.py プロジェクト: abelmaths/flask_v1
def submit_personal_info():
    firstname = request.json['firstname']
    surname = request.json['surname']

    # Load full USER object from DB to make edits to it
    U = mongo.load_by_username(USER.get_username())

    U.set_surname(surname)
    U.set_firstname(firstname)

    if U.is_teacher():
        U = request.json['display_name']
        USER.set_display_name(display_name)
    else:
        U.set_display_name(None)  # Will just amalgamate firstname and surname for pupils

    # Save all of this to the database and put latest in session
    mongo.save_object(U, 'users')
    session['user'] = U.save_to_session()

    return_data = {}
    return json.dumps({'status':1, 'data':return_data})