easyui/mixins/permission_mixins.py
def dispatch(self, request, *args, **kwargs):
        """
        增加了权限控制，当self存在model和permission_required时，才会检查权限
        """
        if getattr(self, 'model', None) and self.permission_required:
            app_label = self.model._meta.app_label
            model_name = self.model.__name__.lower()
            permission_required = self.permission_required.lower()
            permission = '%(app_label)s.%(permission_required)s_%(model_name)s' % {
                'app_label':app_label,
                'permission_required':permission_required,
                'model_name': model_name
            }
            if not self.request.user.has_perm(permission):
                return HttpResponseRedirect(reverse_lazy('easyui:login'))

        return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs)
def dispatch(self, request, *args, **kwargs):
        """
        增加了权限控制，当self存在model和permission_required时，才会检查权限
        """
        if getattr(self, 'model', None) and self.permission_required:
            app_label = self.model._meta.app_label
            model_name = self.model.__name__.lower()
            permission_required = self.permission_required.lower()
            permission = '%(app_label)s.%(permission_required)s_%(model_name)s' % {
                'app_label':app_label,
                'permission_required':permission_required,
                'model_name': model_name
            }
            if not self.request.user.has_perm(permission):
                return HttpResponseRedirect(reverse_lazy('easyui:login'))

        return super(LoginRequiredMixin, self).dispatch(request, *args, **kwargs)
def dispatch ( self , request , * args , * * kwargs ) : if getattr ( self , 'model' , None ) and self . permission_required : app_label = self . model . _meta . app_label model_name = self . model . __name__ . lower ( ) permission_required = self . permission_required . lower ( ) permission = '%(app_label)s.%(permission_required)s_%(model_name)s' % { 'app_label' : app_label , 'permission_required' : permission_required , 'model_name' : model_name } if not self . request . user . has_perm ( permission ) : return HttpResponseRedirect ( reverse_lazy ( 'easyui:login' ) ) return super ( LoginRequiredMixin , self ) . dispatch ( request , * args , * * kwargs )
增加了权限控制，当self存在model和permission_required时，才会检查权限
增加了权限控制，当self存在model和permission_required时，才会检查权限