filer.server.backends.default: 19 total statements, 0.0% covered

Generated: Wed 2013-03-13 10:33 CET

Source file: /media/Envs/Envs/filer-gallery/lib/python2.7/site-packages/filer/server/backends/default.py

Stats: 0 executed, 13 missed, 6 excluded, 13 ignored

  1. #-*- coding: utf-8 -*-
  2. import os
  3. import stat
  4. from django.http import Http404, HttpResponse, HttpResponseNotModified
  5. from django.utils.http import http_date
  6. from django.views.static import was_modified_since
  7. from filer.server.backends.base import ServerBase
  8. class DefaultServer(ServerBase):
  9. """
  10. Serve static files from the local filesystem through django.
  11. This is a bad idea for most situations other than testing.
  12. This will only work for files that can be accessed in the local filesystem.
  13. """
  14. def serve(self, request, file_obj, **kwargs):
  15. fullpath = file_obj.path
  16. # the following code is largely borrowed from `django.views.static.serve`
  17. # and django-filetransfers: filetransfers.backends.default
  18. if not os.path.exists(fullpath):
  19. raise Http404('"%s" does not exist' % fullpath)
  20. # Respect the If-Modified-Since header.
  21. statobj = os.stat(fullpath)
  22. mimetype = self.get_mimetype(fullpath)
  23. if not was_modified_since(request.META.get('HTTP_IF_MODIFIED_SINCE'),
  24. statobj[stat.ST_MTIME], statobj[stat.ST_SIZE]):
  25. return HttpResponseNotModified(mimetype=mimetype)
  26. response = HttpResponse(open(fullpath, 'rb').read(), mimetype=mimetype)
  27. response["Last-Modified"] = http_date(statobj[stat.ST_MTIME])
  28. self.default_headers(request=request, response=response, file_obj=file_obj, **kwargs)
  29. return response