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 post(self): arg = parser_jobs.parse_args() session = db_session.create_session() jobs = Jobs(team_leader=arg['team_leader'], job=arg['job'], work_size=arg['work_size'], collaborators=arg['collaborators'], start_date=arg['start_date'], end_date=arg['end_date'], is_finished=arg['is_finished'])
def post(self): args = parser.parse_args() session = db_session.create_session() job = Jobs(leader_id=args['leader_id'], job=args['job'], work_size=args['work_size'], collaborators=args['collaborators'], is_finished=args['is_finished']) session.add(job) session.commit() return jsonify({'success': 'OK'})
def addjob(): db_session.global_init('db/mars_explorer.db') form = AddJobForm() if form.validate_on_submit(): session = db_session.create_session() job = Jobs(team_leader=form.team_lead.data, job=form.job.data, work_size=form.size.data, collaborators=form.collaborators.data, start_date=form.start.data, end_date=form.stop.data, is_finished=form.finish.data) current_user.jobs.append(job) session.merge(current_user) session.commit() return redirect('/') return render_template('AddJob.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()
def create_job(): if not request.json: return jsonify({'error': 'Empty request'}) elif not all(key in request.json for key in [ 'id', 'leader_id', 'job', 'work_size', 'collaborators', 'is_finished' ]): return jsonify({'error': 'Bad request'}) session = db_session.create_session() if session.query(Jobs).get(request.json['id']): return jsonify({'error': 'Id already exists'}) job = Jobs(id=request.json['id'], leader_id=request.json['leader_id'], job=request.json['job'], work_size=request.json['work_size'], collaborators=request.json['collaborators'], is_finished=request.json['is_finished']) session.add(job) session.commit() return jsonify({'success': 'OK'})
def post(self): args = parser_add_job.parse_args() abort_if_user_not_found(args['team_leader']) start_date = datetime.datetime.now() end_date = datetime.datetime.now() + datetime.timedelta( hours=args['work_size']) session = db_session.create_session() job = Jobs(job=args['job'], team_leader=args['team_leader'], work_size=args['work_size'], collaborators=args['collaborators'], start_date=start_date, end_date=end_date, is_finished=args['is_finished'], creator=args['team_leader']) session.add(job) session.commit() return jsonify({'success': 'OK'})
def create_news(): if not request.json: return jsonify({'error': 'Empty request'}) elif not all(key in request.json for key in ['job', 'team_leader', 'work_size', 'collaborators', 'id', 'is_finished']): return jsonify({'error': 'Bad request'}) elif (not str(request.json['id']).isdigit() or not str(request.json['team_leader']).isdigit() or not str(request.json['work_size']).isdigit() or not isinstance(request.json['is_finished'], bool)): return jsonify({'error': 'Wrong data'}) session = db_session.create_session() if not session.query(User).filter(User.id == int(request.json['team_leader'])).first(): return jsonify({'error': 'Wrong data'}) elif session.query(Jobs).filter(Jobs.id == int(request.json['id'])).first(): return jsonify({'error': 'Id already exists'}) creator = request.json['team_leader'] start_date = datetime.datetime.now() end_date = datetime.datetime.now() + datetime.timedelta( hours=int(request.json['work_size'])) jobs = Jobs( id=request.json['id'], job=request.json['job'], creator=creator, team_leader=request.json['team_leader'], work_size=request.json['work_size'], collaborators=request.json['collaborators'], is_finished=request.json['is_finished'], start_date=start_date, end_date=end_date ) session.add(jobs) session.commit() return jsonify({'success': 'OK'})
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)
jobs = all_db['db']['jobs'] for user in users: if not session.query(User).get(user['id']): user_db = User(surname=user['surname'], name=user['name'], age=user['age'], position=user['position'], speciality=user['speciality'], address=user['address'], email=user['email'], hashed_password=user['hashed_password'], id=user['id'], modified_date=pars_str_to_date(user['modified_date'])) session.add(user_db) for job in jobs: if not session.query(Jobs).get(job['id']): job_db = Jobs(job=job['job'], team_leader=job['team_leader'], work_size=job['work_size'], collaborators=job['collaborators'], start_date=pars_str_to_date(job['start_date']), end_date=pars_str_to_date(job['end_date']), is_finished=job['is_finished'], creator=job['creator'], id=job['id']) session.add(job_db) session.commit()
def main(): db_session.global_init("db/blogs.db") user = User() user.surname = "Scott" user.name = "Ridley" user.age = 21 user.position = "captain" user.speciality = "research engineer" user.address = "module_1" user.email = "*****@*****.**" db_sess = db_session.create_session() db_sess.add(user) db_sess.commit() user = User() user.surname = "Рей" user.name = "Ридл" user.age = 21 user.position = "sequreti" user.speciality = "robots engineer" user.address = "module_2" user.email = "Рей_Ридл@mars.org" db_sess.add(user) db_sess.commit() user = User() user.surname = "Merser" user.name = "Alex" user.age = 21 user.position = "arheolog" user.speciality = "engineer" user.address = "module_3" user.email = "*****@*****.**" db_sess.add(user) db_sess.commit() user = User() user.surname = "Jk" user.name = "Htirlec" user.age = 21 user.position = "pilot" user.speciality = "Pilot" user.address = "module_4" user.email = "*****@*****.**" db_sess.add(user) db_sess.commit() app.run() news = Jobs(job="deployment of residential modules 1 and 2", collaborators="2, 3", is_finished=True, work_size=15, user=user) db_sess.add(news) db_sess.commit() job = db_sess.query(Jobs).filter(Jobs.id == 1).first() job.finished_date = datetime.datetime.now() + datetime.timedelta(hours=15) user = db_sess.query(User).filter(User.id == 2).first() news = Jobs(job="explorant of mineral resurse", collaborators="3, 4", is_finished=False, work_size=14, user=user) db_sess.add(news) db_sess.commit() job = db_sess.query(Jobs).filter(Jobs.id == 2).first() job.finished_date = datetime.datetime.now() + datetime.timedelta(hours=14) user = db_sess.query(User).filter(User.id == 3).first() news = Jobs(job="deployment of manager system", collaborators="2, 4", is_finished=False, work_size=48, user=user) db_sess.add(news) db_sess.commit() job = db_sess.query(Jobs).filter(Jobs.id == 3).first() job.finished_date = datetime.datetime.now() + datetime.timedelta(hours=48) db_sess = db_session.create_session() app.run()