コード例 #1
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        if form.password.data != form.repeat_password.data:
            return render_template('register.html',
                                   title="Решистрация",
                                   form=form,
                                   message="Пароли не совпадают")
        session = db_session.create_session()
        if session.query(User).filter(
                User.email == form.login_email.data).first():
            return render_template('register.html',
                                   title="Регистрация",
                                   form=form,
                                   message="Такой пользователь уже есть")
        user = User(name=form.name.data,
                    surname=form.surname.data,
                    age=form.age.data,
                    position=form.position.data,
                    speciality=form.specialty.data,
                    address=form.address.data,
                    hashed_password=form.password,
                    email=form.login_email.data)
        user.set_password(form.password.data)
        session.add(user)
        session.commit()
        return redirect('/login')
    return render_template('register.html', title='Регистрация', form=form)
コード例 #2
0
 def delete(self, job_id):
     abort_if_users_not_found(job_id)
     session = db_session.create_session()
     job = session.query(Jobs).get(job_id)
     session.delete(job)
     session.commit()
     return jsonify({'success:': 'OK'})
コード例 #3
0
 def get(self):
     session = db_session.create_session()
     jobs = session.query(Jobs).all()
     return jsonify({
         'jobs': [
             job.to_dict(only=('id', 'team_leader', 'job', 'work_size',
                               'collaborators', 'start_date', 'end_date',
                               'is_finished')) for job in jobs
         ]
     })
コード例 #4
0
 def get(self, job_id):
     abort_if_users_not_found(job_id)
     session = db_session.create_session()
     job = session.query(Jobs).get(job_id)
     return jsonify({
         'job':
         job.to_dict(only=('id', 'team_leader', 'job', 'work_size',
                           'collaborators', 'start_date', 'end_date',
                           'is_finished'))
     })
コード例 #5
0
 def post(self):
     args = self.parser.parse_args()
     session = db_session.create_session()
     jobs = Jobs(team_leader=args['team_leader'],
                 job=args['job'],
                 work_size=args['work_size'],
                 collaborators=args['collaborators'],
                 start_date=datetime.datetime.now(),
                 end_date=datetime.datetime.now(),
                 is_finished=bool(args['is_finished']))
     session.add(jobs)
     session.commit()
     return jsonify({'success': 'OK'})
コード例 #6
0
def login():
    form = LoginForm()

    if form.validate_on_submit():
        session = db_session.create_session()
        user = session.query(User).filter(
            User.email == form.email.data).first()
        if user and user.check_password(form.password.data):
            login_user(user, remember=form.remember_me.data)
            return redirect('/')
        return render_template('login.html',
                               message="Неправильный логин или пароль",
                               form=form)
    return render_template('login.html', title="Авторизация", form=form)
コード例 #7
0
def add_works():
    form = WorksForm()

    if form.validate_on_submit():
        session = db_session.create_session()
        job = Jobs(team_leader=form.team_leader.data,
                   job=form.job.data,
                   work_size=form.work_size.data,
                   collaborators=form.collaborators.data,
                   is_finished=form.is_finished.data)
        session.add(job)
        session.commit()
        return redirect('/')
    return render_template("add_works.html",
                           title="Добавление работ",
                           form=form)
コード例 #8
0
def works():
    session = db_session.create_session()
    all_jobs = session.query(Jobs).all()
    list_jobs = []
    for i in all_jobs:
        list_jobs.append({
            "id": i.id,
            "team_leader": i.team_leader,
            "job": i.job,
            "work_size": i.work_size,
            "collaborators": i.collaborators,
            "start_date": i.start_date,
            "end_date": i.end_date,
            "is_finished": i.is_finished
        })
    return render_template("work_log.html",
                           title="Журнал работ",
                           listUsers=list_jobs)
コード例 #9
0
def load_user(user_id):
    session = db_session.create_session()
    return session.query(User).get(user_id)
コード例 #10
0
def abort_if_users_not_found(job_id):
    session = db_session.create_session()
    job = session.query(Jobs).get(job_id)
    if not job:
        abort(404, message=f"Job {job_id} not found")
コード例 #11
0
def abort_if_users_not_found(user_id):
    session = db_session.create_session()
    user = session.query(User).get(user_id)
    print(user)
    if not user:
        abort(404, message=f"User {user_id} not found")