def search(): if not g.search_form.validate(): return redirect(url_for('index')) page = request.args.get('page', 1, type=int) videos, total = Video.search(g.search_form.q.data, page, app.config['POSTS_PER_PAGE']) next_url = url_for('search', q=g.search_form.q.data, page=page + 1)\ if total > page * app.config['POSTS_PER_PAGE'] else None prev_url = url_for('search', q=g.search_form.q.data, page=page - 1)\ if page > 1 else None return render_template('search.html', title=_('search'), videos=videos, next_url=next_url, prev_url=prev_url)
def search(): page = request.args.get('page', 1, type=int) query = request.args.get('q') items_query, total = Item.search(query, page, current_app.config['POSTS_PER_PAGE']) items = [item for item in items_query] videos_query, total = Video.search(query, page, current_app.config['POSTS_PER_PAGE']) videos = [video for video in videos_query] skills_query, total = Skill.search(query, page, current_app.config['POSTS_PER_PAGE']) skills = [skill for skill in skills_query] reddits_query, total = Reddit.search(query, page, current_app.config['POSTS_PER_PAGE']) reddits = [reddit for reddit in reddits_query] all_items = items + videos + skills + reddits result = { 'result': [i.toJSON() for i in all_items], 'has_more': total > page * current_app.config['POSTS_PER_PAGE'], } return jsonify(result)