[FIX] EMPLOYEE: Fix screen appears blank and the document is not displayed
This commit is contained in:
@@ -60,40 +60,46 @@
|
||||
{% if document.document %}
|
||||
<div class="modal-body" {% if document.status == "rejected" %} style="border: 5px solid red;"{% endif %}>
|
||||
<!-- Display the file content based on the file type -->
|
||||
{% if file_extension == 'pdf' or file_extension == 'txt' or file_extension == 'docx' or file_extension == 'xlsx' %}
|
||||
<embed
|
||||
src="data:{{ content_type }};base64,{{ file_content|base64_encode }}"
|
||||
type="{{ content_type }}"
|
||||
width="100%"
|
||||
height="500px"
|
||||
/>
|
||||
{% if file_extension == 'pdf' or file_extension == 'txt' %}
|
||||
<iframe
|
||||
src="{{ document.document.url }}"
|
||||
width="100%"
|
||||
height="500px">
|
||||
</iframe>
|
||||
{% elif file_extension == 'docx' or file_extension == 'xlsx' %}
|
||||
<div class="text-center p-5">
|
||||
<p class="pb-">{% trans "Preview not available for this file type." %}</p>
|
||||
<a href="{{ document.document.url }}" download class="oh-btn oh-btn--info">
|
||||
{% trans "Download File" %}
|
||||
</a>
|
||||
</div>
|
||||
{% elif file_extension == 'jpg' or file_extension == 'jpeg' or file_extension == 'png' or file_extension == 'webp' %}
|
||||
<div class="container">
|
||||
<img
|
||||
src="data:{{ content_type }};base64,{{ file_content|base64_encode }}"
|
||||
alt="File Preview"
|
||||
class="img-fluid"
|
||||
style="display: block; width: 100%;height: 500px;"
|
||||
/>
|
||||
</div>
|
||||
<div class="container">
|
||||
<img
|
||||
src="data:{{ content_type }};base64,{{ file_content|base64_encode }}"
|
||||
alt="File Preview"
|
||||
class="img-fluid"
|
||||
style="display: block; width: 100%;height: 500px;"
|
||||
/>
|
||||
</div>
|
||||
{% else %}
|
||||
<p>{% trans "File format not supported for preview." %}</p>
|
||||
<p>{% trans "File format not supported for preview." %}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
{% if document.status == 'rejected' %}
|
||||
<h2 class="oh-label"> <b>{% trans "Reject Reason: " %}</b></h2>
|
||||
<p class="ms-4">{{document.reject_reason}}</p>
|
||||
<h2 class="oh-label"> <b>{% trans "Reject Reason: " %}</b></h2>
|
||||
<p class="ms-4">{{document.reject_reason}}</p>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<div class="oh-not-found">
|
||||
<img
|
||||
style="width: 150px; height: 150px;"
|
||||
src="{% static 'images/ui/document.png' %}"
|
||||
class="oh-404__image mb-4"
|
||||
alt="Page not found. 404."
|
||||
/>
|
||||
<h3 class="oh-404__subtitle">
|
||||
{% trans "No Document to view." %}
|
||||
</h3>
|
||||
</div>
|
||||
<div class="oh-not-found">
|
||||
<img
|
||||
style="width: 150px; height: 150px;"
|
||||
src="{% static 'images/ui/document.png' %}"
|
||||
class="oh-404__image mb-4"
|
||||
alt="Page not found. 404."
|
||||
/>
|
||||
<h3 class="oh-404__subtitle">
|
||||
{% trans "No Document to view." %}
|
||||
</h3>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
@@ -870,6 +870,28 @@ def file_upload(request, id):
|
||||
return render(request, "tabs/htmx/document_form.html", context=context)
|
||||
|
||||
|
||||
def get_content_type(file_extension):
|
||||
"""
|
||||
This function retuns the content type of a file
|
||||
parameters:
|
||||
|
||||
file_extension: The file extension of the file
|
||||
"""
|
||||
|
||||
content_types = {
|
||||
"pdf": "application/pdf",
|
||||
"txt": "text/plain",
|
||||
"docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
"xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"jpg": "image/jpeg",
|
||||
"png": "image/png",
|
||||
"jpeg": "image/jpeg",
|
||||
}
|
||||
|
||||
# Default to application/octet-stream if the file extension is not recognized
|
||||
return content_types.get(file_extension, "application/octet-stream")
|
||||
|
||||
|
||||
@login_required
|
||||
@hx_request_required
|
||||
def view_file(request, id):
|
||||
@@ -908,28 +930,6 @@ def view_file(request, id):
|
||||
return render(request, "tabs/htmx/view_file.html", context)
|
||||
|
||||
|
||||
def get_content_type(file_extension):
|
||||
"""
|
||||
This function retuns the content type of a file
|
||||
parameters:
|
||||
|
||||
file_extension: The file extension of the file
|
||||
"""
|
||||
|
||||
content_types = {
|
||||
"pdf": "application/pdf",
|
||||
"txt": "text/plain",
|
||||
"docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
"xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
||||
"jpg": "image/jpeg",
|
||||
"png": "image/png",
|
||||
"jpeg": "image/jpeg",
|
||||
}
|
||||
|
||||
# Default to application/octet-stream if the file extension is not recognized
|
||||
return content_types.get(file_extension, "application/octet-stream")
|
||||
|
||||
|
||||
@login_required
|
||||
@hx_request_required
|
||||
@manager_can_enter("horilla_documents.add_document")
|
||||
|
||||
Reference in New Issue
Block a user