Ejemplo n.º 1
0
def editJobs(jobId):
	db_sess = create_session()

	jobs = ()
	if current_user.id != 1:
		jobs = db_sess.query(Jobs).filter(Jobs.id == jobId, Jobs.team_leader == current_user.id).all()
	else:
		jobs = db_sess.query(Jobs).filter(Jobs.id == jobId).all()

	if len(jobs) == 0:
		return redirect('/')
	else:
		jobs = jobs[0]

	form = JobsForm(
			job=jobs.job,
			work_size = jobs.work_size,
			collaborators = jobs.collaborators,
			start_date = jobs.start_date,
			end_date = jobs.end_date,
			is_finished = jobs.is_finished
	)

	if form.validate_on_submit():
		jobs.job = form.job.data
		jobs.work_size = form.work_size.data
		jobs.collaborators = form.collaborators.data
		jobs.start_date = form.start_date.data
		jobs.end_date = form.end_date.data
		jobs.is_finished = form.is_finished.data
		db_sess.commit()
		return redirect('/')
	return render_template('editJobs.html', title='Edit jobs', heading="Edit jobs", form=form)
Ejemplo n.º 2
0
def edit_job(job_id):
    local_db_session = db_session.create_session()
    captain = local_db_session.query(User).get(1)
    if all(map(lambda x: x.id != job_id, current_user.jobs)) and all(map(lambda x: x.id != job_id, captain.jobs)):
        return redirect('/')
    job = local_db_session.query(Jobs).get(job_id)
    if job is None:
        return flask.jsonify({"error": "Bad request"})
    form = JobsForm()
    if form.validate_on_submit():
        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
        local_db_session.commit()
        return redirect('/')
    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 = bool(job.is_finished)
    params = {
        "title": "Editing a Job",
        "current_user": current_user,
        "form": form
    }
    return render_template("jobs.html", **params)
Ejemplo n.º 3
0
def edit_news(id):
	form = JobsForm()
	if request.method == "GET":
		db_sess = db_session.create_session()
		if current_user.id == 1:
			jobs = db_sess.query(Jobs).first()
		else:
			jobs = db_sess.query(Jobs).filter(Jobs.id == id, Jobs.user == current_user).first()
		if jobs:
			form.job.data = jobs.job
			form.team_leader.data = jobs.team_leader
			form.work_size.data = jobs.work_size
			form.list_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()
		if current_user.id == 1:
			jobs = db_sess.query(Jobs).first()
		else:
			jobs = db_sess.query(Jobs).filter(Jobs.id == id, Jobs.user == current_user).first()
		if jobs:
			jobs.job = form.job.data
			jobs.team_leader = form.team_leader.data
			jobs.work_size = form.work_size.data
			jobs.collaborators = form.list_collaborators.data
			jobs.is_finished = form.is_finished.data
			db_sess.commit()
			return redirect('/')
		else:
			abort(404)
	return render_template('jobs.html', title='Редактирование работы', form=form)
Ejemplo n.º 4
0
def edit_news(id):
    form = JobsForm()
    if request.method == "GET":
        db_sess = db_session.create_session()
        jobs = db_sess.query(Jobs).filter(Jobs.id == id | Jobs.id == 1).first()
        if jobs:
            jobs.job = form.job.data
            jobs.team_leader = form.team_leader.data
            jobs.duration = form.duration.data
            jobs.collaborators = form.collaborators.data
            jobs.is_finished = form.is_finished.data
        else:
            abort(404)
    if form.validate_on_submit():
        db_sess = db_session.create_session()
        jobs = db_sess.query(Jobs).filter(Jobs.id == id | Jobs.id == 1).first()
        if jobs:
            jobs.job = form.job.data
            jobs.team_leader = form.team_leader.data
            jobs.duration = form.duration.data
            jobs.collaborators = form.collaborators.data
            jobs.is_finished = form.is_finished.data
            return redirect('/')
        else:
            abort(404)
    return render_template('jobs.html',
                           title='Redactioning of work',
                           form=form)
Ejemplo n.º 5
0
def edit_job(job_id):
    form = JobsForm()
    if request.method == "GET":
        session = db_session.create_session()
        jobs = session.query(Jobs).filter(Jobs.id == job_id,
                                          (Jobs.user_author == current_user) | (current_user.id == 1)).first()
        if jobs:
            form.team_leader.data = jobs.team_leader
            form.job.data = jobs.job
            form.work_size.data = jobs.work_size
            form.collaborators.data = jobs.collaborators
            form.start_date.data = jobs.start_date
            form.end_date.data = jobs.end_date
            form.is_finished.data = jobs.is_finished
            form.category.data = jobs.category
        else:
            abort(404)
    if form.validate_on_submit():
        session = db_session.create_session()
        jobs = session.query(Jobs).filter(Jobs.id == job_id,
                                          (Jobs.user_author == current_user) | (current_user.id == 1)).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.start_date = form.start_date.data
            jobs.end_date = form.end_date.data
            jobs.is_finished = form.is_finished.data
            jobs.category = form.category.data
            session.commit()
            return redirect("/")
        else:
            abort(404)
    return render_template("jobs.html", title="Редактирование работы", form=form)
Ejemplo n.º 6
0
def edit_jobs(id):
    form = JobsForm()
    if request.method == "GET":
        db_sess = db_session.create_session()
        jobs = db_sess.query(Jobs).filter(Jobs.id == id,
                                          Jobs.user == current_user).first()
        if jobs:
            form.title.data = jobs.title
            form.content.data = jobs.content
            form.contacts.data = jobs.contacts
            form.salary.data = jobs.salary
        else:
            abort(404)

    if form.validate_on_submit():
        db_sess = db_session.create_session()
        jobs = db_sess.query(Jobs).filter(Jobs.id == id,
                                          Jobs.user == current_user).first()
        if jobs:
            jobs.title = form.title.data
            jobs.content = form.content.data
            jobs.salary = form.salary.data
            jobs.contacts = form.contacts.data
            db_sess.commit()
            return redirect('/')
        else:
            abort(404)
    return render_template('jobs.html',
                           title='Редактирование вакансии',
                           form=form)
Ejemplo n.º 7
0
def login_job():
    form = JobsForm()
    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)
Ejemplo n.º 8
0
def add_jobs():
    form = JobsForm()
    if form.validate_on_submit():
        db_sess = db_session.create_session()
        jobs = Jobs()
        jobs.title = form.title.data
        jobs.salary = form.salary.data
        jobs.contacts = form.contacts.data
        jobs.content = form.content.data
        current_user.jobs.append(jobs)
        db_sess.merge(current_user)
        db_sess.commit()
        return redirect('/')
    return render_template('jobs.html', title='Добавление вакансии', form=form)
Ejemplo n.º 9
0
Archivo: main.py Proyecto: itpots/web
def add_news():
    form = JobsForm()
    if form.validate_on_submit():
        db_sess = db_session.create_session()
        job = Jobs()
        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
        db_sess.add(job)
        db_sess.commit()
        return redirect('/')
    return render_template('jobs.html', title='Добавление работы', form=form)
Ejemplo n.º 10
0
def add_jobs():
	form = JobsForm()
	if form.validate_on_submit():
		db_sess = db_session.create_session()
		jobs = Jobs()
		jobs.job = form.job.data
		jobs.team_leader = form.team_leader.data
		jobs.work_size = form.work_size.data
		jobs.collaborators = form.list_collaborators.data
		jobs.is_finished = form.is_finished.data
		current_user.job.append(jobs)
		db_sess.merge(current_user)
		db_sess.commit()
		return redirect('/')
	return render_template('jobs.html', title='Добавление работы', form=form)
Ejemplo n.º 11
0
def add_news():
    form = JobsForm()
    if form.validate_on_submit():
        db_sess = db_session.create_session()
        jobs = Jobs()
        jobs.job = form.job.data
        jobs.team_leader = form.team_leader.data
        jobs.duration = form.duration.data
        jobs.collaborators = form.collaborators.data
        jobs.is_finished = form.is_finished.data
        current_user.jobs.append(jobs)
        db_sess.merge(current_user)
        db_sess.commit()
        return redirect('/')
    return render_template('jobs.html', title='add work', form=form)
Ejemplo n.º 12
0
def add_news():
    if not current_user.is_authenticated:
        return redirect('/')
    form = JobsForm()
    if form.validate_on_submit():
        session = db_session.create_session()
        news = Jobs()
        news.title = form.title.data
        news.content = form.content.data
        news.is_private = form.is_private.data
        current_user.news.append(news)
        session.merge(current_user)
        session.commit()
        return redirect('/')
    return render_template('jobs.html',
                           form=form)
Ejemplo n.º 13
0
def addJobs():
	form = JobsForm()
	if form.validate_on_submit():
		db_sess = create_session()
		jobs = Jobs(
			team_leader=current_user.id,
			job=form.job.data,
			work_size=form.work_size.data,
			collaborators=form.collaborators.data,
			start_date=form.start_date.data,
			end_date=form.end_date.data,
			is_finished=form.is_finished.data,
		)
		db_sess.add(jobs)
		db_sess.commit()
		return redirect('/')
	return render_template('editJobs.html', title='Add jobs', heading="Add jobs", form=form)
Ejemplo n.º 14
0
def add_job():
    form = JobsForm()
    if form.validate_on_submit():
        session = 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.start_date = form.start_date.data
        jobs.end_date = form.end_date.data
        jobs.is_finished = form.is_finished.data
        jobs.category = form.category.data
        current_user.jobs.append(jobs)
        session.merge(current_user)
        session.commit()
        return redirect("/")
    return render_template("jobs.html", title="Добавление работы", form=form)
Ejemplo n.º 15
0
def add_job():
    local_db_session = db_session.create_session()
    form = JobsForm()
    if form.validate_on_submit():
        job = Jobs(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)
        current_user.jobs.append(job)
        local_db_session.merge(current_user)
        local_db_session.commit()
        return redirect('/')
    params = {
        "title": "Adding a Job",
        "current_user": current_user,
        "form": form
    }
    return render_template("jobs.html", **params)
Ejemplo n.º 16
0
def newjob():
    if not current_user.is_authenticated:
        return redirect('/')
    form = JobsForm()
    if form.validate_on_submit():
        session = db_session.create_session()
        newjob = Jobs(
            team_leader_id=current_user.id,
            description=form.description.data,
            work_size=form.work_size.data,
            start_date=form.start_date.data,
            is_finished=form.is_finished.data,
        )
        colls = list(map(int, form.collaborators.data.split(',')))
        for col in colls:
            newjob.collaborators.append(col)
        session.add(newjob)
        session.commit()
        return redirect('/')
    return render_template('jobs.html', title='Новая работа', form=form)
Ejemplo n.º 17
0
def update_job(id):
    form = JobsForm()

    if form.validate_on_submit():
        session = create_session()
        job = session.query(Jobs).filter(Jobs.id == id).first()

        job.job = form.job.data
        job.work_size = form.work_size.data
        collaborators = []
        for collaborator in form.collaborators.data.split(','):
            surname, name = collaborator.split()
            collaborators.append(session.query(User).filter(User.surname == surname,
                                                            User.name == name).first().id)
        job.collaborators = ', '.join(map(str, collaborators))
        job.category = session.query(Category).filter(Category.name == form.category.data).first().id
        job.is_finished = form.is_finished.data

        session.commit()

        return redirect('/')

    session = create_session()
    job = session.query(Jobs).filter(Jobs.id == id).first()
    if current_user.id != 1 and current_user.id != job.team_leader:
        return redirect('/')
    form.job.data = job.job
    form.work_size.data = job.work_size
    collaborators = []
    for collaborator in job.collaborators.split(', '):
        collaborators.append(session.query(User).filter(User.id == collaborator).first().fio())
    form.collaborators.data = ', '.join(collaborators)
    form.category.data = session.query(Category).filter(Category.id == job.category).first().name
    form.is_finished.data = job.is_finished

    return render_template('job.html', title=f"Редактирование работы", form=form)
Ejemplo n.º 18
0
def add_job():
    form = JobsForm()

    if form.validate_on_submit():
        session = create_session()
        job = Jobs()

        job.team_leader = session.query(User).filter(User.email == current_user.email).first().id
        job.job = form.job.data
        job.work_size = form.work_size.data
        collaborators = []
        for collaborator in form.collaborators.data.split(','):
            surname, name = collaborator.split()
            collaborators.append(session.query(User).filter(User.surname == surname, User.name == name).first().id)
        job.collaborators = ', '.join(map(str, collaborators))
        job.category = session.query(Category).filter(Category.name == form.category.data).first()
        job.is_finished = form.is_finished.data

        session.add(job)
        session.commit()

        return redirect('/')

    return render_template('job.html', title=f"Добавление работы", form=form)