Skip to content

Commit f4c1771

Browse files
author
SM_SAYEED
committed
view enabled for result files
1 parent 7c7cecd commit f4c1771

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

app.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,16 @@ def uploaded_file(filename):
393393
abort(404)
394394
return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
395395

396+
@app.route('/view_result/<property_name>/<tab>/<path:filename>')
397+
def view_result_file(property_name, tab, filename):
398+
filepath = os.path.join(app.config['UPLOAD_FOLDER'], property_name, tab, filename)
399+
if not os.path.isfile(filepath):
400+
return "File not found.", 404
401+
402+
ext = filename.rsplit('.', 1)[-1].lower()
403+
return render_template("view_result.html", filename=filename, property_name=property_name, tab=tab, ext=ext)
404+
405+
396406

397407
@app.route('/clips', methods=['GET', 'POST'])
398408
def public_clips():

templates/property_detail.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,22 @@ <h3>Upload a {{ pretty_title }} {{ tab.title() }} {% if tab == 'dataset' %}(CSV
176176
{% endif %}
177177
</td>
178178
<td>{{ uploaded_at.split('T')[0] if uploaded_at else '' }}</td>
179+
179180
<td>
180-
{% if fname.endswith('.csv') or fname.endswith('.npy') %}
181+
182+
{% if tab == 'dataset' and (fname.endswith('.csv') or fname.endswith('.npy')) %}
181183
<a href="{{ url_for('view_table', filename=property_name + '/' + tab + '/' + fname) }}" target="_blank">View</a>
184+
{% elif tab == 'results' %}
185+
<a href="{{ url_for('view_result_file', property_name=property_name, tab=tab, filename=fname) }}" target="_blank">View</a>
182186
{% endif %}
183-
<a href="{{ url_for('uploaded_file', filename=property_name + '/' + tab + '/' + fname) }}" download>Download</a>
187+
<a href="{{ url_for('uploaded_file', filename=property_name + '/' + tab + '/' + fname) }}" download>Download</a>
184188
{% if admin %}
185-
<form action="{{ url_for('delete_dataset_file', property_name=property_name, tab=tab, filename=fname) }}" method="post" style="display:inline;" onsubmit="return confirm('Delete this file?');">
189+
<form action="{{ url_for('delete_dataset_file', property_name=property_name, tab=tab, filename=fname) }}" method="post" style="display:inline;" onsubmit="return confirm('Delete this file?');">
186190
<button type="submit" class="delete-btn">Delete</button>
187191
</form>
188192
{% endif %}
189193
</td>
194+
190195
</tr>
191196
{% endfor %}
192197
{% if uploads|length == 0 %}

templates/view_result.html

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<title>View Result File</title>
5+
</head>
6+
<body>
7+
<h2>Viewing: {{ filename }}</h2>
8+
9+
{% if ext in ['png', 'jpg', 'jpeg', 'gif'] %}
10+
<img src="{{ url_for('uploaded_file', filename=property_name + '/' + tab + '/' + filename) }}" style="max-width:100%;">
11+
{% elif ext == 'pdf' %}
12+
<iframe src="{{ url_for('uploaded_file', filename=property_name + '/' + tab + '/' + filename) }}" width="100%" height="600px"></iframe>
13+
{% else %}
14+
<p>Preview not supported. <a href="{{ url_for('uploaded_file', filename=property_name + '/' + tab + '/' + filename) }}">Download file</a></p>
15+
{% endif %}
16+
17+
<p><a href="{{ url_for('property_detail', property_name=property_name, tab=tab) }}">Back</a></p>
18+
</body>
19+
</html>

0 commit comments

Comments
 (0)