def user_stats(): from rq import Queue from ..jobs import game_stats s3_bucket = current_app.config['S3_BUCKET'] aws_region = current_app.config['AWS_REGION'] q = Queue(connection=redis_store) user_role = '' if current_user.is_student(): user_role = 'student' if current_user.is_teacher(): user_role = 'teacher' if current_user.is_administrator(): user_role = 'administrator' result = q.enqueue(game_stats.game_stats, aws_region, s3_bucket, current_user.id, user_role, timeout=59 * 30) job_url = 'https://s3.amazonaws.com/{}/jobs/{}.csv'.format( s3_bucket, result.id) return render_template('game_stats.html', job_url=job_url)
def auth_login(): if current_user.is_authenticated: return redirect(url_for("index")) if request.method == "GET": return render_template("auth/login.html", form=LoginForm()) form = LoginForm(request.form) if not form.validate(): return render_template("auth/login.html", form=form, error="Remember to fill all the fields") user = User.query.filter_by(email=form.email.data, password=form.password.data).first() if not user: return render_template("auth/login.html", form=form, error="Incorrect email address or password") login_user(user) app.jinja_env.globals.update(is_student=current_user.is_student()) app.jinja_env.globals.update(is_teacher=current_user.is_teacher()) return redirect(url_for("index"))
def is_student(): if current_user: student = current_user.is_student() teacher = current_user.is_teacher() app.jinja_env.globals.update(is_student=student) app.jinja_env.globals.update(is_teacher=teacher) return else: app.jinja_env.globals.update(is_student=False) app.jinja_env.globals.update(is_teacher=False) return
def index(): #render a different page based on each user_type if current_user.is_admin(): return redirect(url_for('admin')) elif current_user.is_teacher(): return redirect(url_for('teacher')) elif current_user.is_parent(): return redirect(url_for('parent')) elif current_user.is_student(): return redirect(url_for('student')) else: #This should only happen if the user_type isn't set properly return render_template('index.html', title="Home", user=current_user, upcoming=upcoming)
def index(): cursor = get_db().cursor() if current_user.is_authenticated: if current_user.is_student(): lesson_instances = get_lesson_instances_for_student_id( current_user.student_id) return render_template('index.html', lesson_instances=lesson_instances) elif current_user.is_teacher(): lesson_instances = get_lesson_instances_for_teacher_id( current_user.teacher_id) return render_template('index.html', lesson_instances=lesson_instances) return render_template('index.html')
def courses_course(course_id): course = Course.query.get(course_id) if current_user.is_teacher(): students = course.find_students(course_id) length = course.count_students(course_id) return render_template("courses/course.html", course=course, students=students, length=length) courses = Course.query.all() mycourses = User.query.get(current_user.id).courses return render_template("courses/course.html", course=course, courses=courses, mycourses=mycourses)
def detail(number): problem = HomeWork.query.filter_by(id=number).first_or_404() if current_user.is_teacher(): page = request.args.get('page', 1, type=int) solutions = problem.solutions.order_by( Solution.timestamp.desc()).paginate(page, app.config['POSTS_PER_PAGE'], False) next_url = url_for('detail', page=solutions.next_num) \ if solutions.has_next else None prev_url = url_for('detail', page=solutions.prev_num) \ if solutions.has_prev else None return render_template("detail.html", title="Problem" + str(number), solutions=solutions.items, problem=problem, next_url=next_url, prev_url=prev_url) else: form = UploadFile() if form.validate_on_submit(): filename = form.file.data.filename unique_filename = str(uuid4()) file_path = app.config[ 'UPLOAD_FOLDER'] + 'solutions/' + unique_filename form.file.data.save(file_path) new_file = Solution(path=file_path, problem=problem, author=current_user, unique_name=unique_filename, name=filename) db.session.add(new_file) db.session.commit() flash("Successfully upload solution!") return redirect(url_for("detail", number=number)) return render_template("detail.html", title="Problem" + str(number), problem=problem, form=form)
def uploadHomeWork(): if current_user.is_teacher(): form = UploadFile() if form.validate_on_submit(): filename = form.file.data.filename unique_filename = str(uuid4()) file_path = app.config[ 'UPLOAD_FOLDER'] + 'homeworks/' + unique_filename form.file.data.save(file_path) new_file = HomeWork(name=filename, path=file_path, author=current_user, unique_name=unique_filename) db.session.add(new_file) db.session.commit() flash("Successfully create work!") return redirect(url_for("index")) return render_template("create_work.html", title="Create HomeWork", form=form) else: flash("You don't have permission!") return redirect(url_for("index"))
def users(): form = UserForm() if current_user.can(Permission.CREATE_USERS) and form.validate_on_submit(): user = User() user.username = form.username.data user.password = form.password.data user.role_id = form.role.data db.session.add(user) return redirect(url_for('.index')) page = request.args.get('page', 1, type=int) if current_user.is_teacher(): query = User.query.filter(User.teacher_id == current_user.id) else: query = User.query pagination = query.order_by(User.created.desc()).paginate( page, per_page=current_app.config['BACKEND_POSTS_PER_PAGE'], error_out=False) users = pagination.items return render_template('users.html', form=form, users=users, pagination=pagination)
def wrap_func(*args, **kwargs): if not current_user.is_teacher(): return None return func(*args, **kwargs)
def decorated_function(*args, **kwargs): if current_user.is_teacher(): abort(403) return f(*args, **kwargs)