From cda841065ab557e23278cb837cd64cf552399b7a Mon Sep 17 00:00:00 2001 From: Xevion Date: Sat, 31 Oct 2020 18:47:16 -0500 Subject: [PATCH] added directory prefill shortcut creation --- viewer/helpers.py | 11 +++++++++-- viewer/templates/add.html | 2 +- viewer/templates/browse.html | 17 +++++++++++++---- viewer/views.py | 5 ++++- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/viewer/helpers.py b/viewer/helpers.py index 02cf123..101871b 100644 --- a/viewer/helpers.py +++ b/viewer/helpers.py @@ -1,5 +1,5 @@ import os -from typing import Tuple, List +from typing import List, Tuple def extra_listdir(path: str) -> List[Tuple[str, str]]: @@ -9,7 +9,14 @@ def extra_listdir(path: str) -> List[Tuple[str, str]]: :param path: The path to the directory. :return: A list of tuples, each containing two strings, the file or directory name, and the media type. """ - return [(file, get_all_mediatype(file, path)) for file in os.listdir(path)] + files = [] + for file in os.listdir(path): + mediatype = get_all_mediatype(file, path) + if mediatype == 'folder': + files.append((file, mediatype, os.path.join(path, file))) + else: + files.append((file, mediatype)) + return files def get_all_mediatype(head: str, tail: str) -> str: diff --git a/viewer/templates/add.html b/viewer/templates/add.html index 6d69511..f5d8de9 100644 --- a/viewer/templates/add.html +++ b/viewer/templates/add.html @@ -22,7 +22,7 @@
- + diff --git a/viewer/templates/browse.html b/viewer/templates/browse.html index 70e8348..5cbecf4 100644 --- a/viewer/templates/browse.html +++ b/viewer/templates/browse.html @@ -17,13 +17,22 @@ - - {{ file.0 }} - + {% if file.1 == 'folder' %} + + {{ file.0 }} + + {% else %} + + {{ file.0 }} + {{ file.0 }} + + {% endif %}
{% endfor %}
- + {% load static %} {% endblock content %} diff --git a/viewer/views.py b/viewer/views.py index dc68dd1..712ed85 100644 --- a/viewer/views.py +++ b/viewer/views.py @@ -58,7 +58,10 @@ def file(request, directory_id, file): def add(request): - return render(request, 'add.html', {'title': 'Add New Directory'}) + context = {'title': 'Add New Directory'} + if 'path' in request.GET.keys(): + context['path_prefill'] = request.GET['path'] + return render(request, 'add.html', context) def submit_new(request):