def searchWithoutLoading(): if request.headers['Content-Type'] == 'application/json': request_json = request.get_json() query = request_json['search_query'] if len(query) != 0: posts = dbOps.search(query) if len(posts) == 0: posts_json = json.dumps({'posts_data': []}) return posts_json formatted_posts = [] for post in posts: new_post = ( post.textbook_title, post.textbook_author, str(post.post_id) ) formatted_posts.append(new_post) posts_dictionary = { 'posts_data': list([{ 'textbook_title': textbook_title, 'textbook_author': textbook_author, 'post_id': post_id } for (textbook_title, textbook_author, post_id) in formatted_posts]) } posts_json = json.dumps(posts_dictionary) return posts_json else: posts_json = json.dumps({'posts_data': []}) return posts_json
def searchWithoutLoading(): if request.headers['Content-Type'] == 'application/json': request_json = request.get_json() query = request_json['search_query'] if len(query) != 0: posts = dbOps.search(query) if len(posts) == 0: posts_json = json.dumps({'posts_data': []}) return posts_json formatted_posts = [] for post in posts: new_post = (post.textbook_title, post.textbook_author, str(post.post_id)) formatted_posts.append(new_post) posts_dictionary = { 'posts_data': list([{ 'textbook_title': textbook_title, 'textbook_author': textbook_author, 'post_id': post_id } for (textbook_title, textbook_author, post_id) in formatted_posts]) } posts_json = json.dumps(posts_dictionary) return posts_json else: posts_json = json.dumps({'posts_data': []}) return posts_json
def search(): if request.method == 'POST': query = request.form['search'] posts = dbOps.search(query) if posts: page, per_page, offset = get_page_items(20) pagination = Pagination(page=page, total=len(posts), search=False, record_name='posts', per_page=per_page, css_framework='foundation') return render_template("posts.html", posts=posts[offset:offset + per_page], pagination=pagination, search_terms=query, user_id=session['user_id']) else: flash("No posts match your search!") return redirect(url_for("show_all_posts"))
def search(): if request.method == 'POST': query = request.form['search'] posts = dbOps.search(query) if posts: page, per_page, offset = get_page_items(20) pagination = Pagination(page=page, total=len(posts), search=False, record_name='posts', per_page=per_page, css_framework='foundation') return render_template("posts.html", posts=posts[offset:offset + per_page], pagination=pagination, search_terms=query, user_id=session['user_id']) else: flash("No posts match your search!") return redirect(url_for("show_all_posts"))