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))
@app.route('/download_attachment/<string:filename>')
@app.route('/download_file/<string:filename>')
@login_required
def download_attachment(filename):
def download_file(filename):
# Implement code to serve the attachment for download
# You may use Flask's send_from_directory or send_file
return send_from_directory(app.config['STORAGE_DIR'], filename)

View File

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