Added related functions and display of duplicated paste in search.py

pull/63/head
Mokaddem 2016-07-19 10:48:44 +02:00
parent 996c0e02de
commit a6996c0b23
3 changed files with 41 additions and 2 deletions

View File

@ -91,6 +91,7 @@ class Paste(object):
self.p_langage = None
self.p_nb_lines = None
self.p_max_length_line = None
self.p_duplicate = None
def get_p_content(self):
"""
@ -277,6 +278,10 @@ class Paste(object):
return True, var
else:
return False, var
def _get_p_duplicate(self):
self.p_duplicate = self.store.hget(self.p_path, "p_duplicate")
return self.p_duplicate if self.p_duplicate is not None else []
def save_all_attributes_redis(self, key=None):
"""

View File

@ -58,6 +58,21 @@ def list_len(s):
return len(s)
app.jinja_env.filters['list_len'] = list_len
def parseStringToList(the_string):
strList = ""
elemList = []
for c in the_string:
if c != ']':
if c != '[' and c !=' ' and c != '"':
strList += c
else:
the_list = strList.split(',')
if len(the_list) == 2:
elemList.append(the_list)
elif len(the_list) > 1:
elemList.append(the_list[1:])
strList = ""
return elemList
def showpaste(content_range):
requested_path = request.args.get('paste', '')
@ -71,10 +86,19 @@ def showpaste(content_range):
p_mime = paste.p_mime
p_lineinfo = paste.get_lines_info()
p_content = paste.get_p_content().decode('utf-8', 'ignore')
p_duplicate_full_list = parseStringToList(paste._get_p_duplicate())
p_duplicate_list = []
p_simil_list = []
for dup_list in p_duplicate_full_list:
path, simil_percent = dup_list
p_duplicate_list.append(path)
p_simil_list.append(simil_percent)
if content_range != 0:
p_content = p_content[0:content_range]
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=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=len(p_content), duplicate_list = p_duplicate_list, simil_list = p_simil_list)
@app.route("/_logs")

View File

@ -42,7 +42,17 @@
</table>
</div>
<div class="panel-body" id="panel-body">
<h4> Content: </h4>
{% if duplicate_list|length == 0 %}
<h4> No Duplicate </h4>
{% else %}
<h4> Duplicate list: </h4>
{% set i = 0 %}
{% for dup_path in duplicate_list %}
Similarity: {{ simil_list[i] }}% - <a target="_blank" href="{{ url_for('showsavedpaste') }}?paste={{ dup_path }}" id='dup_path'>{{ dup_path }}</a></br>
{% set i = i + 1 %}
{% endfor %}
{% endif %}
<h4> Content: </h4>
<p data-initsize="{{ initsize }}"> <xmp id="paste-holder">{{ content }}</xmp></p>
</div>
</div>