add view for file thumbnail in admin

This commit is contained in:
Jake Howard 2016-09-06 17:48:43 +01:00
parent 0cb925bdad
commit a95f741f68
Signed by: jake
GPG key ID: 57AFB45680EDD477
2 changed files with 12 additions and 3 deletions

View file

@ -40,3 +40,11 @@ def file_download(request, id, token):
def hotlink_file_download(request, id): def hotlink_file_download(request, id):
file = get_object_or_404(SharedFile, short_id=id, hotlink=True, published=True) file = get_object_or_404(SharedFile, short_id=id, hotlink=True, published=True)
return FileResponse(file) return FileResponse(file)
@login_required
def uploaded_file(request, filename):
file = get_object_or_404(SharedFile, file=request.get_full_path()[1:]) # strip preceding slash
response = FileResponse(file)
del response['Content-Disposition']
return response

View file

@ -1,13 +1,14 @@
from django.conf.urls import include, url from django.conf.urls import include, url
from django.contrib import admin from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from project.files import views from project.files.views import uploaded_file
urlpatterns = [ urlpatterns = [
url(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
url(r'^admin_resumable/', include('admin_resumable.urls')), url(r'^admin_resumable/', include('admin_resumable.urls')),
url(r'^files/', include('project.files.urls', namespace="files")) url(r'^files/', include('project.files.urls', namespace="files")),
url(r'', include("project.pages.urls", namespace="pages")), url(r'^uploads/(?P<filename>.*)', uploaded_file, name="upload"),
url(r'', include("project.pages.urls", namespace="pages"))
] ]