Exemplo n.º 1
0
def create_job():
    if not request.json:
        return jsonify({'error': 'Empty request'})
    elif not all(key in request.json for key in [
            'id', 'team_leader', 'jod', 'work_size', 'collaborators',
            'hazard_category', 'is_finished', 'add_by'
    ]):
        return jsonify({'error': 'Bad request'})
    session = db_session.create_session()
    job = jobs.Jobs(team_leader=request.json['team_leader'],
                    jod=request.json['jod'],
                    work_size=request.json['work_size'],
                    collaborators=request.json['collaborators'],
                    hazard_category=request.json['hazard_category'],
                    is_finished=request.json['is_finished'],
                    add_by=request.json['add_by'])
    a = list(map(lambda x: x['id'], list(session.query(jobs.Jobs).all())))
    if request.json['id'] in a:
        old_job = session.query(
            jobs.Jobs).filter(jobs.Jobs.id == request.json['id'])
        old_job.team_leader = job.team_leader
        old_job.jod = job.jod
        old_job.work_size = job.work_size
        old_job.collaborators = job.collaborators
        old_job.hazard_category = job.hazard_category
        old_job.is_finished = job.is_finished
        old_job.add_by = job.add_by
        session.commit()
    else:
        session.add(job)
        session.commit()
    return jsonify({'success': 'OK'})
Exemplo n.º 2
0
def new_job():
    form = NewJobForm()
    if form.validate_on_submit():
        session = db_session.create_session()
        if session.query(users.User).filter(
                users.User.id == form.team_leader.data).first() is None:
            return render_template(
                'new_job.html',
                form=form,
                message="Тимлидера с таким id не существует")
        for col_id in [
                int(i) for i in form.collaborators.data.split(', ')
                if i.isdigit()
        ]:
            if session.query(users.User).filter(
                    users.User.id == col_id).first() is None:
                return render_template(
                    'new_job.html',
                    form=form,
                    message="Одного из членов команды с таким id не существует"
                )
        job = jobs.Jobs(team_leader=form.team_leader.data,
                        job=form.job.data,
                        work_size=form.work_size.data,
                        collaborators=form.collaborators.data,
                        is_finished=form.is_finished.data)
        session.add(job)
        session.commit()
        return redirect('/')
    return render_template('new_job.html', form=form, message='')
Exemplo n.º 3
0
def add_job():
    form = JobForm()
    if form.validate_on_submit():
        session = db_session.create_session()
        job = jobs.Jobs(team_leader=form.team_leader.data,
                        job=form.job.data,
                        work_size=form.work_size.data,
                        collaborators=form.collaborators.data,
                        is_finished=form.is_finished.data)
        session.add(job)
        session.commit()
        return redirect('/')
    return render_template('add_job.html', title='Добавить работу', form=form)
Exemplo n.º 4
0
def create_job():
    ses = db_session.create_session()
    if not request.json:
        return jsonify({'error': 'Empty request'})
    elif not all(key in request.json for key in ['team_leader', 'job', 'work_size', 'collaborators',
                                                 'category' 'start_date', 'end_date', 'is_finished']):
        return jsonify({'error': 'Bad request'})
    elif ses.query(jobs.Jobs).get(request.json.get('id', -1)):
        return jsonify({'error': 'Id already exists'})
    job = jobs.Jobs(**request.json)
    ses.add(job)
    ses.commit()
    return jsonify({'success': 'OK'})
Exemplo n.º 5
0
def main():
    db_session.global_init("db/blogs.sqlite")

    session = db_session.create_session()
    job = jobs.Jobs()
    job.team_leader = 1
    job.job  = 'deployment of residential modules 1 and 2'
    job.work_size  = 15
    job.collaborators  = '2, 3'
    job.start_date  = datetime.datetime.now()
    job.is_finished  = False
    session.add(job)
    session.commit()
    app.run()
Exemplo n.º 6
0
def add_jobs():
    form = add_job.JobForm()
    if form.validate_on_submit():
        session = db_session.create_session()
        job = jobs.Jobs()
        job.title = 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
        session.commit()
        return redirect('/jobs')
    return render_template('add_job.html',
                           title='Добавление работы',
                           form=form)
Exemplo n.º 7
0
def add_dep():
    form = DepForm()
    if form.validate_on_submit():
        session = db_session.create_session()
        job = jobs.Jobs(
            title=form.title.data,
            chief=form.chief.data,
            members=form.members.data,
            email=form.email.data
        )
        if current_user.__name__ is not None:
            job.add_by = current_user.id
        session.add(job)
        session.commit()
        return redirect('/')
    return render_template('add_department.html', form=form)
Exemplo n.º 8
0
def add_job():
    form = JobsForm()
    if form.validate_on_submit():
        sessions = db_session.create_session()
        job = jobs.Jobs(team_leader=form.team_leader.data,
                        job=form.job.data,
                        work_size=form.work_size.data,
                        collabarators=form.collabarators.data,
                        is_finished=form.is_finished.data)
        # user.set_password(form.password.data)
        sessions.add(job)
        sessions.commit()
        return redirect("/")
    return render_template('add_job.html',
                           title='add_job',
                           form=form,
                           message="")
Exemplo n.º 9
0
def add_job():
    form = JobForm()
    if form.validate_on_submit():
        session = db_session.create_session()
        job = jobs.Jobs(
            team_leader=form.team_leader.data,
            jod=form.jod.data,
            work_size=form.work_size.data,
            collaborators=form.collaborators.data,
            is_finished=form.is_finished.data,
        )
        if current_user.__name__ is not None:
            job.add_by = current_user.id
        session.add(job)
        session.commit()
        return redirect('/')
    return render_template('add_job.html', form=form)
Exemplo n.º 10
0
 def post(self):
     parser = reqparse.RequestParser()
     parser.add_argument('team_leader', required=True, type=int)
     parser.add_argument('jod', required=True)
     parser.add_argument('work_size', required=True, type=int)
     parser.add_argument('collaborators', required=True)
     parser.add_argument('start_date', required=True)
     parser.add_argument('end_date', required=True)
     parser.add_argument('hazard_category', required=True, type=int)
     parser.add_argument('is_finished', required=True, type=bool)
     args = parser.parse_args()
     session = db_session.create_session()
     job = jobs.Jobs(team_leader=args['team_leader'],
                     jod=args['jod'],
                     work_size=args['work_size'],
                     collaborators=args['collaborators'],
                     start_date=args['start_date'],
                     end_date=args['end_date'],
                     hazard_category=args['hazard_category'],
                     is_finished=args['is_finished'])
     session.add(job)
     session.commit()
     return jsonify({'success': 'OK'})