def raw_file(request, attachment_id, filename):
 qs = Attachment.objects.select_related('current_revision')
 attachment = get_object_or_404(qs, pk=attachment_id)
 if (attachment.current_revision is None):
  raise Http404
 if (request.get_host() == settings.ATTACHMENT_HOST):
  rev = attachment.current_revision
  if settings.DEBUG:
   rev.file.read(rev.file.DEFAULT_CHUNK_SIZE)
  response = StreamingHttpResponse(rev.file, content_type=rev.mime_type)
  response['Last-Modified'] = convert_to_http_date(rev.created)
  try:
   response['Content-Length'] = rev.file.size
  except OSError:
   pass
  response['X-Frame-Options'] = ('ALLOW-FROM %s' % settings.DOMAIN)
  return response
 else:
  return redirect(attachment.get_file_url(), permanent=True)

def raw_file ( request , attachment_id , filename ) : qs = Attachment . objects . select_related ( 'current_revision' ) attachment = get_object_or_404 ( qs , pk = attachment_id ) if ( attachment . current_revision is None ) : raise Http404 if ( request . get_host ( ) == settings . ATTACHMENT_HOST ) : rev = attachment . current_revision if settings . DEBUG : rev . file . read ( rev . file . DEFAULT_CHUNK_SIZE ) response = StreamingHttpResponse ( rev . file , content_type = rev . mime_type ) response [ 'Last-Modified' ] = convert_to_http_date ( rev . created ) try : response [ 'Content-Length' ] = rev . file . size except OSError : pass response [ 'X-Frame-Options' ] = ( 'ALLOW-FROM %s' % settings . DOMAIN ) return response else : return redirect ( attachment . get_file_url ( ) , permanent = True )
serve up an attachments file .