def search():
# ajax request handling
if g.sijax.is_sijax_request:
g.sijax.register_callback('update_notifications', update_notifications)
g.sijax.register_callback('set_all_notifications_seen', set_all_notifications_seen)
return g.sijax.process_request()
# non-ajax handling:
# posts = Post.query.search(interrogation).all()
form = forms.SearchForm()
options = {
'title': 'Search',
'search_form': form,
}
if form.validate_on_submit():
selection = form.filter.data
interrogation = form.interrogation.data
if not selection or selection == 'all':
options.update({
'users': User.query.search(interrogation, sort=True)[:5],
'topics': Topic.query.search(interrogation, sort=True)[:5],
'posts': Post.query.search(interrogation, sort=True)[:5],
's_pages': Page.query.search(interrogation, sort=True)[:5],
'proposals': Proposal.query.search(interrogation, sort=True)[:5],
'laws': Law.query.search(interrogation, sort=True)[:5]
})
elif selection == 'users':
options['users'] = User.query.search(interrogation, sort=True)[:20]
elif selection == 'topics':
options['topics'] = Topic.query.search(interrogation, sort=True)[:20]
elif selection == 'posts':
options['posts'] = Post.query.search(interrogation, sort=True)[:20]
elif selection == 'pages':
options['s_pages'] = Page.query.search(interrogation, sort=True)[:20]
elif selection == 'proposals':
options['proposals'] = Proposal.query.search(interrogation, sort=True)[:20]
elif selection == 'laws':
options['laws'] = Law.query.search(interrogation, sort=True)[:20]
options.update(base_options())
return render_template("search.html", **options)
评论列表
文章目录