示例#1
0
    def create_new_project(payload):
        projects = []
        result = {
            "success": True,
        }

        try:
            body = json.loads(request.data)

            title = body['title']
            instructions = body['instructions']
            course_id = body['course_id']

            new_project = Project(title=title,
                                  instructions=instructions,
                                  course_id=course_id)
            new_project.insert()

            projects.append(new_project.format())

        except Exception as e:
            print(e)
            abort(500)

        result['projects'] = projects

        return jsonify(result)
示例#2
0
    def create_project(jwt):
        body = request.get_json()

        try:
            name = body.get('name', None)
            category = body.get('category', None)

            reviewers = Project.query.filter(Project.name.like(name)).count()
            print("current", reviewers)
            if reviewers > 0:
                raise AuthError({
                    'code': 'Bad request',
                    'description': "This project is already existent"
                }, 400)
            reviewer = Project(
                name=name, category=category)
            reviewer.insert()
            return jsonify({
                'success': True,
                'projects': [reviewer.format()]
            })
        except Exception as e:
            print("exception error post reviewer", e)
            print(e)
            if isinstance(e, AuthError):
                raise e
            abort(406)
示例#3
0
def post_project(jwt):
    body = request.get_json()
    if (body is None):
        abort(422)
    name = body.get('name')
    client_id = body.get('client_id')
    description = body.get('description')
    if (name is None or client_id is None or description is None):
        abort(422)
    project = Project(name=name, client_id=client_id, description=description)

    try:
        project.insert()
    except Exception:
        abort(422)
    return jsonify({'success': True, 'project': project.format()})
示例#4
0
def post_project(payload):
    try:
        body = request.get_json()
        name = body['name']
        description = body['description']
        email = body['email']
        phone = body['phone']
    except Exception as e:
        print(e)
        abort(400)

    try:
        project = Project(name=name,
                          description=description,
                          email=email,
                          phone=phone)
        db.session.add(project)
        db.session.commit()
        return jsonify({'success': True, 'project': project.format()})
    except Exception as e:
        db.session.rollback()
        abort(422)
    finally:
        db.session.close()