Flask管理员角色将role_accapted添加到add_view

时间:2018-09-23 17:23:25

标签: flask-admin flask-mongoengine

我已经设法让角色使用此代码,但是!

class Roled(object):
def is_accessible(self):
    roles_accepted = getattr(self, 'roles_accepted', None)
    if flask_login.current_user.is_authenticated:
        user = CustomUser.objects.get(email=flask_login.current_user.id)
        for role in user.roles:
            for permission in role.permissions:
                if permission == "admin":
                    return flask_login.current_user.is_authenticated
def inaccessible_callback(self, name, **kwargs):
    # redirect to login page if user doesn't have access
    return redirect(url_for('login', next=request.url))

class AdminView(Roled, ModelView):
def __init__(self, *args, **kwargs):
    self.roles_accepted = kwargs.pop('roles_accepted', list())
    super(AdminView, self).__init__(*args, **kwargs)

类TranslationView(AdminView):

column_filters = ['eng']
column_searchable_list = ('eng','geo', 'name')

现在,在添加烧瓶管理视图时(如在此question中一样,我在向每个add_view添加role_accapt时遇到问题

1 个答案:

答案 0 :(得分:1)

您的TranslationView应该继承自AdminView类。即

class TranslationView(AdminView):
        column_filters = ['eng']
        column_searchable_list = ('eng','geo', 'name')