attachments.py 803 B

123456789101112131415161718
  1. from django.http import StreamingHttpResponse
  2. from django.template import RequestContext
  3. from misago.apps.errors import error403, error404
  4. from misago.models import Attachment
  5. from misago.readstrackers import ForumsTracker
  6. from misago.shortcuts import render_to_response
  7. def server(self, attachment, thumb=False):
  8. try:
  9. attachment = Attachment.objects.select_related('forum', 'thread', 'user').get(id=attachment)
  10. if thumb:
  11. response = StreamingHttpResponse(open(attachment.thumb_path), content_type=attachment.content_type)
  12. else:
  13. response = StreamingHttpResponse(open(attachment.file_path), content_type=attachment.content_type)
  14. response['Cache-Control'] = 'no-cache'
  15. return response
  16. except Attachment.DoesNotExist:
  17. pass