예제 #1
0
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)
예제 #2
0
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()
예제 #3
0
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)