def decide_if_cors(sender, request, **kwargs):
 host = urlparse(request.META['HTTP_ORIGIN']).netloc.split(':')[0]
 valid_url = False
 for url in WHITELIST_URLS:
  if request.path_info.startswith(url):
   valid_url = True
 if valid_url:
  project_slug = request.GET.get('project', None)
  try:
   project = Project.objects.get(slug=project_slug)
  except Project.DoesNotExist:
   log.warning('Invalid project passed to domain. [{project}:{domain}'.format(project=project_slug, domain=host))
   return False
  domain = Domain.objects.filter(domain__icontains=host, project=project)
  if domain.exists():
   return True
 return False

def decide_if_cors ( sender , request , ** kwargs ) : host = urlparse ( request . META [ 'HTTP_ORIGIN' ] ) . netloc . split ( ':' ) [ 0 ] valid_url = False for url in WHITELIST_URLS : if request . path_info . startswith ( url ) : valid_url = True if valid_url : project_slug = request . GET . get ( 'project' , None ) try : project = Project . objects . get ( slug = project_slug ) except Project . DoesNotExist : log . warning ( 'Invalid project passed to domain. [{project}:{domain}' . format ( project = project_slug , domain = host ) ) return False domain = Domain . objects . filter ( domain__icontains = host , project = project ) if domain . exists ( ) : return True return False
decide whether a request should be given cors access .