def add_jobs(): form = JobsForm() if form.validate_on_submit(): session = db_session.create_session() if not session.query(User).filter( User.id == int(form.team_leader.data)).first(): return render_template('jobs.html', title='Добавление работы', form=form, message='несуществующий id коммандира') job = Jobs() job.job = form.title.data job.team_leader = int(form.team_leader.data) job.work_size = int(form.work_size.data) job.collaborators = form.collaborators.data job.is_finished = form.is_finished.data job.creator = current_user.id date_start = datetime.datetime.now() date_end = datetime.datetime.now() + datetime.timedelta( hours=int(form.work_size.data)) job.start_date = date_start job.end_date = date_end session.add(job) session.commit() return redirect('/') return render_template('jobs.html', title='Добавление работы', form=form)
def main(): db_session.global_init("db/mars_explorer.sqlite") session = db_session.create_session() job = Jobs() job.team_leader = 1 job.job = "deployment of residential modules 1 and 2" job.work_size = 15 job.collaborators = "2, 3" now = datetime.datetime.now() end = now + datetime.timedelta(days=job.work_size) job.start_date = now job.end_date = end job.is_finished = False session.add(job) session.commit()