conf.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from django.conf import settings
  2. from .defaults import default_headers, default_methods # Kept here for backwards compatibility
  3. class Settings(object):
  4. """
  5. Shadow Django's settings with a little logic
  6. """
  7. @property
  8. def CORS_ALLOW_HEADERS(self):
  9. return getattr(settings, 'CORS_ALLOW_HEADERS', default_headers)
  10. @property
  11. def CORS_ALLOW_METHODS(self):
  12. return getattr(settings, 'CORS_ALLOW_METHODS', default_methods)
  13. @property
  14. def CORS_ALLOW_CREDENTIALS(self):
  15. return getattr(settings, 'CORS_ALLOW_CREDENTIALS', False)
  16. @property
  17. def CORS_PREFLIGHT_MAX_AGE(self):
  18. return getattr(settings, 'CORS_PREFLIGHT_MAX_AGE', 86400)
  19. @property
  20. def CORS_ORIGIN_ALLOW_ALL(self):
  21. return getattr(settings, 'CORS_ORIGIN_ALLOW_ALL', False)
  22. @property
  23. def CORS_ORIGIN_WHITELIST(self):
  24. return getattr(settings, 'CORS_ORIGIN_WHITELIST', ())
  25. @property
  26. def CORS_ORIGIN_REGEX_WHITELIST(self):
  27. return getattr(settings, 'CORS_ORIGIN_REGEX_WHITELIST', ())
  28. @property
  29. def CORS_EXPOSE_HEADERS(self):
  30. return getattr(settings, 'CORS_EXPOSE_HEADERS', ())
  31. @property
  32. def CORS_URLS_REGEX(self):
  33. return getattr(settings, 'CORS_URLS_REGEX', r'^.*$')
  34. @property
  35. def CORS_MODEL(self):
  36. return getattr(settings, 'CORS_MODEL', None)
  37. @property
  38. def CORS_REPLACE_HTTPS_REFERER(self):
  39. return getattr(settings, 'CORS_REPLACE_HTTPS_REFERER', False)
  40. conf = Settings()