Exemplo n.º 1
0
    def put(self):
        data = Article.parser.parse_args()
        # article = ArticleModel(**data)
        article = ArticleModel.find_by_article_id(data["id"])
        if article is None:
            article = ArticleModel(**data)
        else:
            article.id = data["id"]
            article.title = data["title"]
            article.tag = data["tag"]
            article.sortDescription = data["sortDescription"]
            article.date = data["date"]
            article.key = data["key"]
            article.handleCode = data["handleCode"]
            article.user_id = data["user_id"]

        try:
            article.save_to_db()
        except:
            return {
                "message":
                "Something was wrong when you try to update this article"
            }, 500

        return article.json()
Exemplo n.º 2
0
    def put(self, title):
        data = Article.parser.parse_args()

        article = ArticleModel.find_by_title(title)

        if article:
            article.price = data['price']
        else:
            article = ArticleModel(title, **data)

        article.save_to_db()

        return article.json()
Exemplo n.º 3
0
    def put(self, article_id):
        _article_parser = reqparse.RequestParser(bundle_errors=True)

        _article_parser.add_argument('title',
                                     type=non_empty_string,
                                     required=False,
                                     help="The title field is required!")
        _article_parser.add_argument('slug',
                                     type=non_empty_string,
                                     required=False,
                                     help="The slug field is required!")
        _article_parser.add_argument('image_url',
                                     type=non_empty_string,
                                     required=True,
                                     help="The image_url field is required!")
        _article_parser.add_argument('description',
                                     type=non_empty_string,
                                     required=False,
                                     help="The description field is required!")
        _article_parser.add_argument('category_id',
                                     type=non_empty_string,
                                     required=False,
                                     help="The category field is required!")
        data = _article_parser.parse_args()
        article = ArticleModel.find_by_id(article_id)

        if article is None:
            article = ArticleModel(**data)
        else:
            article.title = data['title'] if data[
                'title'] is not None else article.title
            article.slug = data['slug'] if data[
                'slug'] is not None else article.slug
            article.image_url = data['image_url'] if data[
                'image_url'] is not None else article.image_url
            article.description = data['description'] if data[
                'description'] is not None else article.description
            article.category_id = data['category_id'] if data[
                'category_id'] is not None else article.category_id

        try:
            article.save_to_db()
        except Exception as e:
            return {
                'message': 'An error occurred while creating the article.'
            }, 500

        return article.json(), 201
Exemplo n.º 4
0
    def post(self):
        data = Article.parser.parse_args()
        article = ArticleModel(**data)

        if data["title"] == "":
            return {"message": "error"}, 400

        try:
            article.save_to_db()
        except:
            return {
                "message":
                "Something was wrong when you try to insert this article"
            }, 500

        return {'article': article.json()}, 201
Exemplo n.º 5
0
    def post(self, title):
        if ArticleModel.find_by_title(title):
            return {
                'message':
                "An article with title '{}' already exists.".format(title)
            }, 400

        data = Article.parser.parse_args()

        article = ArticleModel(title, **data)

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

        return article.json(), 201
Exemplo n.º 6
0
    def post(self):
        _article_parser = reqparse.RequestParser(bundle_errors=True)
        _article_parser.add_argument('title',
                                     type=non_empty_string,
                                     required=True,
                                     help="The title field is required!")
        _article_parser.add_argument('slug',
                                     type=non_empty_string,
                                     required=True,
                                     help="The slug field is required!")
        _article_parser.add_argument('image_url',
                                     type=non_empty_string,
                                     required=True,
                                     help="The image_url field is required!")
        _article_parser.add_argument('description',
                                     type=non_empty_string,
                                     required=True,
                                     help="The description field is required!")
        _article_parser.add_argument('category_id',
                                     type=non_empty_string,
                                     required=True,
                                     help="The category field is required!")
        data = _article_parser.parse_args()
        if ArticleModel.find_by_title(data['title']):
            return {
                'message':
                "A article with name {} already exists".format(data['title'])
            }, 400

        article = ArticleModel(**data)
        try:
            article.save_to_db()
        except Exception as e:
            return {
                'message': 'An error occurred while creating the article.'
            }, 500

        return article.json(), 201