add vimeo
[redakcja.git] / apps / catalogue / ebook_utils.py
1 # -*- coding: utf-8 -*-
2 from django.http import HttpResponse
3
4
5 def serve_file(file_path, name, mime_type):
6     def read_chunks(f, size=8192):
7         chunk = f.read(size)
8         while chunk:
9             yield chunk
10             chunk = f.read(size)
11
12     response = HttpResponse(content_type=mime_type)
13     response['Content-Disposition'] = 'attachment; filename=%s' % name
14     with open(file_path) as f:
15         for chunk in read_chunks(f):
16             response.write(chunk)
17     return response