本文整理汇总了Python中models.Question.search方法的典型用法代码示例。如果您正苦于以下问题:Python Question.search方法的具体用法?Python Question.search怎么用?Python Question.search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Question
的用法示例。
在下文中一共展示了Question.search方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: questions
# 需要导入模块: from models import Question [as 别名]
# 或者: from models.Question import search [as 别名]
def questions(request, **kwargs):
page_data = []
session_data = {}
if local.request.session['uid']:
session_data['user_name'] = User.get_by_id(local.request.session['uid'])[0].name
page = Page(session_data)
if 'search' in request.args:
questions_list = Question.search(request.args['search'])
page.title = "Questions - '%s' - Meno" % request.args['search']
if 'sort' in request.args:
sorts = {
'new': 'date_created',
}
sort_attr = sorts[request.args['sort']]
questions_list = Question.get(order=(sort_attr, 'desc'), limit=30)
else:
page.title = 'Questions - Meno'
questions_list = Question.get_latest(30)
for question in questions_list:
edit = question.latest_edit()[0]
user = User.get_by_id(question.user_id)[0]
age = question.age()
stat = question.latest_status()[0]
question_data = {
'question_id': str(question.id),
'user_id': str(question.user_id),
'views': str(question.views),
'votes': str(question.votes),
'date_created': str(question.created),
'category': str(Category.get_by_id(question.category_id)[0].name),
'answers_count': str(count(question.answers())),
'title': str(edit.title),
'user': str(user.name),
'status': str(stat.status),
'age': str("Asked %sh %sm %ss ago" % (age[0], age[0], age[1])),
}
page_data.append(question_data)
content = QuestionsList(page_data)
local.request.session['last'] = request.base_url
return respond(page.render(content))