Exemple #1
0
    def post(cls, slug):
        """Update article title field."""
        new_title = request.get_json()["title"]
        article = ArticleModel.find_by_slug(slug)
        if not article:
            return {"message": "Article not found"}, 404
        if new_title == article.title:
            return {"message": "You're trying to change to existing title"}
        if ArticleModel.find_by_title(new_title):
            return {"message": "This title is taken"}

        article.title = new_title
        article.save_to_db()
        return {"message": "Title has been changed"}, 200
Exemple #2
0
    def post(cls):
        """
        Create new article.

        Article published_date field is not set which means is not available
        publicly.
        """
        article_json = request.get_json()
        article_data = article_schema.load(article_json)

        if ArticleModel.find_by_title(article_data.title):
            return {"message": "Article with given title already exists"}

        article_data.save_to_db()
        return article_schema.dump(article_data), 201