mirror of
https://github.com/Xevion/simple-viewer.git
synced 2026-01-31 08:26:02 -06:00
basic site design, directory path reading, uuid setup, file icon mimetype categorization
This commit is contained in:
+35
-3
@@ -1,7 +1,39 @@
|
||||
from django.shortcuts import render
|
||||
import mimetypes
|
||||
import os
|
||||
|
||||
from django.http import FileResponse
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
|
||||
from viewer.helpers import get_mediatype
|
||||
from viewer.models import ServedDirectory
|
||||
|
||||
from django.http import HttpResponse
|
||||
|
||||
def index(request):
|
||||
"""Index view for the simple-viewer project."""
|
||||
return HttpResponse('Hello, World.')
|
||||
directories = ServedDirectory.objects.all()
|
||||
context = {'title': 'Index',
|
||||
'directories': directories}
|
||||
return render(request, 'index.html', context)
|
||||
|
||||
|
||||
def browse(request, directory_id):
|
||||
dir = get_object_or_404(ServedDirectory, id=directory_id)
|
||||
|
||||
if os.path.isdir(dir.path):
|
||||
files = [
|
||||
(file, get_mediatype(mimetypes.guess_type(file)[0])) for file in os.listdir(dir.path)
|
||||
]
|
||||
context = {
|
||||
'title': f'Browse - {os.path.dirname(dir.path)}',
|
||||
'files': files,
|
||||
'directory': dir
|
||||
}
|
||||
return render(request, 'browse.html', context)
|
||||
else:
|
||||
context = {
|
||||
'title': 'Invalid Directory',
|
||||
'message': 'The path this server directory points to {}.'.format(
|
||||
'exists, but is not a directory' if os.path.exists(dir.path) else 'does not exist'
|
||||
)
|
||||
}
|
||||
return render(request, 'message.html', context, status=500)
|
||||
|
||||
Reference in New Issue
Block a user