def get_banner(id): banner = Banner.get_banner_by_id(id=id) return jsonify(banner)
def get_banner(id): '''获取「首页轮播图」''' id = IDMustBePositiveInt().validate_for_api().id.data banner = Banner.get_banner_by_id(id=id) # banner.hide('description') # 临时隐藏 return Success(banner)
def delete(bid): Banner.remove_model(bid, throw=True) return Success(msg='横幅删除成功')
def get_one(id): '''获取「首页轮播图」''' banner = Banner.get_banner_by_id(id=id) # banner.hide('description') # 可以隐藏某个字段 return Success(banner)
def hide(bid): Banner.hide_model(bid, throw=True) return Success(msg='横幅隐藏成功')
def show(bid): Banner.show_model(bid, throw=True) return Success(msg='横幅显示成功')
def create(): form = BannerContent().validate_for_api() Banner.add_model(form.data, throw=True) return Success(msg='添加横幅成功')
def update(bid): form = BannerContent().validate_for_api() Banner.edit_model(bid, form.data, throw=True) return Success(msg='修改横幅成功')
def get_all(): models = Banner.get_all_models(throw=True) for model in models: model._fields = ['id', 'name'] return jsonify(models)
def get_paginate(): start, count = paginate() q = request.args.get('q', None) res = Banner.get_paginate_models(start, count, q, soft=False, throw=True) return jsonify(res)
def get(bid): model = Banner.get_model(bid, throw=True) return jsonify(model)
def delete_banner(bid): """删除id=bid的轮播图""" Banner.remove_banner(bid) return Success()
def update_banner(bid): """更新id=bid轮播图的信息""" form = UpdateBannerForm().validate_for_api() Banner.update_banner(bid, form.data) return Success()
def create_banner(): """创建一个轮播图""" form = CreateBannerForm().validate_for_api() Banner.create_banner(form.data) return Success()
def get_banner(id): id = IDMustBePositiveInt().validate_for_api().id.data banner = Banner.get_banner_by_id(id=id) # banner.hide('description') # 临时隐藏 return Success(banner)