本文整理汇总了Python中appliances.models.Provider.get_available_provider_keys方法的典型用法代码示例。如果您正苦于以下问题:Python Provider.get_available_provider_keys方法的具体用法?Python Provider.get_available_provider_keys怎么用?Python Provider.get_available_provider_keys使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类appliances.models.Provider
的用法示例。
在下文中一共展示了Provider.get_available_provider_keys方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: vms
# 需要导入模块: from appliances.models import Provider [as 别名]
# 或者: from appliances.models.Provider import get_available_provider_keys [as 别名]
def vms(request, current_provider=None):
if not request.user.is_authenticated():
return go_home(request)
provider_keys = sorted(Provider.get_available_provider_keys())
providers = []
for provider_key in provider_keys:
try:
provider = Provider.objects.get(id=provider_key)
except ObjectDoesNotExist:
providers.append((provider_key, True))
else:
providers.append((provider_key, provider.is_working))
if current_provider is None and providers:
return redirect("vms_at_provider", current_provider=provider_keys[0])
return render(request, 'appliances/vms/index.html', locals())
示例2: vms
# 需要导入模块: from appliances.models import Provider [as 别名]
# 或者: from appliances.models.Provider import get_available_provider_keys [as 别名]
def vms(request, current_provider=None):
if not request.user.is_authenticated() or not request.user.is_superuser:
return go_home(request)
all_provider_keys = sorted(Provider.get_available_provider_keys())
providers = []
provider_keys = []
if request.user.is_staff or request.user.is_superuser:
user_filter = {}
else:
user_filter = {'user_groups__in': request.user.groups.all()}
for provider_key in all_provider_keys:
try:
provider = Provider.objects.filter(id=provider_key, **user_filter).distinct().first()
except ObjectDoesNotExist:
continue
if provider is not None:
providers.append((provider_key, provider.is_working))
provider_keys.append(provider_key)
if current_provider is None and providers:
return redirect("vms_at_provider", current_provider=provider_keys[0])
return render(request, 'appliances/vms/index.html', locals())