Example #1
0
def index():
    db_sess = db_session.create_session()
    user = db_sess.query(User).filter(User.login == current_user.login).first()
    if user.ball == 0:
        return render_template("ready.html", user=user, ball=0)
    else:
        return render_template("ready.html", user=user, ball=int(user.ball))
    def get(self, login):

        abort_if_news_not_found(login)
        session = db_session.create_session()
        user = session.query(User).filter(User.login == login).first()
        return jsonify({'users': user.to_dict(
            only=('name', 'surname', 'login'))})
 def delete(self, login):
     abort_if_news_not_found(login)
     session = db_session.create_session()
     user = session.query(User).filter(User.login == login).first()
     session.delete(user)
     session.commit()
     return jsonify({'success': 'OK'})
 def get(self, test_id):
     abort_if_news_not_found(test_id)
     session = db_session.create_session()
     test = session.query(Test).get(test_id)
     return jsonify({
         'tests':
         test.to_dict(only=('question', 'answers_options', 'answer'))
     })
 def get(self):
     session = db_session.create_session()
     test = session.query(Test).all()
     return jsonify({
         'test': [
             item.to_dict(only=('question', 'answers_options', 'answer'))
             for item in test
         ]
     })
Example #6
0
def student_login():
    if request.method == 'GET':
        db_sess = db_session.create_session()
        quest = db_sess.query(Test).all()
        user = db_sess.query(User).filter(
            User.login == current_user.login).first()
        sp = []
        sp_id = []
        sp_ans = []
        ch = 0
        while ch != 10:
            z = random.choice(quest)
            if z.id not in [i.id for i in sp]:
                s = z.answers_options.split('\n')
                sp_ans.append([])
                for i in s:
                    if i:
                        sp_ans[-1].append(i)
                sp.append(z)
                sp_id.append(str(z.id))
                ch += 1
        user.questions_id = ' '.join(sp_id)
        db_sess.commit()
        return render_template("Test_form.html", questions=sp, ans_opt=sp_ans)
    elif request.method == 'POST':
        db_sess = db_session.create_session()
        user = db_sess.query(User).filter(
            User.login == current_user.login).first()
        quest = db_sess.query(Test).all()
        ch = 0
        for i in quest:
            if str(i.id) in user.questions_id.split():
                if str(request.form.get(str(i.id))).split(')')[0] == i.answer:
                    ch += 1
        user.ball = ch
        db_sess.commit()
        return redirect("/user_student_entrance")
 def post(self):
     args = parser.parse_args()
     session = db_session.create_session()
     user = User(
         name=args['name'],
         surname=args['surname'],
         login=args['login'],
         hashed_password=args['hashed_password'],
         klass=args['klass'],
         ball=0,
         is_teacher=0,
         questions_id=''
     )
     session.add(user)
     session.commit()
     return jsonify({'success': 'OK'})
Example #8
0
def student_delete():
    form = DeleteStudentForm()
    if form.validate_on_submit():
        db_sess = db_session.create_session()
        student = db_sess.query(User).filter(
            User.login == form.login.data).first()
        if student and current_user.hashed_password == form.password.data:
            db_sess.delete(student)
            db_sess.commit()
            return redirect('/user_teacher')
        return render_template('Delete_student.html',
                               message="Неправильный логин или пароль",
                               form=form)
    return render_template('Delete_student.html',
                           title='удаление ученика',
                           form=form)
Example #9
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        db_sess = db_session.create_session()
        user = db_sess.query(User).filter(
            User.login == form.login.data).first()
        if user and user.hashed_password == form.password.data:
            login_user(user, remember=form.remember_me.data)
            if user.is_teacher:
                return redirect("/user_teacher")
            else:
                return redirect("/user_student_entrance")
        return render_template('login.html',
                               message="Неправильный логин или пароль",
                               form=form)
    return render_template('login.html', title='Авторизация', form=form)
Example #10
0
def student_app():
    form = RegistForm()
    if form.validate_on_submit():
        if form.password.data != form.password_again.data:
            return render_template('register.html',
                                   title='Регистрация',
                                   form=form,
                                   message="Пароли не совпадают")
        db_sess = db_session.create_session()
        if db_sess.query(User).get(form.login.data):
            return render_template('register.html',
                                   title='Регистрация',
                                   form=form,
                                   message="Такой пользователь уже есть")
        user = User(name=form.name.data,
                    surname=form.surname.data,
                    login=form.login.data,
                    ball=0)
        user.hashed_password = form.password.data
        db_sess.add(user)
        db_sess.commit()
        return redirect('/user_teacher')
    return render_template('register.html', title='Регистрация', form=form)
def abort_if_news_not_found(login):
    session = db_session.create_session()
    user = session.query(User).filter(User.login == login).first()
    if not user:
        abort(404, message=f"News {login} not found")
 def get(self):
     session = db_session.create_session()
     user = session.query(User).all()
     return jsonify({'user': [item.to_dict(
         only=('name', 'surname', 'login')) for item in user]})
Example #13
0
def teacher_login():
    db_sess = db_session.create_session()
    sp = db_sess.query(User).filter(User.is_teacher == 0)
    return render_template('table_student.html',
                           title='Таблица учеников',
                           students=sp)
Example #14
0
def load_user(user_id):
    db_sess = db_session.create_session()
    return db_sess.query(User).get(user_id)
def abort_if_news_not_found(test_id):
    session = db_session.create_session()
    test = session.query(Test).get(test_id)
    if not test:
        abort(404, message=f"News {test_id} not found")