Example #1
0
    def post(self):
        data = self.arguments.parse_args()
        author = AuthorModel(**data)
        author_find = author.find(author.firstname)

        if author_find:
            #return {"mensage": "Book id '{}' already exists.".format(data.title)}, 200
            return author_find.json(), 409
        else:
            try:
                author.save()
            except:
                return {
                    'mensage':
                    'An internal error ocurred trying to save author.'
                }, 500
            return author.json()
Example #2
0
    def put(self, id_author):

        data = Author.arguments.parse_args()
        data = AuthorModel(id_author, **data)

        find_author = AuthorModel.find(id_author)

        if find_author:
            find_author.update(**data)
            find_author.save()
            return find_author.json(), 200  #ok

        new_author = AuthorModel(id_author, **data)

        try:
            new_author.save()
        except:
            return {
                'mensage': 'An internal error ocurred trying to save author.'
            }, 500
        return find_author.json()