Beispiel #1
0
def create_pupil_independent():
    """
    Create pupil account not connected to a class
    """
    email = request.json['email']
    password = request.json['password']
    firstname = request.json['firstname']
    surname = request.json['surname']
    
    # Check username and password etc.
    USER = mongo.load_by_arbitrary({'email':email}, 'users')
    if USER.exists():
        USER = {}
        return_data = {'message':'Username already taken'}
        return json.dumps({'status':0, 'data':return_data})
    
    else:
        # Create user
        mongo.create_user(
            username=email,
            firstname=firstname,
            surname=surname,
            password=password,
            display_name=None,
            is_teacher=False,
            email=email,
            confirmed=False)

        USER = mongo.load_by_arbitrary({'email':email}, 'users')
        session['user'] = USER.save_to_session()

        return_data = {}
        return json.dumps({'status':1, 'data':return_data})
Beispiel #2
0
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})
Beispiel #3
0
def teacher_all_exercises():
    """
    Show grid of all exercises (old and new and due)
    Filterable
    """
    # Load all submission objects for the pupil
    homeworks = mongo.load_by_arbitrary({'teacher_id':USER.get_id()}, 'homeworks', multiple=True)

    # Send along as json to be used within datatable (javascript)
    homework_data = []
    for H in homeworks:
        record = {
            'exercise_title_visible':H.get_exercise_title_visible(),
            'exercise_description_visible':H.get_exercise_description_visible(),
            'classroom_name':H.get_classroom_name(),
            'date_set':H.get_date_set(),
            'date_due':H.get_date_due(),
            'status_count':H.get_status_count(),
            'see_pupil_progress':{'text':'See pupil progress', 'url':url_for('teacher_exercise_progress', homework_id = H.get_id())},
            'see_exercises':{'text':'Preview exercise', 'url':'/'}
        }
        homework_data.append(record)
        debug(homework_data)

    return render_template('instructor_exercises.html', homework_data = homework_data) #, USER=USER)
Beispiel #4
0
def create_teacher_attempt():
    email = request.json['email']
    password = request.json['password']
    firstname = request.json['firstname']
    surname = request.json['surname']
    display_name = request.json['display_name']

    # Check email does not exist in database
    if mongo.load_by_arbitrary({'email':email}, 'users').exists():
        return_data = {'message':'This email address is already registered.'}
        return json.dumps({'status':0, 'data':return_data})

    # Create user
    mongo.create_user(
        username=email,
        firstname=firstname,
        surname=surname,
        display_name=display_name,
        password=password,
        is_teacher=True,
        email=email,
        confirmed=False)

    USER = mongo.load_by_username(email)
    session['user'] = USER.save_to_session()

    return_data = {}
    return json.dumps({'status':1, 'data':return_data})
Beispiel #5
0
def signup_pupil_into_classroom(entry_code):
    """
    Page for pupil to signup to a classroom using username and password
    i.e. school account
    If already logged in, allow logged in pupil to add class to their roster
    But count wrong attempts (for logged in or anon user) and block if too many
    """

    debug("Trying to enter class with entry code:{}".format(entry_code))

    classroom = mongo.load_by_arbitrary({'entry_code':entry_code}, 'classrooms')
    if not classroom.exists():
        flash('Sorry, this classroom does not exist')
        return redirect(url_for('home'))

    if USER.exists():
        # Check if already a member of this class
        if classroom.check_if_pupil_in_class(USER.get_id()):
            flash('You are already a member of this class')
            return redirect(url_for('pupil_all_exercises'))
        else:
            # Show confirmation page for pupil to confirm entry to class
            return render_template('pupil_join_classroom_confirm.html',
                entry_code=entry_code,
                teacher_name=classroom.get_teacher_name(),
                classroom_name=classroom.get_classroom_name()
                )
    else:    
        # If not logged in, allow account creation        
        return render_template('signup_pupil_via_school.html', entry_code=entry_code)
Beispiel #6
0
def create_pupil_via_school():
    """
    Create pupil account given a valid entry code
    Add pupil to the class whilst creating their account
    """
    username = request.json['username']
    password = request.json['password']
    entry_code = request.json['entry_code']
    firstname = request.json['firstname']
    surname = request.json['surname']
    
    # Check username and password etc.
    USER = mongo.load_by_username(username)
    if USER.exists():
        USER = {}
        return_data = {'message':'Username already taken'}
        return json.dumps({'status':0, 'data':return_data})
    
    # Create user
    mongo.create_user(
        username=username,
        firstname=firstname,
        surname=surname,
        password=password,
        display_name=None,
        is_teacher=False,
        email=None,
        confirmed=False)
    USER = mongo.load_by_username(username)
    session['user'] = USER.save_to_session()

    # Add to class
    classroom = mongo.load_by_arbitrary({'entry_code':entry_code}, 'classrooms')
    mongo.pupil_joins_classroom(USER, 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})
Beispiel #7
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})
Beispiel #8
0
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)
Beispiel #9
0
def teacher_exercise_progress(homework_id):
    """
    Show all pupils and their progress on the exercise
    """
    submissions = mongo.load_by_arbitrary({'teacher_id':USER.get_id(), 'homework_id':homework_id}, 'submissions', multiple=True)

    # Send along as json to be used within datatable (javascript)
    submission_data = []
    for S in submissions:
        record = {
            'pupil_name':S.get_pupil_name(),
            'exercise_title_visible':S.get_exercise_title_visible(),
            'progress':S.get_level_scores(),
            'status':S.get_status_display(),
            'total_score':display_pct(S.get_total_score()),
            'percentage_attempted':display_pct(S.get_percentage_attempted()),
            'see_attempt':{'text':'See attempt (TODO)', 'url':'/'},
        }
        submission_data.append(record)

    return render_template('instructor_submissions.html', submission_data = submission_data, format='pupils')
Beispiel #10
0
def teacher_all_classes():
    """
    Show grid of all classes
    """
    # Load all classrooms for teacher
    classrooms = mongo.load_by_arbitrary({'teacher_id':USER.get_id()}, 'classrooms', multiple=True)

    # Send along as json to be used within datatable (javascript)
    classroom_data = []
    for C in classrooms:
        record = {
            'name':C.get_classroom_name(),
            'pupil_count':C.get_number_of_pupils(),
            'latest_set':C.get_latest_set_and_next_due_homeworks(),
            'next_due':C.get_latest_set_and_next_due_homeworks(),
            'entry_code':C.get_entry_code(),
            'see_pupils':{'text':'Pupils', 'url':'/'},
            'see_exercises':{'text':'Exercises', 'url':'/'},
            'set_exercise':{'text':'Set exercise', 'url':'/'},
        }
        classroom_data.append(record)

    return render_template('instructor_classrooms.html', classroom_data=classroom_data)
Beispiel #11
0
def pupil_all_exercises():
    """
    Table (or nicer format) if all exercises done and to do
    \nTo do: can click (green) 'do exercise'
    \nDone: can click different button (blue) saying 'revisit'
    """
    # Load all submission objects for the pupil
    submissions = mongo.load_by_arbitrary({'user_id':USER.get_id()}, 'submissions', multiple=True)

    # Send along as json to be used within datatable (javascript)
    submission_data = []
    for S in submissions:
        record = {
            'exercise_name':{'text':S.get_exercise_title_visible(), 'url':S.get_href()},
            'exercise_description_visible':S.get_exercise_description_visible(),
            'status':S.get_status_display(),
            'total_score':display_pct(S.get_total_score()),
            'percentage_attempted':display_pct(S.get_percentage_attempted()),
            'date_set':S.get_date_set(),
            'date_due':S.get_date_due(),
        }
        submission_data.append(record)

    return render_template('my_exercises.html', submission_data = submission_data)