Python flask_admin 模块,BaseView() 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用flask_admin.BaseView()

项目:Canella-CMS    作者:mush42    | 项目源码 | 文件源码
def add_settings_categories():
    categories = current_settings.categories.items()
    for category, info in categories:
        class SettingsAdmin(AuthenticationViewMixin, BaseView):
            settings_category = category
            @expose('/', methods=['Get', 'POST'])
            def index(self):
                form = make_settings_form(category=self.settings_category)
                if form.validate_on_submit():
                    update_settings_from_form(form.data)
                    flash("Settings were successfully saved")
                    return redirect(request.url)
                return self.render('canella/admin/settings.html', form=form)

        admin.add_view(SettingsAdmin(
            name=info['label'],
            menu_icon_type='fa',
            menu_icon_value=info['icon'],
            category=gettext("Settings"),
            endpoint="admin-settings-{}".format(category),
            url="settings/{}".format(category)
        ))