Example #1
0
def create_homework_submit():
    """
    Create a homework object and save to database
    (this will create submission for each pupil)
    """
    classroom_id = request.json['classroom_id']
    exercise_id = request.json['exercise_id']
    date_set = request.json['date_set']
    date_due = request.json['date_due']
    attempts_required = request.json['attempts_required']
    pupil_list = request.json['pupil_list']
    exclude_include = request.json['exclude_include']

    exercise_object = mongo.load_by_id(ObjectId(exercise_id), 'exercises')
    classroom_object = mongo.load_by_id(ObjectId(classroom_id), 'classrooms')

    # Debug
    debug_text = "Loaded this exercise --> {}".format(exercise_object.D)
    debug(debug_text)
    debug_text = "Loaded this classroom --> {}".format(classroom_object.D)
    debug(debug_text)

    mongo.create_homework(
        exercise_object = exercise_object,
        classroom_object = classroom_object,
        teacher_object = USER,
        date_set=date_set,
        date_due=date_due)

    debug("Created homework.")

    return_data = {}
    return json.dumps({'status':1, 'data':return_data})
Example #2
0
def pupil_join_classroom_confirm():
    """
    Pupil joins classroom (already logged in, entry code for classroom)
    """
    entry_code = request.json['entry_code']
    
    # Add to class
    USER_db = mongo.load_by_id(ObjectId(USER.get_id()), 'users') # Load proper pupil from DB
    classroom = mongo.load_by_arbitrary({'entry_code':entry_code}, 'classrooms')
    mongo.pupil_joins_classroom(USER_db, classroom)

    # Create submission objects (should refactor all of this code a bit)
    pupil_id = USER.get_id()
    pupil_name = USER.get_display_name()
    for homework_id in classroom.get_homework_ids():
        homework_object = mongo.load_by_arbitrary({'_id':homework_id}, 'homeworks')
        mongo.create_submission(pupil_id, pupil_name, homework_object)

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