Skip to content

Commit 7043202

Browse files
author
mominur-helios
committed
change breadcrumb
1 parent a037633 commit 7043202

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

home/views.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import uuid
23
from django.shortcuts import render, redirect
34
from django.http import HttpResponse, FileResponse, Http404
45
from django.conf import settings
@@ -33,12 +34,14 @@ def get_files_from_directory(directory_path):
3334

3435

3536
def get_breadcrumbs(request):
36-
path_components = [component for component in request.path.split('/') if component]
37+
path_components = [component for component in request.path.split(os.sep) if component]
3738
breadcrumbs = []
3839
url = ''
3940

4041
for component in path_components:
41-
url += f'/{component}'
42+
url += f'{os.sep}{component}'
43+
if component == "file-manager":
44+
component = "root"
4245
breadcrumbs.append({'name': component, 'url': url})
4346

4447
return breadcrumbs
@@ -70,9 +73,10 @@ def generate_nested_directory(root_path, current_path):
7073
directories = []
7174
for name in os.listdir(current_path):
7275
if os.path.isdir(os.path.join(current_path, name)):
76+
unique_id = str(uuid.uuid4())
7377
nested_path = os.path.join(current_path, name)
7478
nested_directories = generate_nested_directory(root_path, nested_path)
75-
directories.append({'name': name, 'path': os.path.relpath(nested_path, root_path), 'directories': nested_directories})
79+
directories.append({'id': unique_id, 'name': name, 'path': os.path.relpath(nested_path, root_path), 'directories': nested_directories})
7680
return directories
7781

7882

templates/includes/subdirectories.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
{% for subdirectory in directory.directories %}
22
{% if subdirectory.directories %}
33
<li
4-
id="collapse{{directory.name}}"
5-
class="ms-{{depth}} collapse {% if subdirectory.name in request.get_full_path %} show {% endif %}"
4+
id="collapse{{directory.id}}"
5+
class="ms-{{depth}} collapse show {% if subdirectory.name in request.get_full_path %} {% endif %}"
66
>
77
<i class="fa-solid fa-folder"></i>
88
<a
99
data-bs-toggle="collapse"
10-
href="#collapse{{subdirectory.name}}"
10+
href="#collapse{{subdirectory.id}}"
1111
role="button"
1212
aria-expanded="false"
13-
aria-controls="collapse{{subdirectory.name}}"
13+
aria-controls="collapse{{subdirectory.id}}"
1414
>
1515
{{ subdirectory.name }}
1616
</a>
1717
</li>
1818
{% include 'includes/subdirectories.html' with directory=subdirectory depth=depth|add:"2" %}
1919
{% else %}
2020
<li
21-
id="collapse{{directory.name}}"
22-
class="ms-{{depth}} collapse {% if subdirectory.name in request.get_full_path %} show {% endif %} "
21+
id="collapse{{directory.id}}"
22+
class="ms-{{depth}} collapse show {% if subdirectory.name in request.get_full_path %} {% endif %} "
2323
>
2424
<i class="fa-solid fa-folder"></i>
2525
<a href="{% url 'file_manager' subdirectory.path %}">{{ subdirectory.name }}</a>

templates/pages/file-manager.html

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,13 @@
3838
{% if directory.directories %}
3939
<li class="">
4040
<i class="fa-solid fa-folder"></i>
41-
<a data-bs-toggle="collapse" href="#collapse{{directory.name}}" role="button" aria-expanded="false"
42-
aria-controls="collapse{{directory.name}}">
41+
<a
42+
data-bs-toggle="collapse"
43+
href="#collapse{{directory.id}}"
44+
role="button"
45+
aria-expanded="false"
46+
aria-controls="collapse{{directory.id}}"
47+
>
4348
{{ directory.name }}
4449
</a>
4550
</li>

0 commit comments

Comments
 (0)