示例#1
0
    def post(self, team_id):
        current_user = get_jwt_identity()
        data = task_parser.parse_args()
        if TaskModel.find_by_title(data['title']):
            return {
                'message': 'Task {} already exists'.format(data['title'])
            }, 409

        user = UserModel.query.get(current_user)
        new_task = TaskModel(data['title'], data['status'], data["priority"])
        new_task.reporter_id = user.id
        if data['description']:
            new_task.description = data['description']
        if data['assigne_id']:
            new_task.assigne_id = data['assigne_id']
        if data['planneddate']:
            new_task.planneddate = data['planneddate']
        new_task.team_id = team_id

        try:
            new_task.save_to_db()
            resp = jsonify({
                'message':
                'Task {} was created'.format(data['title']),
                'id':
                new_task.id
            })
            resp.status_code = 200
            return resp
        except:
            return {'message': 'Something went wrong'}, 500
示例#2
0
    def post(self, SK8RAT_name):
        # Get raw request and read as json blob
        request_raw = request.data.decode("UTF-8")
        json_blob = json.loads(request_raw)

        # Check SK8RAT by name
        SK8RAT = SK8RATModel.query.filter(
            SK8RATModel.name == SK8RAT_name).first()

        # If name doesn't exist, error; else grab guid
        if (not SK8RAT):
            return {'message': 'SK8RAT does not exist.'}
        guid = SK8RAT.guid

        # Check guid against tasking database
        task = TaskModel.query.filter(TaskModel.guid == guid).first()

        if (task is None):
            # task was not found, create initial
            new_task = TaskModel(guid=guid,
                                 task_id=1,
                                 task=json_blob['task'],
                                 task_status="wait",
                                 task_output="")
        else:
            # task was found, find most recent task_id for this guid, add 1
            task2 = TaskModel.query.filter(TaskModel.guid == guid).order_by(
                TaskModel.task_id.desc()).first()
            new_task = TaskModel(guid=guid,
                                 task_id=task2.task_id + 1,
                                 task=json_blob['task'],
                                 task_status="wait",
                                 task_output="")

        new_task.save_to_db()
        message = "Task " + json_blob['task'] + " with task id " + str(new_task.task_id) +\
                  " assigned to " + SK8RAT.name + "."
        return {'message': message}