mirror of
https://github.com/Xevion/simple-viewer.git
synced 2025-12-06 13:16:31 -06:00
added server side directory adding, validation and redirecting, show directory path and mention 'files' near filecount in panel header
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import os
|
||||
|
||||
from django.http import FileResponse, HttpResponse
|
||||
from django.http import FileResponse, HttpResponseRedirect
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.urls import reverse
|
||||
|
||||
from viewer.helpers import extra_listdir
|
||||
from viewer.models import ServedDirectory
|
||||
@@ -61,4 +62,25 @@ def add(request):
|
||||
|
||||
|
||||
def submit_new(request):
|
||||
return HttpResponse('')
|
||||
try:
|
||||
s = ServedDirectory(
|
||||
path=request.POST['path'],
|
||||
regex_pattern=request.POST.get('regex'),
|
||||
regex=request.POST.get('regex') is not None,
|
||||
match_filename=request.POST.get('match_filename', False),
|
||||
recursive=request.POST.get('recursive', False)
|
||||
)
|
||||
if not os.path.isdir(request.POST['path']):
|
||||
raise ValueError('A invalid Directory was specified in the request.')
|
||||
s.save()
|
||||
except KeyError:
|
||||
return render(request, 'message.html', status=403,
|
||||
context={'title': 'Invalid Options',
|
||||
'message': 'The POST request you sent did not have the options required to complete '
|
||||
'the request.'})
|
||||
except ValueError:
|
||||
return render(request, 'message.html', status=400,
|
||||
context={'title': 'Invalid Directory',
|
||||
'message': 'The directory you specified was not a valid directory, either it doesn\'t '
|
||||
'exist or it isn\'t a directory.'})
|
||||
return HttpResponseRedirect(reverse('browse', args=(s.id,)))
|
||||
|
||||
Reference in New Issue
Block a user