update sources API

This commit is contained in:
Laura Klünder 2017-07-08 15:09:56 +02:00
parent 8662d5a062
commit df19daf501
2 changed files with 8 additions and 3 deletions

View file

@ -224,6 +224,4 @@ class SourceViewSet(MapdataViewSet):
def _image(self, request, pk=None):
source = self.get_object()
response = HttpResponse(content_type=mimetypes.guess_type(source.name)[0])
response.write(source.image)
return response
return HttpResponse(open(source.filepath, 'rb'), content_type=mimetypes.guess_type(source.name)[0])

View file

@ -1,3 +1,6 @@
import os
from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _
@ -15,6 +18,10 @@ class Source(BoundsMixin, models.Model):
verbose_name_plural = _('Sources')
default_related_name = 'sources'
@property
def filepath(self):
return os.path.join(settings.SOURCES_ROOT, self.name)
@property
def title(self):
return self.name