License
=======
-CeCILL v2, compatible with GPL v2 (see `LICENSE <http://github.com/yomguy/Telemeta/blob/master/LICENSE`_)
+CeCILL v2, compatible with GPL v2 (see `LICENSE <http://github.com/yomguy/Telemeta/blob/master/LICENSE>`_)
Sponsors
from django.contrib.auth.forms import UserChangeForm
from django.core.exceptions import ObjectDoesNotExist
from django.contrib.syndication.views import Feed
+from django.core.servers.basehttp import FileWrapper
from telemeta.models import *
import telemeta.models
# TOOLS
+class FixedFileWrapper(FileWrapper):
+ 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 = HttpResponse(wrapper, content_type=content_type)
+ response['Content-Length'] = os.path.getsize(filename)
+ return response
+
def render(request, template, data = None, mimetype = None):
return render_to_response(template, data, context_instance=RequestContext(request),
mimetype=mimetype)