attachments.py 935 B

1234567891011121314151617181920
  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(hash_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. if not attachment.is_image:
  16. response['Content-Disposition'] = 'attachment;filename="%s"' % attachment.name
  17. return response
  18. except Attachment.DoesNotExist:
  19. pass