Example #1
0
    def post(self, category_name):

        db.create_all()
        db.session.commit()
        if BrandCategoryModel.find_by_name(category_name):
            return {
                'message':
                "An Record with name '{}' already exists.".format(
                    category_name)
            }, 400

        data = self.parser.parse_args()

        brandcategory = BrandCategoryModel(
            category_name,
            **data,
        )
        brandcategory.created_by = 1
        brandcategory.created_on = datetime.now()
        brandcategory.modified_by = 0
        brandcategory.deleted_by = 0
        try:
            brandcategory.save_to_db()
        except Exception as e:
            return {
                "message":
                "An error occurred while inserting the Record.'{}'".format(e)
            }

        return brandcategory.json(), 201
Example #2
0
    def post(self):
        data = self.parser.parse_args()
        category = BrandCategoryModel(**data)
        category.created_by = 1
        category.created_on = datetime.now()
        category.modified_by = 0
        category.deleted_by = 0
        category.modified_on = None
        category.deleted_on = None

        try:
            validateObj = BrandCategoryModel.validateData(data, request)

            if type(validateObj) is dict:
                return {"success": False, "errors": validateObj}, 400

            if BrandCategoryModel.find_by_name(data['category_name']):
                return {
                    "success": False,
                    "message":
                    "A category with that Record Name already exists"
                }, 400
            name = data['category_name']
            if name.strip():
                category.save_to_db()
                category.token = encodeID(category.category_id)
                category.save_to_db()
            else:
                return {
                    "success": False,
                    "message": "String Should not be empty"
                }
        except Exception as e:
            return {
                "message":
                "An error occurred creating the Record.'{}'".format(e)
            }, 500
        return category.json(), 201