searching now working with preview, details and redirection to the paste display page.

pull/57/head
Mokaddem 2016-07-06 14:30:32 +02:00
parent 7ff9b9a583
commit 9209d48e30
3 changed files with 67 additions and 26 deletions

View File

@ -20,7 +20,10 @@ if not os.path.exists(configfile):
cfg = ConfigParser.ConfigParser() cfg = ConfigParser.ConfigParser()
cfg.read(configfile) cfg.read(configfile)
max_preview_char = 500
max_preview_char = cfg.get("Flask", "max_preview_char")
max_preview_modal = cfg.get("Flask", "max_preview_modal")
# REDIS # # REDIS #
r_serv = redis.StrictRedis( r_serv = redis.StrictRedis(
@ -86,7 +89,7 @@ def search():
results = searcher.search(query, limit=None) results = searcher.search(query, limit=None)
for x in results: for x in results:
r.append(x.items()[0][1]) r.append(x.items()[0][1])
content = Paste.Paste(x.items()[0][1]).get_p_content() 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 content_range = max_preview_char if len(content)>max_preview_char else len(content)-1
c.append(content[0:content_range]) c.append(content[0:content_range])
return render_template("search.html", r=r, c=c) return render_template("search.html", r=r, c=c)
@ -117,7 +120,33 @@ def tldstrending():
@app.route("/showsavedpaste/") @app.route("/showsavedpaste/")
def showsavedpaste(): def showsavedpaste():
return render_template("show_saved_paste.html") requested_path = request.args.get('paste', '')
paste = Paste.Paste(requested_path)
p_date = str(paste._get_p_date())
p_date = p_date[6:]+'/'+p_date[4:6]+'/'+p_date[0:4]
p_source = paste.p_source
p_encoding = paste._get_p_encoding()
p_language = paste._get_p_language()
p_size = paste.p_size
p_mime = paste.p_mime
p_lineinfo = paste.get_lines_info()
p_content = paste.get_p_content().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)
@app.route("/showpreviewpaste/")
def showpreviewpaste():
requested_path = request.args.get('paste', '')
paste = Paste.Paste(requested_path)
p_date = str(paste._get_p_date())
p_date = p_date[6:]+'/'+p_date[4:6]+'/'+p_date[0:4]
p_source = paste.p_source
p_encoding = paste._get_p_encoding()
p_language = paste._get_p_language()
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)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -25,6 +25,13 @@
max-height: 500px; max-height: 500px;
font-size: 13px; font-size: 13px;
} }
xmp {
white-space:pre-wrap;
word-wrap:break-word;
}
.modal-backdrop.fade {
opacity: 0;
}
</style> </style>
</head> </head>
@ -57,14 +64,14 @@
<!-- Modal content--> <!-- Modal content-->
<div id="mymodalcontent" class="modal-content"> <div id="mymodalcontent" class="modal-content">
<div id="mymodalbody" class="modal-body"> <div id="mymodalbody" class="modal-body" max-width="850px">
<p>Some text in the modal.</p> <p>Loading paste information...</p>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<a id="button_show_path" target="_blank" href=""><button type="button" class="btn btn-info">Show saved paste</button></a>
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button> <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
@ -98,7 +105,7 @@
<tr> <tr>
<td>{{ i + 1 }}</td> <td>{{ i + 1 }}</td>
<td><a target="_blank" href="{{ url_for('showsavedpaste') }}?paste={{ path }}"> {{ path }}</a></td> <td><a target="_blank" href="{{ url_for('showsavedpaste') }}?paste={{ path }}"> {{ path }}</a></td>
<td><p><span class="glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="left" title="{{ prev_content }}"></span> <button type="button" class="btn-link" data-toggle="modal" data-target="#mymodal" data-url="{{ url_for('showsavedpaste') }}?paste={{ path }}"><span class="fa fa-search-plus"></span></button></p></td> <td><p><span class="glyphicon glyphicon-info-sign" data-toggle="tooltip" data-placement="left" title="{{ prev_content }}"></span> <button type="button" class="btn-link" data-num="{{ i + 1 }}" data-toggle="modal" data-target="#mymodal" data-url="{{ url_for('showsavedpaste') }}?paste={{ path }}&num={{ i+1 }}" data-path="{{ path }}"><span class="fa fa-search-plus"></span></button></p></td>
</tr> </tr>
{% set i = i + 1 %} {% set i = i + 1 %}
{% endfor %} {% endfor %}
@ -119,6 +126,7 @@
<script> <script>
$(document).ready(function(){ $(document).ready(function(){
$('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="tooltip"]').tooltip();
$("#button_show_path").hide();
}); });
</script> </script>
@ -127,11 +135,17 @@ $(document).ready(function(){
// 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", function (event) { $("[data-toggle='modal']").on("click", function (event) {
event.preventDefault(); event.preventDefault();
var url = $(this).attr('data-url'); var modal=$(this)
var modal_id = $(this).attr('data-target'); var url = " {{ url_for('showpreviewpaste') }}?paste=" + $(this).attr('data-path') + "&num=" + $(this).attr('data-num');
$.get(url, function (data) { $.get(url, function (data) {
$("#mymodalbody").html(data); $("#mymodalbody").html(data);
$("#button_show_path").attr('href', $(modal).attr('data-url'));
$("#button_show_path").show('fast');
}); });
}); });
$("#mymodal").on('hidden.bs.modal', function () {
$("#mymodalbody").html("<p>Loading paste information...</p>");
$("#button_show_path").attr('href', '');
});
</script> </script>
</html> </html>

View File

@ -7,7 +7,7 @@
</head> </head>
<body> <body>
<h2> Paste: </h2> <h2> Paste: {{ request.args.get('num') }}</h2>
<h3> {{ request.args.get('paste') }} </h3> <h3> {{ request.args.get('paste') }} </h3>
<hr></br> <hr></br>
@ -19,30 +19,28 @@
<th>Source</th> <th>Source</th>
<th>Encoding</th> <th>Encoding</th>
<th>Language</th> <th>Language</th>
<th>Size</th> <th>Size (Kb)</th>
<th>Mime</th> <th>Mime</th>
<th>Number of line</th> <th>Number of lines</th>
<th>Max line length</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr> <tr>
<td>John</td> <td>{{ date }}</td>
<td>Doe</td> <td>{{ source }}</td>
<td>john@example.com</td> <td>{{ encoding }}</td>
</tr> <td>{{ language }}</td>
<tr> <td>{{ size }}</td>
<td>Mary</td> <td>{{ mime }}</td>
<td>Moe</td> <td>{{ lineinfo.0 }}</td>
<td>mary@example.com</td> <td>{{ lineinfo.1 }}</td>
</tr>
<tr>
<td>July</td>
<td>Dooley</td>
<td>july@example.com</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
<h4> Content: </h4>
<p id="paste_content"> <xmp> {{ content }} </xmp> </p>
</body> </body>
</html> </html>