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


Python models.Provider类代码示例

本文整理汇总了Python中appliances.models.Provider的典型用法代码示例。如果您正苦于以下问题:Python Provider类的具体用法?Python Provider怎么用?Python Provider使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: add_provider

def add_provider(user, provider_key):
    if not user.is_staff:
        raise Exception("You don't have enough rights!")
    try:
        provider_o = Provider.objects.get(id=provider_key)
        return False
    except ObjectDoesNotExist:
        provider_o = Provider(id=provider_key)
        provider_o.save()
        return True
开发者ID:pombredanne,项目名称:cfme_tests,代码行数:10,代码来源:api.py

示例2: vms

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())
开发者ID:jaryn,项目名称:cfme_tests,代码行数:15,代码来源:views.py

示例3: providers

def providers(request, provider_id=None):
    if provider_id is None:
        try:
            return redirect(
                "specific_provider", provider_id=Provider.objects.order_by("id")[0].id)
        except IndexError:
            # No Provider
            messages.info(request, "No provider present, redirected to the homepage.")
            return go_home(request)
    else:
        try:
            provider = Provider.objects.get(id=provider_id)
        except ObjectDoesNotExist:
            messages.warning(request, "Provider '{}' does not exist.".format(provider_id))
            return redirect("providers")
    providers = Provider.objects.order_by("id")
    complete_usage = Provider.complete_user_usage()
    return render(request, 'appliances/providers.html', locals())
开发者ID:amavinag,项目名称:cfme_tests,代码行数:18,代码来源:views.py

示例4: vms

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())
开发者ID:rananda,项目名称:cfme_tests,代码行数:21,代码来源:views.py

示例5: provider_usage

def provider_usage(request):
    complete_usage = Provider.complete_user_usage(request.user)
    return render(request, 'appliances/provider_usage.html', locals())
开发者ID:rananda,项目名称:cfme_tests,代码行数:3,代码来源:views.py

示例6: providers

def providers(request):
    providers = Provider.objects.order_by("id")
    complete_usage = Provider.complete_user_usage()
    return render(request, 'appliances/providers.html', locals())
开发者ID:jaryn,项目名称:cfme_tests,代码行数:4,代码来源:views.py

示例7: my_appliances

def my_appliances(request, show_user="my"):
    if not request.user.is_superuser:
        if not (show_user == "my" or show_user == request.user.username):
            messages.info(request, "You can't view others' appliances!")
            return redirect("my_appliances")
        if show_user == request.user.username:
            return redirect("my_appliances")
    else:
        other_users = User.objects.exclude(pk=request.user.pk).order_by("last_name", "first_name")
    if show_user == "my":
        pools = AppliancePool.objects.filter(owner=request.user).order_by("id")
    elif show_user == "all":
        pools = AppliancePool.objects.order_by("id")
    else:
        pools = AppliancePool.objects.filter(owner__username=show_user).order_by("id")
    pools = pools.select_related('group', 'provider', 'owner')
    page = request.GET.get("page")
    try:
        per_page = int(request.GET.get("per_page", 5))
    except (ValueError, TypeError):
        per_page = 5

    pools_paginator = Paginator(pools, per_page)
    try:
        pools_paged = pools_paginator.page(page)
        page = int(page)
    except PageNotAnInteger:
        # If page is not an integer, deliver first page.
        pools_paged = pools_paginator.page(1)
        page = 1
    except EmptyPage:
        # If page is out of range (e.g. 9999), deliver last page of results.
        pools_paged = pools_paginator.page(pools_paginator.num_pages)
        page = pools_paginator.num_pages

    pages = list(pools_paginator.page_range)
    if pools_paginator.num_pages <= 5:
        start_index = 0
        end_index = 5
    else:
        if page - 2 < 0:
            start_index = 0
            end_index = 5
        elif page + 2 > pools_paginator.num_pages:
            end_index = pools_paginator.num_pages
            start_index = end_index - 5
        else:
            start_index = page - 3
            end_index = page + 2
    if start_index < 0:
        end_index -= start_index
        start_index = 0
    pages = pages[start_index:end_index]
    available_groups = Group.objects.filter(
        id__in=Template.objects.values_list('template_group', flat=True).distinct())
    group_tuples = []
    for grp in available_groups:
        group_tuples.append((grp.templates.order_by('-date')[0].date, grp))
    group_tuples.sort(key=lambda gt: gt[0], reverse=True)
    template_types = [t for t in Template.TEMPLATE_TYPES]
    can_order_pool = show_user == "my"
    new_pool_possible = True
    display_legend = False
    for pool in pools:
        if not pool.finished:
            display_legend = True
    per_pool_quota = None
    pools_remaining = None
    num_user_vms = Appliance.objects.filter(appliance_pool__owner=request.user).count()
    if request.user.has_quotas:
        if request.user.quotas.total_pool_quota is not None:
            if request.user.quotas.total_pool_quota <= len(pools):
                new_pool_possible = False
            pools_remaining = request.user.quotas.total_pool_quota - len(pools)
        if request.user.quotas.total_vm_quota is not None:
            if request.user.quotas.total_vm_quota <= num_user_vms:
                new_pool_possible = False
        if request.user.quotas.per_pool_quota is not None:
            per_pool_quota = request.user.quotas.per_pool_quota
            remaining_vms = request.user.quotas.total_vm_quota - num_user_vms
            if remaining_vms < per_pool_quota:
                per_pool_quota = remaining_vms
    per_pool_quota_enabled = per_pool_quota is not None
    can_change_hw = request.user.has_perm('appliances.can_modify_hw')
    provider_types = Provider.get_available_provider_types(request.user)
    return render(request, 'appliances/my_appliances.html', locals())
开发者ID:lcouzens,项目名称:cfme_tests,代码行数:86,代码来源:views.py

示例8: available_provider_types

def available_provider_types(user):
    """Return a list of provider types usable for provisioning."""
    return Provider.get_available_provider_types(user)
开发者ID:akarol,项目名称:cfme_tests,代码行数:3,代码来源:api.py

示例9: provider_usage

def provider_usage(request):
    complete_usage = Provider.complete_user_usage(request.user)
    total_usage = sum(count for pair in complete_usage for count in [int(pair[1])])
    return render(request, 'appliances/provider_usage.html', locals())
开发者ID:apagac,项目名称:cfme_tests,代码行数:4,代码来源:views.py


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