标题搜索
def news_review():
page = request.args.get('page', 1)
keywords = request.args.get('keywords', None)
try:
page = int(page)
except Exception as ret:
current_app.logger.error(ret)
page = 1
news_list = []
total_page = 1
current_page = 1
filters = [News.status != 0]
if keywords:
filters.append(News.title.contains(keywords))
try:
paginate = News.query.filter(*filters).order_by(News.create_time.desc()).paginate(page, constants.ADMIN_NEWS_PAGE_MAX_COUNT, False)
news_list = paginate.items
total_page = paginate.pages
current_page = paginate.page
except Exception as ret:
current_app.logger.error(ret)
news_dict_list = []
for news in news_list:
news_dict_list.append(news.to_review_dict())
data = {
'total_page' : total_page,
'current_page' : current_page,
'news_list' : news_dict_list
}
return render_template('admin/news_review.html', data=data)