]> git.parisson.com Git - telemeta.git/commitdiff
Merge branch 'feature/html5' into feature/dj1.8
authorThomas Fillon <thomas@parisson.com>
Tue, 11 Apr 2017 14:20:04 +0000 (16:20 +0200)
committerThomas Fillon <thomas@parisson.com>
Tue, 11 Apr 2017 14:20:04 +0000 (16:20 +0200)
Conflicts:
telemeta/views/core.py
telemeta/views/item.py

1  2 
app/scripts/app.sh
telemeta/views/admin.py
telemeta/views/collection.py
telemeta/views/core.py

Simple merge
index c0e84bea9b5f4906fc01cd47a7bc49dd6e4c6ab1,ec579eb69cf1648a700242786cc4d3db7096d7e6..e4119e314a7d4d37a78e5bf895884a5af0ac0f9f
  # Authors: Olivier Guilyardi <olivier@samalyse.com>
  #          Guillaume Pellerin <yomguy@parisson.com>
  
 +from django.apps import apps
  
  from telemeta.views.core import *
+ import telemeta.models
  
 +
  class AdminView(object):
      """Provide Admin web UI methods"""
  
index 703b4ee318e8e7829f15f92efd979e761d07e6ca,d440221af4f44b5ddf3bea496ba001056b394fef..333a59f2046dcc6d4aed3e4302187426824a4eee
  
  
  from telemeta.views.core import *
+ from telemeta.views.core import serve_media
  from telemeta.views.epub import *
  
 +
  class CollectionView(object):
      """Provide Collections web UI methods"""
  
index e6b77f8cfa6a0238149fa46cfe4b50e2933dd03b,32aa0b81420f76bc1c36d25d83bde62988209100..6857ccae83a0ff822a18e31271429333ed29dca0
@@@ -38,7 -41,8 +41,8 @@@ from django.utils.decorators import met
  from django.contrib.auth import authenticate, login
  from django.template import RequestContext, loader
  from django import template
--from django.http import HttpResponse, HttpResponseRedirect, StreamingHttpResponse
 -# from django.http import FileResponse -> introduced in Django 1.7.4
++from django.http import HttpResponse, HttpResponseRedirect
++from django.http import FileResponse
  from django.http import Http404
  from django.shortcuts import render_to_response, redirect, get_object_or_404
  from django.views.generic import *
@@@ -91,59 -95,55 +95,45 @@@ class TelemetaBaseMixin(object)
      cache_tmp = TelemetaCache(getattr(settings, 'FILE_UPLOAD_TEMP_DIR', os.path.join(MEDIA_ROOT, 'tmp')))
  
  
- class FixedFileWrapper(FileWrapper):
+ def serve_media(filename, content_type="", buffering=True):
+     if not settings.DEBUG:
+         return nginx_media_accel(filename, content_type=content_type,
+                                  buffering=buffering)
+     else:
 -        response = StreamingHttpResponse(stream_from_file(filename), content_type=content_type)
++        response = FileResponse(open(filename, 'rb'))
+         response['Content-Disposition'] = 'attachment; ' + 'filename=' + filename
+         return response
  
-     def __iter__(self):
-         self.filelike.seek(0)
-         return self
  
- def send_file(request, filename, content_type='image/jpeg'):
-     """
-     Send a file through Django without loading the whole file into
-     memory at once. The FileWrapper will turn the file object into an
-     iterator for chunks of 8KB.
-     """
-     wrapper = FixedFileWrapper(file(filename, 'rb'))
-     response = StreamingHttpResponse(wrapper, content_type=content_type)
-     response['Content-Length'] = os.path.getsize(filename)
-     return response
- def nginx_media_accel(request, filename):
-     """Send a protected medie file through nginx with X-Accel-Redirect"""
+ def nginx_media_accel(media_path, content_type="", buffering=True):
+     """Send a protected media file through nginx with X-Accel-Redirect"""
  
      response = HttpResponse()
-     url = settings.MEDIA_URL + filename
-     # let nginx determine the correct content type
-     response['Content-Type'] = ""
+     url = settings.MEDIA_URL + os.path.relpath(media_path, settings.MEDIA_ROOT)
+     filename = os.path.basename(media_path)
+     response['Content-Disposition'] = "attachment; filename=%s" % (filename)
+     response['Content-Type'] = content_type
      response['X-Accel-Redirect'] = url
+     if not buffering:
+         response['X-Accel-Buffering'] = 'no'
      return response
  
  
 -def render(request, template, data=None, mimetype=None):
 +def render(request, template, data=None, content_type=None):
      return render_to_response(template, data, context_instance=RequestContext(request),
 -                              mimetype=mimetype)
 +                              content_type=content_type)
 +
  
  def stream_from_processor(decoder, encoder, flag):
      pipe = decoder | encoder
      for chunk in pipe.stream():
          yield chunk
      flag.value = True
      flag.save()
--
--
--def stream_from_file(file):
--    chunk_size = 0x100000
--    f = open(file, 'r')
--    while True:
--        chunk = f.read(chunk_size)
--        if not len(chunk):
--            f.close()
--            break
--        yield chunk
--
++    
  
  def get_item_access(item, user):
      # Item access rules according to this workflow: