refactor models, change map package storage and map package loading

This commit is contained in:
Laura Klünder 2016-08-29 22:10:43 +02:00
parent 0656090f27
commit 376d85f9b4
12 changed files with 226 additions and 150 deletions

View file

@ -1,8 +1,11 @@
import mimetypes
import os
from django.conf import settings
from django.contrib.admin.views.decorators import staff_member_required
from django.core.files import File
from django.http import HttpResponse
from django.shortcuts import get_object_or_404, render
from django.shortcuts import get_object_or_404
from .models import Source
@ -10,7 +13,8 @@ from .models import Source
@staff_member_required
def source(request, source):
source = get_object_or_404(Source, name=source)
response = HttpResponse(content_type=mimetypes.guess_type(source.image.name)[0])
for chunk in source.image.chunks():
response = HttpResponse(content_type=mimetypes.guess_type(source.name)[0])
image_path = os.path.join(settings.MAP_ROOT, source.package.directory, 'sources', source.name)
for chunk in File(open(image_path, 'rb')).chunks():
response.write(chunk)
return response