From: Guillaume Pellerin Date: Tue, 29 Apr 2014 13:26:21 +0000 (+0200) Subject: server: add a streaming function to ResultGrapherView X-Git-Tag: 0.5.5~1^2~29 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=70c47cf77c8f12d9e42b965d13731e2ca833ec24;p=timeside.git server: add a streaming function to ResultGrapherView --- diff --git a/timeside/server/models.py b/timeside/server/models.py index 0266d51..a378e62 100644 --- a/timeside/server/models.py +++ b/timeside/server/models.py @@ -237,6 +237,14 @@ class Task(BaseResource): proc.render(output=result.file.path) result.status_setter(4) + if proc.type == 'encoder': + parameters = {} + preset, c = Preset.objects.get_or_create(processor=processor, parameters=unicode(parameters)) + result, c = Result.objects.get_or_create(preset=preset, item=item) + result.file = path + str(result.uuid) + '.' + proc.file_extension + proc.render(output=result.file.path) + result.status_setter(4) + del proc # except: diff --git a/timeside/server/views.py b/timeside/server/views.py index 9cea65c..141b76f 100644 --- a/timeside/server/views.py +++ b/timeside/server/views.py @@ -10,6 +10,17 @@ from timeside.server.models import * from timeside.server.serializers import * +def stream_from_file(file): + chunk_size = 0x10000 + f = open(file, 'r') + while True: + chunk = f.read(chunk_size) + if not len(chunk): + f.close() + break + yield chunk + + class SelectionViewSet(viewsets.ModelViewSet): model = Selection @@ -84,8 +95,8 @@ class ResultAnalyzerView(View): class ResultGrapherView(View): - model = Item + model = Result def get(self, request, *args, **kwargs): result = Result.objects.get(pk=kwargs['pk']) - return HttpResponse(result.file, mimetype='image/png') + return HttpResponse(stream_from_file(result.file.path), mimetype='image/png')