Exemple #1
0
 def validate(self):
     if not super().validate():
         return False
     session = db_session.create_session()
     if not session.query(User).filter(
             User.id == self.chief_id.data).first():
         self.chief_id.errors.append("Такого пользователя не существует")
         session.close()
         return False
     if not self.members.data:
         session.close()
         return True
     for member in self.members.data.split(", "):
         try:
             if not session.query(User).filter(
                     User.id == int(member)).first():
                 self.members.errors.append(
                     f"Пользователя с id {member} не существует")
                 session.close()
                 return False
         except ValueError:
             self.members.errors.append(
                 f"Пользователя с id {member} не существует")
             session.close()
             return False
     session.close()
     return True
Exemple #2
0
 def validate(self):
     if not super().validate():
         return False
     session = db_session.create_session()
     if not session.query(User).filter(
             User.id == self.team_leader.data).first():
         self.team_leader.errors.append("Такого пользователя не существует")
         session.close()
         return False
     if not self.collaborators.data:
         session.close()
         return True
     for collaborator in self.collaborators.data.split(", "):
         try:
             if not session.query(User).filter(
                     User.id == int(collaborator)).first():
                 self.collaborators.errors.append(
                     f"Пользователя с id {collaborator} не существует")
                 session.close()
                 return False
         except ValueError:
             self.collaborators.errors.append(
                 f"Пользователя с id {collaborator} не существует")
             session.close()
             return False
     session.close()
     return True
def delete_jobs(jobs_id):
    db_sess = db_session.create_session()
    jobs = db_sess.query(Jobs).get(jobs_id)
    if not jobs:
        return jsonify({'error': 'Not found'})
    db_sess.delete(jobs)
    db_sess.commit()
    return jsonify({'success': 'OK'})
def get_jobs():
    db_sess = db_session.create_session()
    jobs = db_sess.query(Jobs).all()
    return jsonify({
        'jobs': [
            item.to_dict(only=('id', 'team_leader', 'job', 'work_size',
                               'collaborators')) for item in jobs
        ]
    })
def get_job(job_id):
    db_sess = db_session.create_session()
    jobs = db_sess.query(Jobs).get(job_id)
    if not jobs:
        return jsonify({'error': 'Not found'})
    return jsonify({
        'jobs':
        jobs.to_dict(only=('team_leader', 'job', 'id', 'work_size',
                           'collaborators', 'start_date', 'end_date',
                           'is_finished'))
    })
Exemple #6
0
 def validate(self):
     if not super().validate():
         return False
     session = db_session.create_session()
     user = session.query(User).filter_by(email=self.email.data).first()
     if user:
         self.email.errors.append('Пользователь с такой почтой существует')
         session.close()
         return False
     if self.password.data != self.password_again.data:
         self.password_again.errors.append('Пароли не совпадают')
         session.close()
         return False
     session.close()
     return True
Exemple #7
0
 def validate(self):
     if not super().validate():
         return False
     session = db_session.create_session()
     user = session.query(User).filter_by(email=self.email.data).first()
     if not user:
         self.email.errors.append('Такого пользователя не существует')
         session.close()
         return False
     if not user.check_password(self.password.data):
         self.password.errors.append('Неверный пароль')
         session.close()
         return False
     session.close()
     return True
def change_jobs(jobs_id):
    if not request.json:
        return jsonify({'error': 'Empty request'})
    db_sess = db_session.create_session()
    jobs = db_sess.query(Jobs).filter(Jobs.id == jobs_id).first()
    if not jobs:
        return jsonify({'error': 'Not found'})

    correct_keys = [
        'team_leader', 'job', 'id', 'work_size', 'collaborators', 'is_finished'
    ]
    for key in request.json.keys():
        if key in correct_keys:
            exec(f'jobs.{key} = request.json["{key}"]')
        else:
            return jsonify({'error': f'Key {key} is not exists'})

    db_sess.commit()
    return jsonify({'success': 'OK'})
def create_jobs():
    if not request.json:
        return jsonify({'error': 'Empty request'})
    elif not all(key in request.json for key in [
            'team_leader', 'job', 'id', 'work_size', 'collaborators',
            'is_finished'
    ]):
        return jsonify({'error': 'Bad request'})
    elif any(request.json['id'] == item['id']
             for item in get('http://localhost:5000/api/jobs').json()['jobs']):
        return jsonify({'error': 'Id already exists'})
    db_sess = db_session.create_session()
    jobs = Jobs(id=request.json['id'],
                team_leader=request.json['team_leader'],
                job=request.json['job'],
                work_size=request.json['work_size'],
                collaborators=request.json['collaborators'],
                is_finished=request.json['is_finished'])
    db_sess.add(jobs)
    db_sess.commit()
    return jsonify({'success': 'OK'})