(self, request)
return rv
构建某一公众号下功能列表
构建某一公众号下功能列表
构建某一公众号下功能列表
def _build_wechat_func_dict(self, request):
        """构建某一公众号下功能列表"""
        has_module_perms = get_user_permissions(
            request.user, request.app, exclude_manage=True, exclude_sub=True)
        if not has_module_perms:
            return None

        app_id = request.app_id
        app_label = WeChatApp._meta.app_label
        rv = dict(
            name=str(request.app),
            app_label=app_label,
            app_url=reverse(
                "admin:wechat_funcs_list",
                current_app=self.name,
                kwargs=dict(
                    wechat_app_id=app_id,
                    app_label=app_label
                )
            ),
            has_module_perms=True,
            models=[]
        )

        for model, model_admin in self._iter_wechatadmins():
            info = (model._meta.app_label, model._meta.model_name)
            perms = model_admin.get_model_perms(request)
            if not perms:
                continue
            model_dict = {
                "name": model._meta.verbose_name_plural,
                "object_name": model._meta.object_name,
                "perms": perms,
            }
            if perms.get("change"):
                try:
                    model_dict["admin_url"] = reverse(
                        "admin:%s_%s_changelist" % info,
                        current_app=self.name,
                        kwargs=dict(wechat_app_id=app_id)
                    )
                except NoReverseMatch:
                    pass
            if perms.get("add"):
                try:
                    model_dict['add_url'] = reverse(
                        "admin:%s_%s_add" % info,
                        current_app=self.name,
                        kwargs=dict(wechat_app_id=app_id)
                    )
                except NoReverseMatch:
                    pass
            rv["models"].append(model_dict)

        return rv
def _build_wechat_func_dict ( self , request ) : has_module_perms = get_user_permissions ( request . user , request . app , exclude_manage = True , exclude_sub = True ) if not has_module_perms : return None app_id = request . app_id app_label = WeChatApp . _meta . app_label rv = dict ( name = str ( request . app ) , app_label = app_label , app_url = reverse ( "admin:wechat_funcs_list" , current_app = self . name , kwargs = dict ( wechat_app_id = app_id , app_label = app_label ) ) , has_module_perms = True , models = [ ] ) for model , model_admin in self . _iter_wechatadmins ( ) : info = ( model . _meta . app_label , model . _meta . model_name ) perms = model_admin . get_model_perms ( request ) if not perms : continue model_dict = { "name" : model . _meta . verbose_name_plural , "object_name" : model . _meta . object_name , "perms" : perms , } if perms . get ( "change" ) : try : model_dict [ "admin_url" ] = reverse ( "admin:%s_%s_changelist" % info , current_app = self . name , kwargs = dict ( wechat_app_id = app_id ) ) except NoReverseMatch : pass if perms . get ( "add" ) : try : model_dict [ 'add_url' ] = reverse ( "admin:%s_%s_add" % info , current_app = self . name , kwargs = dict ( wechat_app_id = app_id ) ) except NoReverseMatch : pass rv [ "models" ] . append ( model_dict ) return rv