Implemented file in comments delete

This commit is contained in:
Vadim Likholetov 2023-12-10 15:14:23 +02:00
parent 563b5eebe6
commit 4c3e6b314d
2 changed files with 22 additions and 30 deletions

View File

@ -247,9 +247,9 @@ def delete_file(attachment_id):
return redirect(url_for('sar_details', id=sar_id)) return redirect(url_for('sar_details', id=sar_id))
@app.route('/download_attachment/<string:filename>') @app.route('/download_file/<string:filename>')
@login_required @login_required
def download_attachment(filename): def download_file(filename):
# Implement code to serve the attachment for download # Implement code to serve the attachment for download
# You may use Flask's send_from_directory or send_file # You may use Flask's send_from_directory or send_file
return send_from_directory(app.config['STORAGE_DIR'], filename) return send_from_directory(app.config['STORAGE_DIR'], filename)

View File

@ -103,8 +103,8 @@
{% set ns.drawn = true %} {% set ns.drawn = true %}
<!-- Button to delete GPX Upload Modal --> <!-- Button to delete GPX Upload Modal -->
<button type="button" class="gpx-delete-button"> <button type="button" class="gpx-delete-button">
<a href="{{ url_for('delete_gpx', gpx_id=gpx_track.id, sar_id=sar.SARCall.id ) }}"> <a href="{{ url_for('delete_gpx', gpx_id=gpx_track.id, sar_id=sar.SARCall.id ) }}">
&#128465;</a> &#128465;</a>
</button> </button>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
@ -123,46 +123,38 @@
{# File attachments part #} {# File attachments part #}
<small><strong>File attachment:</strong></small><p> <small><strong>File attachment:</strong></small><p>
{% set ns=namespace(has_file = false) %} {% set ns=namespace(has_file = false) %}
{% set fs=namespace(filename = 0) %}
{% for file in comments_with_attachment %} {% for file in comments_with_attachment %}
{% if file.comment_id == comment.id %} {% if file.comment_id == comment.id %}
{% set ns.has_file = true %} {% set ns.has_file = true %}
{% if file.is_image %} <a href="{{ url_for('download_file', filename = file.file_name) }}">
<img src="{{ url_for('download_thumb', filename=file.file_name) }}" {% if file.is_image %}
class="img-thumbnail"> <img src="{{ url_for('download_thumb', filename=file.file_name) }}"
{% set filename = file.file_name %} class="img-thumbnail">
{% else %} {% else %}
<i class="fa fa-file" aria-hidden="true"></i> {{ file.file_name }} <i class="fa fa-file" aria-hidden="true"></i> {{ file.file_name }}
{% endif %} {% endif %}
{% set fs.filename = file.id %}
</a>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% if is_logged_in %} {% if is_logged_in %}
{% if ns.has_file %} {% if ns.has_file %}
<!-- Display the attachment --> <!-- Display the attachment -->
<table> <!-- Button to delete the attachment -->
<td> <form method="POST"
{# Download attachment #} action="{{ url_for('delete_file', attachment_id=fs.filename) }}">
<button type="submit" class="btn btn-primary"> {# Delete attachment #}
<a href="{{ url_for('download_attachment', filename=filename) }}">&#11015;</a> <input type="hidden" id="sar_call_id" name="sarId"
</button> value="{{ sar.SARCall.id }}">
</td> <button type="submit" class="btn btn-danger">&#128465;</button>
<td> </form>
<!-- Button to delete the attachment -->
<form method="POST"
action="{{ url_for('delete_file', attachment_id=comment.id) }}">
{# Delete attachment #}
<input type="hidden" id="sar_call_id" name="sarId"
value="{{ sar.SARCall.id }}">
<button type="submit" class="btn btn-danger">&#128465;</button>
</form>
</td>
</table>
{% else %} {% else %}
<form method="POST" <form method="POST"
action={{ url_for("upload_file") }} enctype="multipart/form-data"> action={{ url_for("upload_file") }} enctype="multipart/form-data">
<input type="file" name="file" accept="image/*"> <input type="file" name="file" accept="image/*">
<br><br>
<input type="submit" value="Upload"> <input type="submit" value="Upload">
<input type="file" id="attachmentInput" style="display: none;"> <input type="file" id="attachmentInput" style="display: none;">
<input type="hidden" id="comment_id" name="commentId" <input type="hidden" id="comment_id" name="commentId"