Skip to content

Commit 41a2d66

Browse files
Merge pull request #12 from app-generator/file-manager
File manager
2 parents 27165d6 + 5b6068c commit 41a2d66

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

core/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,5 @@
171171

172172
LOGIN_REDIRECT_URL = '/'
173173
EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
174+
175+
X_FRAME_OPTIONS = 'SAMEORIGIN'

home/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def get_breadcrumbs(request):
4141
for component in path_components:
4242
url += f'{os.sep}{component}'
4343
if component == "file-manager":
44-
component = "root"
44+
component = "media"
4545
breadcrumbs.append({'name': component, 'url': url})
4646

4747
return breadcrumbs

templates/includes/subdirectories.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
role="button"
1212
aria-expanded="false"
1313
aria-controls="collapse{{subdirectory.id}}"
14+
onclick="window.location.href = '{% url 'file_manager' subdirectory.path|urlencode %}';"
1415
>
1516
{{ subdirectory.name }}
1617
</a>
@@ -22,7 +23,7 @@
2223
class="ms-{{depth}} collapse show"
2324
>
2425
<i class="fa-solid fa-folder"></i>
25-
<a href="{% url 'file_manager' subdirectory.path %}">{{ subdirectory.name }}</a>
26+
<a href="{% url 'file_manager' subdirectory.path|urlencode %}">{{ subdirectory.name }}</a>
2627
</li>
2728
{% endif %}
2829
{% endfor %}

templates/pages/file-manager.html

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
{% if forloop.last %}
2929
<li class="breadcrumb-item active" aria-current="page">{{ breadcrumb.name }}</li>
3030
{% else %}
31-
<li class="breadcrumb-item"><a href="{{ breadcrumb.url }}">{{ breadcrumb.name }}</a></li>
31+
{% if breadcrumb.name|lower == 'media' %}
32+
<li class="breadcrumb-item active" aria-current="page">{{ breadcrumb.name }}</li>
33+
{% else %}
34+
<li class="breadcrumb-item"><a href="{{ breadcrumb.url }}">{{ breadcrumb.name }}</a></li>
35+
{% endif %}
3236
{% endif %}
3337
{% endfor %}
3438
</ol>
@@ -44,6 +48,7 @@
4448
role="button"
4549
aria-expanded="false"
4650
aria-controls="collapse{{directory.id}}"
51+
onclick="window.location.href = '{% url 'file_manager' directory.path|urlencode %}';"
4752
>
4853
{{ directory.name }}
4954
</a>
@@ -52,13 +57,23 @@
5257
{% else %}
5358
<li>
5459
<i class="fa-solid fa-folder"></i>
55-
<a href="{% url 'file_manager' directory.path %}">{{ directory.name }}</a>
60+
<a href="{% url 'file_manager' directory.path|urlencode %}">{{ directory.name }}</a>
5661
</li>
5762
{% endif %}
5863
{% endfor %}
5964
</ul>
6065
</div>
6166
<div class="col-lg-9 border py-2">
67+
<div class="d-flex justify-content-start mb-3">
68+
<label for="fileInput">
69+
<i class="fa-solid fa-upload text-primary fs-3"></i>
70+
</label>
71+
<form method="post" action="{% url 'upload_file' %}" id="upload-file" enctype="multipart/form-data">
72+
{% csrf_token %}
73+
<input type="hidden" name="directory" value="{{ selected_directory }}">
74+
<input id="fileInput" class="d-none" onchange="submitForm()" type="file" name="file" required>
75+
</form>
76+
</div>
6277
{% if files %}
6378
<div class="table-responsive">
6479
<table class="table">
@@ -73,21 +88,9 @@
7388
<td>{{ file.filename|file_extension|cut:"."|upper }}</td>
7489
<td>
7590
<div class="d-flex align-items-center actions">
76-
{% if file.file|file_extension in ".csv, .txt" %}
77-
<a href="/media/{{ file.file }}">
78-
<i title="View" class="fa-solid fa-eye text-primary"></i>
79-
</a>
80-
{% elif file.file|file_extension == '.pdf' %}
81-
<object data="/media/{{ file.file }}" type="application/pdf">
82-
<a href="/media/{{ file.file }}">
83-
<i title="View" class="fa-solid fa-eye text-primary"></i>
84-
</a>
85-
</object>
86-
{% else %}
87-
<span data-bs-toggle="modal" data-bs-target="#file-{{forloop.counter}}">
88-
<i title="View" class="fa-solid fa-eye text-primary"></i>
89-
</span>
90-
{% endif %}
91+
<span data-bs-toggle="modal" data-bs-target="#file-{{forloop.counter}}">
92+
<i title="View" class="fa-solid fa-eye text-primary"></i>
93+
</span>
9194
<div class="dot-separator mx-2"></div>
9295
<span>
9396
<a href="{% url 'download_file' file.file|encoded_file_path %}">
@@ -104,7 +107,7 @@
104107
<!-- Modal -->
105108
<div class="modal fade" id="file-{{forloop.counter}}" data-bs-backdrop="static" data-bs-keyboard="false"
106109
tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
107-
<div class="modal-dialog modal-dialog-centered modal-lg">
110+
<div class="modal-dialog modal-dialog-centered modal-xl">
108111
<div class="modal-content">
109112
<div class="modal-header">
110113
<h1 class="modal-title fs-5" id="staticBackdropLabel">{{ file.filename }}</h1>
@@ -114,11 +117,13 @@ <h1 class="modal-title fs-5" id="staticBackdropLabel">{{ file.filename }}</h1>
114117
</div>
115118
<div class="modal-body">
116119
{% if file.filename|file_extension in ".jpg, .png, .gif" %}
117-
<img class="w-100" src="/media/{{ file.file }}" alt="df">
120+
<img height="700px" class="w-100" src="/media/{{ file.file }}" alt="df">
118121
{% elif file.filename|file_extension in ".mp4, .webm, .ogg" %}
119-
<video class="w-100" height="240" controls>
122+
<video class="w-100" height="700" controls>
120123
<source src="/media/{{ file.file }}" type="video/mp4">
121124
</video>
125+
{% elif file.filename|file_extension in ".pdf, .txt" %}
126+
<iframe src="/media/{{ file.file }}" width="100%" height="700px"></iframe>
122127
{% endif %}
123128
</div>
124129
</div>

0 commit comments

Comments
 (0)