当前位置: 首页>>代码示例>>Python>>正文


Python Zone.get_headless_zones方法代码示例

本文整理汇总了Python中securesync.models.Zone.get_headless_zones方法的典型用法代码示例。如果您正苦于以下问题:Python Zone.get_headless_zones方法的具体用法?Python Zone.get_headless_zones怎么用?Python Zone.get_headless_zones使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在securesync.models.Zone的用法示例。


在下文中一共展示了Zone.get_headless_zones方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_or_create_headless_organization

# 需要导入模块: from securesync.models import Zone [as 别名]
# 或者: from securesync.models.Zone import get_headless_zones [as 别名]
    def get_or_create_headless_organization(cls, refresh_zones=False):
        """
        Retrieve the organization encapsulating all headless zones.
        """
        if cls.HEADLESS_ORG_PK is not None:
            # Already exists and cached, just query fast and return
            headless_org = cls.objects.get(pk=cls.HEADLESS_ORG_PK)

        else:
            # Potentially inefficient query, so limit this to once per server thread
            # by caching the results.  Here, we've had a cache miss
            headless_orgs = cls.objects.filter(name=cls.HEADLESS_ORG_NAME)
            if not headless_orgs:
                # Cache miss because the org actually doesn't exist.  Create it!
                headless_org = Organization(name=cls.HEADLESS_ORG_NAME)
                headless_org.save(**({cls.HEADLESS_ORG_SAVE_FLAG: True}))
                cls.HEADLESS_ORG_PK = headless_org.pk

            else:
                # Cache miss because it's the first relevant query since this thread started.
                assert len(headless_orgs) == 1, "Cannot have multiple HEADLESS ZONE organizations"
                cls.HEADLESS_ORG_PK = headless_orgs[0].pk
                headless_org = headless_orgs[0]

        # TODO(bcipolli): remove this code!
        #
        # In the future, when we self-register headless zones, we'll
        #    add them directly to the headless organization.
        #    For now, we'll have to do an exhaustive search.
        if refresh_zones:
            headless_org.zones.add(*Zone.get_headless_zones())

        return headless_org
开发者ID:2flcastro,项目名称:ka-lite-central,代码行数:35,代码来源:models.py


注:本文中的securesync.models.Zone.get_headless_zones方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。