From 465244e1cec1b04a03636f72c3f46ed0891e2087 Mon Sep 17 00:00:00 2001 From: Mokaddem Date: Thu, 7 Jul 2016 16:38:00 +0200 Subject: [PATCH] Added dynamic table sorting in search page. (Still need to add dependencies) --- bin/packages/Paste.py | 3 +++ var/www/Flask_server.py | 17 +++++++---------- var/www/templates/search.html | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/bin/packages/Paste.py b/bin/packages/Paste.py index cc5c41ad..bedf36b0 100755 --- a/bin/packages/Paste.py +++ b/bin/packages/Paste.py @@ -198,6 +198,9 @@ class Paste(object): def _get_p_date(self): return self.p_date + def _get_p_size(self): + return self.p_size + def _get_hash_lines(self, min=1, start=1, jump=10): """ Returning all the lines of the paste hashed. diff --git a/var/www/Flask_server.py b/var/www/Flask_server.py index 546d92c6..924c0501 100755 --- a/var/www/Flask_server.py +++ b/var/www/Flask_server.py @@ -76,6 +76,8 @@ def search(): q.append(query) r = [] c = [] + paste_date = [] + paste_size = [] # Search from whoosh import index from whoosh.fields import Schema, TEXT, ID @@ -89,10 +91,13 @@ def search(): results = searcher.search(query, limit=None) for x in results: r.append(x.items()[0][1]) - content = Paste.Paste(x.items()[0][1]).get_p_content().decode('utf8', 'ignore') + paste = Paste.Paste(x.items()[0][1]) + content = paste.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, char_to_display=max_preview_modal) + paste_date.append(paste._get_p_date()) + paste_size.append(paste._get_p_size()) + return render_template("search.html", r=r, c=c, paste_date=paste_date, paste_size=paste_size, char_to_display=max_preview_modal) @app.route("/") def index(): @@ -156,14 +161,6 @@ def getmoredata(): requested_path = request.args.get('paste', '') paste = Paste.Paste(requested_path) p_content = paste.get_p_content().decode('utf-8', 'ignore') - '''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] - - #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 diff --git a/var/www/templates/search.html b/var/www/templates/search.html index 9f0c3b4f..451f46df 100644 --- a/var/www/templates/search.html +++ b/var/www/templates/search.html @@ -12,10 +12,14 @@ + + + +