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