当前位置: 首页>>代码示例>>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;未经允许,请勿转载。