def edit_job(job_id): form = AddJobForm() if request.method == 'GET': session = db_session.create_session() job = session.query(Jobs).filter(Jobs.id == job_id, ((Jobs.team_leader == current_user.id) | (current_user.id == 1))).first() if job: form.job_field.data = job.job form.team_leader_field.data = job.team_leader form.work_size_field.data = job.work_size form.collaborators_field.data = job.collaborators form.finished_field.data = job.is_finished return render_template('job_form.html', form=form, edit=True) else: abort(404) if form.validate_on_submit(): session = db_session.create_session() job = session.query(Jobs).filter(Jobs.id == job_id, ((Jobs.team_leader == current_user.id) | (current_user.id == 1))).first() if job: job.job = form.job_field.data job.team_leader = form.team_leader_field.data job.collaborators = form.collaborators_field.data job.work_size = form.work_size_field.data job.is_finished = form.finished_field.data session.commit() return redirect('/') else: abort(404)
def index(): db_sess = db_session.create_session() jobs = db_sess.query(Jobs).all() team_leaders = [] for i in range(len(jobs)): team_leaders.append(' '.join(db_sess.query(User.surname, User.name).filter(User.id == jobs[i].team_leader)[0])) return render_template('jobs.html', jobs=jobs, team_leaders=team_leaders)
def index(): db_session.global_init('db/mars_explorer.sqlite') db_sess = db_session.create_session() jobs = db_sess.query(Jobs).all() for i in range(len(jobs)): jobs[i].team_leader = ' '.join( db_sess.query(User.surname, User.name).filter(User.id == jobs[i].team_leader)[0]) return render_template('jobs.html', jobs=jobs)
def delete_job(job_id): session = db_session.create_session() job = session.query(Jobs).filter(Jobs.id == job_id, ((Jobs.team_leader == current_user.id) | (current_user.id == 1))).first() if job: session.delete(job) session.commit() else: abort(404) return redirect('/')
def login(): form = LoginForm() if form.validate_on_submit(): db_sess = db_session.create_session() user = db_sess.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)
def add_job(): form = AddJobForm() if form.validate_on_submit(): session = db_session.create_session() job = Jobs() job.job = form.job_field.data job.team_leader = form.team_leader_field.data job.collaborators = form.collaborators_field.data job.work_size = form.work_size_field.data job.is_finished = form.finished_field.data session.add(job) session.commit() return redirect('/') return render_template('job_form.html', form=form, edit=False)
def register(): form = RegistrationForm() if form.validate_on_submit(): session = db_session.create_session() user = User() user.surname = form.surname_field.data user.name = form.name_field.data user.age = form.age_field.data user.position = form.position_field.data user.speciality = form.speciality_field.data user.address = form.address_field.data user.email = form.email_field.data user.set_password(form.password_field.data) session.add(user) session.commit() return redirect('/') return render_template('register.html', title='Регистрация пользователя', form=form)
def registration(): form = RegistrationForm() if form.validate_on_submit(): db_session.global_init('db/mars_explorer.sqlite') session = db_session.create_session() user = User() user.surname = form.surname_field.data user.name = form.name_field.data user.age = form.age_field.data user.position = form.position_field.data user.speciality = form.speciality_field.data user.address = form.address_field.data user.email = form.email_field.data user.hashed_password = form.password_field.data session.add(user) session.commit() return redirect('/register/success') return render_template('register.html', title='Регистрация пользователя', form=form)
def load_user(user_id): db_sess = db_session.create_session() return db_sess.query(User).get(user_id)