def serve_protected_file(request, path):
 try:
  file_obj = File.objects.get(file=path, is_public=False)
 except File.DoesNotExist:
  raise Http404('File not found')
 if (not file_obj.has_read_permission(request)):
  if settings.DEBUG:
   raise PermissionDenied
  else:
   raise Http404('File not found')
 return server.serve(request, file_obj=file_obj.file, save_as=False)

def serve_protected_file ( request , path ) : try : file_obj = File . objects . get ( file = path , is_public = False ) except File . DoesNotExist : raise Http404 ( 'File not found' ) if ( not file_obj . has_read_permission ( request ) ) : if settings . DEBUG : raise PermissionDenied else : raise Http404 ( 'File not found' ) return server . serve ( request , file_obj = file_obj . file , save_as = False )
serve protected files to authenticated users with read permissions .