示例#1
0
    def put(self, id):
        id = TodoModel.is_valid_id(id)
        data = Todo.parser.parse_args()

        if id == False:
            return {'message': 'invalid id'}, 400

        todo = TodoModel.find_by_id(id)

        current_user = current_identity

        if not todo:
            todo = TodoModel(id, current_user.username, data['text'], False)
            todo.save_to_db()
            return {'message': 'Saved a new todo'}, 201

        if not todo.check_autherized(current_user.username):
            return {'message': 'not authorized to modify this todo'}, 401

        todo.text = data.text
        todo.done = data.done

        todo.save_to_db()

        return {'message': 'updated'}
示例#2
0
 def post(self, id):
     user = current_identity
     data = Todo.parser.parse_args()
     todo = {'username': user.username, 'text': data['text'], 'done': False}
     todo = TodoModel(None, user.username, data['text'], False)
     todo.save_to_db()
     return {'message': 'todo has been created'}, 201
示例#3
0
    def put(self, title):
        data = Todo.parser.parse_args()
        todo = TodoModel.find_by_title(title)

        if todo is None:
            todo = TodoModel(title, **data)
        else:
            todo.content = data['content']
        todo.save_to_db()
        return todo.json()
示例#4
0
    def post(self):
        data = self.parser.parse_args()
        todo = TodoModel(**data)

        try:
            todo.save_to_db()
        except Exception as exception:
            print(exception)
            return {'message': 'An error occured inserting the item.'}, 500

        return todo.json(), 201
示例#5
0
    def post(self, title):
        if TodoModel.find_by_title(title):
            return {
                'message': "the todo '{}' already exists".format(title)
            }, 400

        data = Todo.parser.parse_args()

        todo = TodoModel(title, data['content'])

        try:
            todo.save_to_db()
        except:
            return {"message": "An error occurred inserting the todo."}, 500

        return todo.json(), 201
示例#6
0
    def put(self, title):

        data = Todo.parser.parse_args()
        todo = TodoModel.find_by_title(title)

        if todo is None:
            todo = TodoModel(title, data['description'], data['description'])
        else:
            todo.description = data['description']
            todo.category_id = data['category']

        try:
            todo.save_to_db()
        except:
            return {'message': 'Error updating todo'}, 500

        return todo.json()
示例#7
0
    def post(self, title):

        if TodoModel.find_by_title(title):
            return {
                "message":
                "A todo with the title of '{}' already exists.".format(title)
            }

        data = Todo.parser.parse_args()
        todo = TodoModel(title, data['description'], data['category'])

        try:
            todo.save_to_db()
        except:
            return {'message': 'Error saving todo'}, 500

        return todo.json(), 201
示例#8
0
    def post(self):
        data = Todos.parser.parse_args()
        todo = TodoModel(desc=data['desc'],
                         done='false',
                         project_id=data['project_id'],
                         user_id=data['user_id'])

        if (ProjectModel.find_by_id(todo.project_id)):
            if (UserModel.find_by_id(todo.user_id)):
                try:
                    todo.save_to_db()
                    return todo.json(), 201
                except:
                    return {
                        "message": "An error occurred inserting the todo."
                    }, 500
            else:
                return {"message": "The associated user does not exist."}, 500
        else:
            return {"message": "The associated project does not exist."}, 500
示例#9
0
    def test_todoのインスタンスが作成されること(self):
        todo = TodoModel('task1', 'walking')

        self.assertEqual(todo.title, 'task1')
        self.assertEqual(todo.content, 'walking')
示例#10
0
 def test_todoの情報がjsonで返却される(self):
     todo = TodoModel('task1', 'waking')
     expected = {'title': 'task1', 'content': 'waking'}
     self.assertEqual(todo.json(), expected)