本文整理汇总了Python中forms.SearchForm.full_clean方法的典型用法代码示例。如果您正苦于以下问题:Python SearchForm.full_clean方法的具体用法?Python SearchForm.full_clean怎么用?Python SearchForm.full_clean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forms.SearchForm
的用法示例。
在下文中一共展示了SearchForm.full_clean方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tree_list
# 需要导入模块: from forms import SearchForm [as 别名]
# 或者: from forms.SearchForm import full_clean [as 别名]
def tree_list(request):
with get_treestore() as treestore:
if request.method == 'POST':
form = SearchForm(request.POST)
if form.is_valid():
taxa = form.cleaned_data['taxa']
filter = form.cleaned_data['filter']
params = [(x, y) for x, y in form.cleaned_data.items()]
return redirect('/trees/?' + urllib.urlencode(params))
else:
taxa = request.GET.get('taxa')
filter = request.GET.get('filter')
filter = filter if filter else None
form = SearchForm(initial=request.GET)
form.full_clean()
taxa = [x.strip() for x in taxa.split(',')] if taxa else []
params = {'form': form, 'taxonomy':settings.DEFAULT_TAXONOMY}
params.update(csrf(request))
try:
trees = list(treestore.list_trees_containing_taxa(contains=taxa, filter=filter,
taxonomy=settings.DEFAULT_TAXONOMY, show_counts=True))
except Exception as e:
errors = form._errors.setdefault(NON_FIELD_ERRORS, ErrorList())
err_msg = "There was a problem with your search: %s" % e
errors.append(err_msg)
return render_to_response(
'list.html',
params,
context_instance=RequestContext(request)
)
trees = [(tree_id_from_uri(m[0]), int(m[1])) for m in trees]
paginator = Paginator(trees, TREES_PER_PAGE)
page = request.GET.get('page')
try:
tree_list = paginator.page(page)
except PageNotAnInteger:
# If page is not an integer, deliver first page.
tree_list = paginator.page(1)
except EmptyPage:
# If page is out of range (e.g. 9999), deliver last page of results.
tree_list = paginator.page(paginator.num_pages)
params.update({'tree_list': tree_list,
'max_match_count': len(taxa)})
num_pages = paginator.num_pages
page_range = [n for n in range(tree_list.number - 2, tree_list.number + 3)
if n >= 1 and n <= num_pages]
params.update({
'total_results': len(trees),
'low_result': TREES_PER_PAGE * (tree_list.number - 1) + 1,
'high_result': min(len(trees), TREES_PER_PAGE * tree_list.number)
})
if page_range[0] == 2: page_range = [1] + page_range
elif page_range[0] > 2: page_range = [1, '...'] + page_range
if page_range[-1] == num_pages - 1: page_range += [num_pages]
elif page_range[-1] < num_pages - 1: page_range += ['...', num_pages]
pages = []
for page in page_range:
if page == '...': pages.append((page, None))
else:
p = []
for arg in ('taxa', 'filter'):
if arg in request.GET:
p += [(arg, request.GET.get(arg))]
p += [('page', page)]
pages.append((page, '/trees/?' + urllib.urlencode(p)))
params['pages'] = pages
return render_to_response(
'list.html',
params,
context_instance=RequestContext(request)
)