烧瓶躁动的预处理器“ DELETE_RESOURCE”未调用

时间:2018-08-03 05:33:44

标签: flask sqlalchemy preprocessor

嗨,我有Javascript客户端,它可以使以下网址 http://127.0.0.1:2500/api/sdk_prodinfo/abcde,(其中abcde是服务器端表“ sdk_prodinfo”的主键)

我已在python flask应用程序上注册了api,其代码如下所示

manager.create_api(SdkProdinfo, 
app=app,methods=['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],

include_methods=["dns_addresses"],

preprocessors={
                'POST': [SdkProdinfo.pre_create_app],
                'DELETE': [SdkProdinfo.pre_delete_app],
                'PUT': [SdkProdinfo.pre_update_app],
                'PATCH': [SdkProdinfo.pre_update_app]
                },

validation_exceptions=[ValidationError])


def pre_delete_app(instance_id, **kw):


        current_app.logger.debug("{0}.{1}: Validating delete prod app request".format(__name__, inspect.currentframe().f_code.co_name))

        from . import sdk_prod_count
        from . import sdk_prod_purchase

        # Check if the app is live
        prd_cnt = db.session.query(sdk_prod_count.SdkProdCount).get(instance_id)
        if prd_cnt is None:
            abort(make_response(jsonify(message="No matching prod count"), 400))
        if prd_cnt is not None and prd_cnt.go_live == 1:
            abort(make_response(jsonify(message="Deletion not allowed - app is live"), 400))

        # Check if the app has a purchase history
        purchases = db.session.query(sdk_prod_purchase.SdkProdPurchase).filter(sdk_prod_purchase.SdkProdPurchase.production_nmaid == instance_id).all()
        if len(purchases) > 0: # is not None and prd_cnt.go_live == 1:
            abort(make_response(jsonify(message="Deletion not allowed - app has a purchase history"), 400))

        return request.json['prod_nmaid']

但是,当我尝试从UI发出删除请求时,由于某种原因,我的预处理器功能“ SdkProdinfo.pre_delete_app”未被调用。

有人可以帮我吗?

0 个答案:

没有答案