You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
DjangoBlog/src/blog/forms.py

23 lines
705 B

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import logging
from django import forms
from haystack.forms import SearchForm
logger = logging.getLogger(__name__)
#zhq: 博客搜索表单类 - 继承自Haystack的SearchForm
class BlogSearchForm(SearchForm):
querydata = forms.CharField(required=True)
def search(self):
#zhq: 执行搜索操作调用父类的search方法
datas = super(BlogSearchForm, self).search()
# zhq: 如果表单验证失败,返回空结果
if not self.is_valid():
return self.no_query_found()
# zhq: 记录搜索关键词到日志
if self.cleaned_data['querydata']:
logger.info(self.cleaned_data['querydata'])
return datas