From f1979f6dcb3cce4241cc7aa0d0ac2be315bb59bc Mon Sep 17 00:00:00 2001 From: Mokaddem Date: Thu, 7 Jul 2016 15:34:08 +0200 Subject: [PATCH] Search preview modal more dynamic and responsive --- var/www/Flask_server.py | 21 ++++--- var/www/templates/search.html | 77 ++++++++++++++++--------- var/www/templates/show_saved_paste.html | 2 +- 3 files changed, 64 insertions(+), 36 deletions(-) diff --git a/var/www/Flask_server.py b/var/www/Flask_server.py index e87864a9..546d92c6 100755 --- a/var/www/Flask_server.py +++ b/var/www/Flask_server.py @@ -92,7 +92,7 @@ def search(): content = Paste.Paste(x.items()[0][1]).get_p_content().decode('utf8', 'ignore') content_range = max_preview_char if len(content)>max_preview_char else len(content)-1 c.append(content[0:content_range]) - return render_template("search.html", r=r, c=c) + return render_template("search.html", r=r, c=c, char_to_display=max_preview_modal) @app.route("/") def index(): @@ -145,21 +145,26 @@ def showpreviewpaste(): p_size = paste.p_size p_mime = paste.p_mime p_lineinfo = paste.get_lines_info() - p_content = paste.get_p_content()[0:max_preview_modal].decode('utf-8', 'ignore') - return render_template("show_saved_paste.html", date=p_date, source=p_source, encoding=p_encoding, language=p_language, size=p_size, mime=p_mime, lineinfo=p_lineinfo, content=p_content) + #p_content = paste.get_p_content()[0:max_preview_modal].decode('utf-8', 'ignore') + p_content = paste.get_p_content().decode('utf-8', 'ignore') + p_content = p_content[0:max_preview_modal] + p_initsize = len(p_content) + return render_template("show_saved_paste.html", date=p_date, source=p_source, encoding=p_encoding, language=p_language, size=p_size, mime=p_mime, lineinfo=p_lineinfo, content=p_content, initsize=p_initsize) @app.route("/getmoredata/") def getmoredata(): requested_path = request.args.get('paste', '') - index_prev = int(request.args.get('index', '')) paste = Paste.Paste(requested_path) - p_content = paste.get_p_content().decode('utf-8', 'ignore') - final_index = (index_prev+1)*max_preview_modal + '''final_index = (index_prev+1)*max_preview_modal if final_index > len(p_content)-1: # prevent out of bound final_index = len(p_content)-1 - - to_return = p_content[index_prev*max_preview_modal:final_index] + ''' + #to_return = p_content[index_prev*max_preview_modal:final_index] + + #correct_index = len(p_content) if max_preview_modal > len(p_content) else max_preview_modal + #to_return = str(p_content[correct_index:]) + to_return = p_content[max_preview_modal:] return to_return if __name__ == "__main__": diff --git a/var/www/templates/search.html b/var/www/templates/search.html index deb53537..9f0c3b4f 100644 --- a/var/www/templates/search.html +++ b/var/www/templates/search.html @@ -124,17 +124,19 @@ diff --git a/var/www/templates/show_saved_paste.html b/var/www/templates/show_saved_paste.html index 427b6a9a..924fd2da 100644 --- a/var/www/templates/show_saved_paste.html +++ b/var/www/templates/show_saved_paste.html @@ -43,7 +43,7 @@

Content:

-

{{ content }}

+

{{ content }}