Fixed bug in terms-management-interface (only display one paste) + removed get_language of all pastes due to the huge overhead.

This commit is contained in:
Mokaddem 2016-08-22 13:59:12 +02:00
parent d3c0fc5f94
commit e144e8e1c6
2 changed files with 22 additions and 29 deletions

View file

@ -626,8 +626,6 @@ def terms_management_query_paste():
set_paste_name = "tracked_" + term set_paste_name = "tracked_" + term
track_list_path = r_serv_term.smembers(set_paste_name) track_list_path = r_serv_term.smembers(set_paste_name)
print set_paste_name
print track_list_path
for path in track_list_path: for path in track_list_path:
paste = Paste.Paste(path) paste = Paste.Paste(path)
@ -635,14 +633,13 @@ def terms_management_query_paste():
p_date = p_date[6:]+'/'+p_date[4:6]+'/'+p_date[0:4] p_date = p_date[6:]+'/'+p_date[4:6]+'/'+p_date[0:4]
p_source = paste.p_source p_source = paste.p_source
p_encoding = paste._get_p_encoding() p_encoding = paste._get_p_encoding()
p_language = paste._get_p_language()
p_size = paste.p_size p_size = paste.p_size
p_mime = paste.p_mime p_mime = paste.p_mime
p_lineinfo = paste.get_lines_info() p_lineinfo = paste.get_lines_info()
p_content = paste.get_p_content().decode('utf-8', 'ignore') p_content = paste.get_p_content().decode('utf-8', 'ignore')
if p_content != 0: if p_content != 0:
p_content = p_content[0:400] p_content = p_content[0:400]
paste_info.append({"path": path, "date": p_date, "source": p_source, "encoding": p_encoding, "language": p_language, "size": p_size, "mime": p_mime, "lineinfo": p_lineinfo, "content": p_content}) paste_info.append({"path": path, "date": p_date, "source": p_source, "encoding": p_encoding, "size": p_size, "mime": p_mime, "lineinfo": p_lineinfo, "content": p_content})
return jsonify(paste_info) return jsonify(paste_info)

View file

@ -220,48 +220,44 @@
// On click, get html content from url and update the corresponding modal // On click, get html content from url and update the corresponding modal
$("[data-toggle='modal']").on("click.openmodal", function (event) { $("[data-toggle='modal']").on("click.openmodal", function (event) {
//console.log(data);
event.preventDefault(); event.preventDefault();
var the_modal=$(this); var the_modal=$(this);
var url = "{{ url_for('terms_management_query_paste') }}?term=" + $(this).attr('data-term'); var url = "{{ url_for('terms_management_query_paste') }}?term=" + $(this).attr('data-term');
$.getJSON(url, function (data) { $.getJSON(url, function (data) {
//console.log(data);
if (data.length != 0) { if (data.length != 0) {
var html_to_add = "";
html_to_add += "<table class=\"table table-striped\">";
html_to_add += "<thead>";
html_to_add += "<tr>";
html_to_add += "<th>Source</th>";
html_to_add += "<th>Date</th>";
html_to_add += "<th>Encoding</th>";
html_to_add += "<th>Size (Kb)</th>";
html_to_add += "<th>Mime</th>";
html_to_add += "<th>(# lines, Max line length)</th>";
html_to_add += "<th>Preview</th>";
html_to_add += "</tr>";
html_to_add += "</thead>";
html_to_add += "<tbody>";
for (i=0; i<data.length; i++) { for (i=0; i<data.length; i++) {
curr_data = data[i]; curr_data = data[i];
var html_to_add = "";
html_to_add += "<table class=\"table table-condensed\">";
html_to_add += "<thead>";
html_to_add += "<tr>";
html_to_add += "<th>Source</th>";
html_to_add += "<th>Date</th>";
html_to_add += "<th>Encoding</th>";
html_to_add += "<th>Language</th>";
html_to_add += "<th>Size (Kb)</th>";
html_to_add += "<th>Mime</th>";
html_to_add += "<th>Number of lines</th>";
html_to_add += "<th>Max line length</th>";
html_to_add += "<th>Preview</th>";
html_to_add += "</tr>";
html_to_add += "</thead>";
html_to_add += "<tbody>";
html_to_add += "<tr>"; html_to_add += "<tr>";
html_to_add += "<td>"+curr_data.source+"</td>"; html_to_add += "<td>"+curr_data.source+"</td>";
html_to_add += "<td>"+curr_data.date+"</td>"; html_to_add += "<td>"+curr_data.date+"</td>";
html_to_add += "<td>"+curr_data.encoding+"</td>"; html_to_add += "<td>"+curr_data.encoding+"</td>";
html_to_add += "<td>"+curr_data.language+"</td>";
html_to_add += "<td>"+curr_data.size+"</td>"; html_to_add += "<td>"+curr_data.size+"</td>";
html_to_add += "<td>"+curr_data.mime+"</td>"; html_to_add += "<td>"+curr_data.mime+"</td>";
html_to_add += "<td>"+curr_data.lineinfo[0]+"</td>"; html_to_add += "<td>("+curr_data.lineinfo[0]+", "+curr_data.lineinfo[1]+")</td>";
html_to_add += "<td>"+curr_data.lineinfo[1]+"</td>";
html_to_add += "<td><div class=\"row\"><button class=\"btn btn-xs btn-default\" data-toggle=\"popover\" data-placement=\"left\" data-content=\""+curr_data.content+"\">Preview content</button><a target=\"_blank\" href=\"{{ url_for('showsavedpaste') }}?paste="+curr_data.path+"&num=0\"> <button type=\"button\" class=\"btn btn-xs btn-info\">Show Paste</button></a></div></td>"; html_to_add += "<td><div class=\"row\"><button class=\"btn btn-xs btn-default\" data-toggle=\"popover\" data-placement=\"left\" data-content=\""+curr_data.content+"\">Preview content</button><a target=\"_blank\" href=\"{{ url_for('showsavedpaste') }}?paste="+curr_data.path+"&num=0\"> <button type=\"button\" class=\"btn btn-xs btn-info\">Show Paste</button></a></div></td>";
html_to_add += "</tr>"; html_to_add += "</tr>";
html_to_add += "</tbody>";
html_to_add += "</table>";
$("#mymodalbody").html(html_to_add);
$("[data-toggle=popover]").popover();
$("#button_show_plot").attr("href", "{{ url_for('terms_plot_tool')}}"+"?term="+the_modal.attr('data-term') );
} }
html_to_add += "</tbody>";
html_to_add += "</table>";
$("#mymodalbody").html(html_to_add);
$("[data-toggle=popover]").popover();
$("#button_show_plot").attr("href", "{{ url_for('terms_plot_tool')}}"+"?term="+the_modal.attr('data-term') );
} else { } else {
$("#mymodalbody").html("No paste containing this term has been received yet."); $("#mymodalbody").html("No paste containing this term has been received yet.");
$("#button_show_plot").attr("href", "{{ url_for('terms_plot_tool')}}"+"?term="+the_modal.attr('data-term') ); $("#button_show_plot").attr("href", "{{ url_for('terms_plot_tool')}}"+"?term="+the_modal.attr('data-term') );