Пример #1
0
def classroom_student_join_code(join_code):
    if not 'user_id' in session:
        session['user_id'] = db.insert("INSERT INTO users VALUES()", [])
    
    classroom = db.fetchrow("SELECT * FROM classrooms WHERE join_code = %s", [join_code])
    
    if not classroom:
        return redirect(url_for('.index'))
        
    classroom_user_code = db.get_classroom_user_code(classroom['id'], session['user_id'])

    return render_template('classroom/student.html', 
        user_token          = security.create_user_token(session['user_id'], classroom_id=classroom['id']), 
        classroom           = classroom,
        classroom_user_code = classroom_user_code,
        execution_link      = "%s%s" % (request.host_url[:-1], url_for('.execute_code_by_short_code', classroom_id=classroom['id'], short_code=classroom_user_code['short_code']), )
    )
Пример #2
0
def classroom_teacher(classroom_id):
    if not 'user_id' in session:
        session['user_id'] = db.insert("INSERT INTO users VALUES()", [])

    result = db.fetchrow("SELECT COUNT(*) AS total_entries FROM classroom_user_roles WHERE user_id = %s AND role = %s", [session['user_id'], ClassroomRoles.TEACHER])

    if result['total_entries'] <= 0:
        return redirect(url_for('.classroom_student', classroom_id=classroom_id))
    
    classroom = db.fetchrow("SELECT * FROM classrooms WHERE id = %s", [classroom_id])

    if not classroom:
        return redirect(url_for('.index'))
    
    public_link = "%s%s" % (request.host_url[:-1], url_for('.classroom_student_join_code', join_code=classroom['join_code']), )

    return render_template('classroom/teacher.html', user_token=security.create_user_token(session['user_id'], classroom_id=classroom_id), classroom=classroom, public_link=public_link)