feature: diff in the web interface for duplicates pastes.

pull/164/head
Sami Mokaddem 2017-12-12 10:48:21 +01:00
parent 9cab76cf88
commit 3fe7ecf75a
2 changed files with 24 additions and 5 deletions

View File

@ -7,7 +7,8 @@
import redis import redis
import json import json
import flask import flask
from flask import Flask, render_template, jsonify, request, Blueprint from flask import Flask, render_template, jsonify, request, Blueprint, make_response
import difflib
import Paste import Paste
@ -113,5 +114,21 @@ def getmoredata():
to_return = p_content[max_preview_modal-1:] to_return = p_content[max_preview_modal-1:]
return to_return return to_return
@showsavedpastes.route("/showDiff/")
def showDiff():
s1 = request.args.get('s1', '')
s2 = request.args.get('s2', '')
p1 = Paste.Paste(s1)
p2 = Paste.Paste(s2)
maxLengthLine1 = p1.get_lines_info()[1]
maxLengthLine2 = p2.get_lines_info()[1]
if maxLengthLine1 > 100000 or maxLengthLine2 > 100000:
return "Can't make the difference as the lines are too long."
htmlD = difflib.HtmlDiff()
lines1 = p1.get_p_content().decode('utf8', 'ignore').splitlines()
lines2 = p2.get_p_content().decode('utf8', 'ignore').splitlines()
the_html = htmlD.make_file(lines1, lines2)
return the_html
# ========= REGISTRATION ========= # ========= REGISTRATION =========
app.register_blueprint(showsavedpastes) app.register_blueprint(showsavedpastes)

View File

@ -63,6 +63,7 @@
<th>Paste info</th> <th>Paste info</th>
<th>Date</th> <th>Date</th>
<th>Path</th> <th>Path</th>
<th>Action</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -72,6 +73,7 @@
<td>Similarity: {{ simil_list[i] }}%</td> <td>Similarity: {{ simil_list[i] }}%</td>
<td>{{ date_list[i] }}</td> <td>{{ date_list[i] }}</td>
<td><a target="_blank" href="{{ url_for('showsavedpastes.showsavedpaste') }}?paste={{ dup_path }}" id='dup_path'>{{ dup_path }}</a></td> <td><a target="_blank" href="{{ url_for('showsavedpastes.showsavedpaste') }}?paste={{ dup_path }}" id='dup_path'>{{ dup_path }}</a></td>
<td><a target="_blank" href="{{ url_for('showsavedpastes.showDiff') }}?s1={{ request.args.get('paste') }}&s2={{ dup_path }}" class="fa fa-columns" title="Show differences"></a></td>
</tr> </tr>
{% set i = i + 1 %} {% set i = i + 1 %}
{% endfor %} {% endfor %}