本文整理汇总了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