當前位置: 首頁>>代碼示例>>Python>>正文


Python Form.fields['params']方法代碼示例

本文整理匯總了Python中django.forms.Form.fields['params']方法的典型用法代碼示例。如果您正苦於以下問題:Python Form.fields['params']方法的具體用法?Python Form.fields['params']怎麽用?Python Form.fields['params']使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.forms.Form的用法示例。


在下文中一共展示了Form.fields['params']方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: monitoring_rating

# 需要導入模塊: from django.forms import Form [as 別名]
# 或者: from django.forms.Form import fields['params'] [as 別名]
def monitoring_rating(request, monitoring_pk):
    """
    Return a response containing the rating table,
    the table settings form, and the parameter selection form.
    """
    monitoring = get_object_or_404(Monitoring, pk=monitoring_pk)
    user = request.user
    if not user.has_perm('exmo2010.view_monitoring', monitoring):
        raise PermissionDenied

    # Process rating_columns_form data to know what columns to show in table
    columns_form = rating_columns_form(request)
    if columns_form.post_ok(request):
        # After form submission redirect to the same page.
        return HttpResponseRedirect(request.path)

    # Process params_form - it will contain chosen params if rating_type is 'user'
    params_form = Form(request.GET)
    params_form.fields['params'] = ModelMultipleChoiceField(
        monitoring.parameter_set.all(), widget=CheckboxSelectMultiple)

    params = params_form.cleaned_data['params'] if params_form.is_valid() else None

    rating_type = request.GET.get('type', 'all')
    rating_list = monitoring.rating(params, rating_type)

    context = {
        'monitoring': monitoring,
        'rating_type': rating_type,
        'params_form': params_form,
        'rating_columns_form': columns_form,
    }

    orgs = set()
    if user.is_active:
        # Include all orgs from all observers groups that current user belongs to.
        obs_groups = user.observersgroup_set.filter(monitoring=monitoring)
        orgs = orgs.union(set(obs_groups.values_list('organizations__pk', flat=True)))

    if user.is_expert or monitoring.is_published:

        queryform = RatingQueryForm(request.GET)

        if queryform.is_valid():
            queryset = queryform.apply(monitoring.organization_set.all())
            orgs = orgs.union(set(queryset.values_list('pk', flat=True)))
            rating_list = [t for t in rating_list if t.organization.pk in orgs]

        approved_tasks = Task.approved_tasks.filter(organization__monitoring=monitoring).distinct()
        rating_stats = dict(_comments_stats(rating_list), **{
            'num_approved_tasks': approved_tasks.count(),
            'num_rated_tasks': len(rating_list),
            'openness': avg('task_openness', rating_list),
            'openness_initial': avg('task_openness_initial', rating_list),
            'openness_delta': avg('openness_delta', rating_list)
        })

        context.update({
            'rating_list': rating_list,
            'rating_stats': rating_stats,
            'queryform': queryform,
        })
    else:
        if user.is_organization:
            orgs = orgs.union(set(user.profile.organization.values_list('pk', flat=True)))
        rating_list = [t for t in rating_list if t.organization.pk in orgs]
        context.update({
            'rating_list': rating_list,
            'rating_stats': None
        })

    return TemplateResponse(request, 'rating.html', context)
開發者ID:TransparenCEE,項目名稱:exmo2010,代碼行數:74,代碼來源:views.py


注:本文中的django.forms.Form.fields['params']方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。