示例#1
0
    def post(self):
        data = NewProject.parser.parse_args()
        user_id = get_jwt_identity()
        check_projects = ProjectModel.get_projects_by_user_id(user_id)
        check_projects = [
            pr for pr in check_projects if pr.name == data['name']
        ]
        if check_projects:
            return {
                'message':
                "A project with name '{}' already exists.".format(data['name'])
            }, 400

        # Create a new project
        project = ProjectModel(id=None, **data)
        try:
            project.save_to_db()
        except Exception as e:
            print(e)
            return {"message": "An error occurred inserting the item."}, 500

        # Map the project to the user
        mapping_user = UserProjectMap(user_id=user_id, project_id=project.id)
        try:
            mapping_user.save_to_db()
        except:
            project.delete_from_db()
            return {
                "message": "An error occurred mapping the user to the project."
            }, 500

        return project.json(), 201
示例#2
0
 def put(self, id):
     data = Project.parser.parse_args()
     project = ProjectModel.find_by_id(id)
     if project:
         project.name = data['name']
     else:
         project = ProjectModel(None, **data)
     project.save_to_db()
     return project.json()
示例#3
0
 def put(self, pname):
     data = Project.parser.parse_args()
     project = ProjectModel.find_by_name(pname, int(current_identity))
     if project:
         project.description = data['description']
     else:
         project = ProjectModel(pname, **data)
     project.save_to_db()
     return project.json()
示例#4
0
    def post(self):
        data = ProjectList.parser.parse_args()
        y, m, d = data['to_date'].split('-')
        project = ProjectModel(data['name'], datetime.datetime(int(y), int(m), int(d)))

        try:
            project.save_to_db()
        except:
            return {'message': 'An error occured inserting the project'}, 500

        return project.json(), 201
示例#5
0
    def post(self):
        data = Projects.parser.parse_args()
        project = ProjectModel(name=data['name'], user_id=data['user_id'])

        if (UserModel.find_by_id(project.user_id)):
            try:
                project.save_to_db()
                return project.json(), 201
            except:
                return {
                    "message": "An error occurred inserting the project."
                }, 500
        else:
            return {"message": "The associated user does not exist."}, 500
示例#6
0
 def post(self, pname):
     data = Project.parser.parse_args()
     # TODO: fix this <class 'werkzeug.local.LocalProxy'> to int problem
     project = ProjectModel(pname, data['description'],
                            int(current_identity), data['roles'])
     # print((data['roles']))
     # for rolestr in data['roles']:
     # print(eval(rolestr))
     # save roles
     try:
         project.save_to_db()
     except:
         return {"message": "An error occured inserting the project"}, 500
     return project.json(), 201