之前一直不知道context模块中存储的是什么东西,这回看一下代码;
其中最主要的类是:RequestContext;
class RequestContext(object):
 
"""Helper class to represent useful information about a request context.
 
Stores information about the security context under which the user
accesses the system, as well as additional request information.
"""
 
    user_idt_format = '{user} {tenant} {domain} {user_domain} {p_domain}'
 
    def __init__(self, auth_token=None, user=None, tenant=None, domain=None,
                       user_domain=None, project_domain=None, is_admin=False,
                       read_only=False, show_deleted=False, request_id=None,
                       instance_uuid=None):
        self.auth_token = auth_token
        self.user = user
        self.tenant = tenant
        self.domain = domain
        self.user_domain = user_domain
        self.project_domain = project_domain
        self.is_admin = is_admin
        self.read_only = read_only
        self.show_deleted = show_deleted
        self.instance_uuid = instance_uuid
        if not request_id:
            request_id = generate_request_id()
        self.request_id = request_id
        …...
"""Helper class to represent useful information about a request context.
 
Stores information about the security context under which the user
accesses the system, as well as additional request information.
"""
RequestContext类主要保存了一次web请求的useful context information,主要包括安全验证信息和其他一些信息;
如果用户想要对request的上下文新增一些信息,或加强功能,可以继承这个类;
 
其中两个函数分别获取admin上下文信息,和判断一个context是不是一个normal user:
def get_admin_context(show_deleted=False):
    context = RequestContext(None,
                    tenant=None,
                    is_admin=True,
                    show_deleted=show_deleted)
    return context
 
def is_user_context(context):
"""Indicates if the request context is a normal user."""
    if not context:
        return False
    if context.is_admin:
        return False
    if not context.user_id or not context.project_id:
        return False
    return True
 

最新文章

  1. ((uchar*)(Img1->imageData + Img1->widthStep*pt.y))[pt.x] 的 具体含义
  2. CXF 动态创建客户端调用稳定版本号为2.7.18
  3. js转html实体
  4. 使用Ant打包工具 基本介绍
  5. AUPE学习第八章------进程控制
  6. ASP的高效率的分页算法.net,php同样可以参考
  7. VShell破解版
  8. Unix:关于一个file在file system和disk中占用空间
  9. 优雅地实现CSS Animation delay
  10. Python爬虫之ip代理池
  11. Redisson 分布式锁
  12. CodeBlocks无法调试的解决方法
  13. VSCode插件开发全攻略(六)开发调试技巧
  14. C#设计模式之6:抽象工厂模式
  15. WPS for Linux
  16. django过滤器,日期格式化
  17. PAT L3-010 是否完全二叉搜索树(二叉搜索树)
  18. Python urllib模块学习
  19. PostgreSQL的autovacuum 与 vacuum full
  20. bzoj 4552

热门文章

  1. WCF技术剖析之二:再谈IIS与ASP.NET管道
  2. Linux基础:Grep查询&AWK查询
  3. 学习HTML5之塔克大战(详细记录)
  4. DOI EXCEL显示报表
  5. iOS:控制器间的数据传递
  6. echart饼状图的学习
  7. ES mlockall作用——preventing that memory from being paged to the swap area
  8. spring校验相关
  9. jar转dll
  10. 复利计算4.0单元测试(c语言)