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)
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)
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()})
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()