def add_job(): form = JobForm() db_sess = db_session.create_session() form.categories.choices = [(category.id, category.name) for category in db_sess.query(Category).all()] if form.validate_on_submit(): if not db_sess.query(User).filter( User.id == form.team_leader.data).first(): return render_template("job.html", title="Добавить работу", form=form, message="Тимлидер не найден") job = Jobs(team_leader=form.team_leader.data, job=form.title.data, work_size=form.work_size.data, collaborators=form.collaborators.data, is_finished=form.is_finished.data, categories=[ db_sess.query(Category).get(category_id) for category_id in form.categories.data ]) db_sess.add(job) db_sess.commit() return redirect('/') return render_template('job.html', title='Добавить работу', form=form)
def edit_jobs(job_id): form = JobForm() if request.method == "GET": db_sess = db_session.create_session() jobs = db_sess.query(Jobs).filter(Jobs.id == job_id).first() if jobs: form.team_leader.data = current_user.id form.job.data = jobs.job form.work_size.data = jobs.work_size form.collaborators.data = jobs.collaborators form.is_finished.data = jobs.is_finished else: abort(404) if form.validate_on_submit(): db_sess = db_session.create_session() jobs = db_sess.query(Jobs).filter(Jobs.id == job_id).first() if jobs: jobs.team_leader = form.team_leader.data jobs.job = form.job.data jobs.work_size = form.work_size.data jobs.collaborators = form.collaborators.data jobs.is_finished = form.is_finished.data db_sess.commit() return redirect('/job') else: abort(404) return render_template('job.html', title='Редактирование новости', form=form)
def edit_news(id): form = JobForm() if request.method == "GET": session = db_session.create_session() job = session.query(Job).filter(Job.id == id, ((Job.leader == current_user) | (current_user.id == 1))).first() if job: form.job.data = job.job form.team_leader.data = job.team_leader form.work_size.data = job.work_size form.collaborators.data = job.collaborators form.is_finished.data = job.is_finished else: abort(404) if form.validate_on_submit(): session = db_session.create_session() job = session.query(Job).filter(Job.id == id, ((Job.leader == current_user) | (current_user.id == 1))).first() if job: job.job = form.job.data job.team_leader = form.team_leader.data job.work_size = form.work_size.data job.collaborators = form.collaborators.data job.is_finished = form.is_finished.data session.commit() return redirect('/') else: abort(404) return render_template("addjob.html", title="Редактирование работы", form=form)
def edit_job(id): form = JobForm() if request.method == "GET": db_sess = db_session.create_session() job = db_sess.query(Jobs).filter((Jobs.id == id), ((Jobs.team_leader == current_user.id) | (Jobs.team_leader == 1)) ).first() if job: form.description.data = job.description form.work_size.data = job.work_size form.collaborators.data = job.collaborators form.team_leader.data = job.team_leader form.start_date.data = datetime.datetime.strftime(job.start_date, "%d/%m/%Y %H:%M") form.end_date.data = datetime.datetime.strftime(job.end_date, "%d/%m/%Y %H:%M") form.is_finished.data = job.is_finished else: abort(404) if form.validate_on_submit(): db_sess = db_session.create_session() job = db_sess.query(Jobs).filter(Jobs.id == id, ((Jobs.team_leader == current_user.id) | (Jobs.team_leader == 1)) ).first() if job: job.description = form.description.data job.work_size = form.work_size.data job.collaborators = form.collaborators.data job.team_leader = form.team_leader.data job.start_date = datetime.datetime.strptime(form.start_date.data, "%d/%m/%Y %H:%M") job.end_date = datetime.datetime.strptime(form.end_date.data, "%d/%m/%Y %H:%M") job.is_finished = form.is_finished.data db_sess.commit() return redirect('/') else: abort(404) return render_template('addjob.html', form=form)
def add_job(): form = JobForm() if form.validate_on_submit(): if not form.team_leader.data.isdigit(): return render_template('job.html', title='Регистрация', form=form, message="Id of leader must be integer") if not form.work_size.data.isdigit(): return render_template('job.html', title='Регистрация', form=form, message="Work size must be integer") db_sess = db_session.create_session() job = Job( job=form.job.data, team_leader=form.team_leader.data, work_size=form.work_size.data, collaborators=form.collaborators.data, is_finished=form.is_finished.data, ) db_sess.add(job) db_sess.commit() return redirect('/') return render_template('job.html', title='Добавление работы', form=form)
def jobs(): form = JobForm(request.form) if form.validate_on_submit(): job = Job(user=g.user) form.populate_obj(job) db.session.add(job) db.session.commit() flash('Nyt job oprettet') return redirect(url_for('jobs')) return render_template('jobs.html', jobs=g.user.jobs.all(), form=form)
def add_job(): form = JobForm() if form.validate_on_submit(): session = db_session.create_session() job = Job() job.job = form.job.data job.team_leader = form.team_leader.data job.work_size = form.work_size.data job.collaborators = form.collaborators.data job.is_finished = form.is_finished.data current_user.jobs.append(job) session.merge(current_user) session.commit() return redirect("/") return render_template("addjob.html", title="Adding a job", form=form)
def edit_job(job_id): form = JobForm() db_sess = db_session.create_session() form.categories.choices = [(category.id, category.name) for category in db_sess.query(Category).all()] if request.method == "GET": if current_user.id == 1: job = db_sess.query(Jobs).filter(Jobs.id == job_id).first() else: job = db_sess.query(Jobs).filter( Jobs.id == job_id, Jobs.user == current_user).first() if job: form.title.data = job.job form.team_leader.data = job.team_leader form.work_size.data = job.work_size form.collaborators.data = job.collaborators form.is_finished.data = job.is_finished form.categories.data = [category.id for category in job.categories] else: abort(404) if form.validate_on_submit(): if current_user.id == 1: job = db_sess.query(Jobs).filter(Jobs.id == job_id).first() else: job = db_sess.query(Jobs).filter( Jobs.id == job_id, Jobs.user == current_user).first() if job: if not db_sess.query(User).filter( User.id == form.team_leader.data).first(): return render_template("job.html", title="Добавить работу", form=form, message="Тимлидер не найден") job.job = form.title.data job.team_leader = form.team_leader.data job.work_size = form.work_size.data job.collaborators = form.collaborators.data job.is_finished = form.is_finished.data job.categories = [ db_sess.query(Category).get(category_id) for category_id in form.categories.data ] db_sess.commit() return redirect("/") else: abort(404) return render_template("job.html", form=form, title="Редактировать работу")
def add_job(): form = JobForm() if form.validate_on_submit(): db_sess = db_session.create_session() job = Jobs() job.description = form.description.data job.work_size = form.work_size.data job.collaborators = form.collaborators.data job.team_leader = form.team_leader.data job.start_date = datetime.datetime.strptime(form.start_date.data, "%d/%m/%Y %H:%M") job.end_date = datetime.datetime.strptime(form.end_date.data, "%d/%m/%Y %H:%M") job.is_finished = form.is_finished.data db_sess.add(job) db_sess.commit() return redirect('/index') return render_template('addjob.html', form=form)
def add_job(): form = JobForm() form.team_leader.data = current_user.id if form.validate_on_submit(): db_sess = db_session.create_session() jobs = Jobs() jobs.team_leader = form.team_leader.data jobs.job = form.job.data jobs.work_size = form.work_size.data jobs.collaborators = form.collaborators.data jobs.is_finished = form.is_finished.data user = db_sess.query(User).filter(User.id == jobs.team_leader).first() user.jobs.append(jobs) db_sess.merge(user) db_sess.commit() return redirect("/job") return render_template("job.html", title="Добавление работы", form=form)
def add_jobs(): form = JobForm() if form.validate_on_submit(): db_sess = db_session.create_session() job = Jobs() job.team_leader = form.team_leader.data job.job = form.title.data job.work_size = form.work_size.data job.collaborators = form.collaborators.data job.category = form.category.data job.is_finished = form.is_finished.data db_sess.merge(current_user) db_sess.add(job) db_sess.commit() return redirect('/jobs_list') return render_template('jobs_form.html', title='Добавление работы', form=form)
def jobs_edit(job_id): form = JobForm() if request.method == "GET": session = db_session.create_session() if current_user.id == 1: job = session.query(Jobs).filter(Jobs.id == job_id).first() else: job = session.query(Jobs).filter( Jobs.id == job_id, Jobs.leader == current_user).first() if job: form.job.data = job.job form.leader_id.data = job.leader_id form.work_size.data = job.work_size form.collaborators.data = job.collaborators form.category.data = ', '.join( map(lambda x: x.name, job.categories)) form.is_finished.data = job.is_finished else: abort(404) if form.validate_on_submit(): session = db_session.create_session() if current_user.id == 1: job = session.query(Jobs).filter(Jobs.id == job_id).first() else: job = session.query(Jobs).filter( Jobs.id == job_id, Jobs.leader == current_user).first() if job: job.leader_id = form.leader_id.data job.job = form.job.data job.work_size = form.work_size.data job.collaborators = form.collaborators.data for i in map(int, form.category.data.split(',')): c = session.query(Category).filter(Category.id == i).first() if not c: c = Category(id=i, name=f'{i}') job.categories.append(c) job.is_finished = form.is_finished.data session.commit() return redirect('/') else: abort(404) return render_template('jobs_add.html', title='Редактирование работы', form=form)
def edit_job(id): form = JobForm() if request.method == "GET": db_sess = db_session.create_session() job = db_sess.query(Jobs).filter( Jobs.id == id, ((bool(1 == current_user.id)) | (bool(Jobs.team_leader == current_user.id)))).first() if job: form.team_leader.data = job.team_leader form.title.data = job.job form.work_size.data = job.work_size form.collaborators.data = job.collaborators form.category.data = job.category form.is_finished.data = job.is_finished else: abort(404) if form.validate_on_submit(): db_sess = db_session.create_session() job = db_sess.query(Jobs).filter( Jobs.id == id, ((bool(1 == current_user.id)) | (bool(Jobs.team_leader == current_user.id)))).first() if job: job.team_leader = form.team_leader.data job.job = form.title.data job.work_size = form.work_size.data job.collaborators = form.collaborators.data job.category = form.category.data job.is_finished = form.is_finished.data db_sess.commit() return redirect('/jobs_list') else: abort(404) return render_template('jobs_form.html', title='Редактирование работы', form=form)
def jobs_create(): form = JobForm() if form.validate_on_submit(): session = db_session.create_session() job = Jobs() job.leader_id = form.leader_id.data job.job = form.job.data job.work_size = form.work_size.data job.collaborators = form.collaborators.data for i in map(int, form.category.data.split(',')): c = session.query(Category).filter(Category.id == i).first() if not c: c = Category(id=i, name=f'{i}') job.categories.append(c) job.is_finished = form.is_finished.data user = session.query(User).filter(User.id == job.leader_id).first() if user: user.jobs.append(job) session.merge(current_user) session.commit() return redirect('/') return render_template('jobs_add.html', title='Добавление работы', form=form)