Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

templates.py 1.1KB

1234567891011121314151617181920212223242526272829303132333435
  1. import copy
  2. from django.conf import settings
  3. from . import Error, Tags, register
  4. E001 = Error(
  5. "You have 'APP_DIRS': True in your TEMPLATES but also specify 'loaders' "
  6. "in OPTIONS. Either remove APP_DIRS or remove the 'loaders' option.",
  7. id='templates.E001',
  8. )
  9. E002 = Error(
  10. "'string_if_invalid' in TEMPLATES OPTIONS must be a string but got: {} ({}).",
  11. id="templates.E002",
  12. )
  13. @register(Tags.templates)
  14. def check_setting_app_dirs_loaders(app_configs, **kwargs):
  15. return [E001] if any(
  16. conf.get('APP_DIRS') and 'loaders' in conf.get('OPTIONS', {})
  17. for conf in settings.TEMPLATES
  18. ) else []
  19. @register(Tags.templates)
  20. def check_string_if_invalid_is_string(app_configs, **kwargs):
  21. errors = []
  22. for conf in settings.TEMPLATES:
  23. string_if_invalid = conf.get('OPTIONS', {}).get('string_if_invalid', '')
  24. if not isinstance(string_if_invalid, str):
  25. error = copy.copy(E002)
  26. error.msg = error.msg.format(string_if_invalid, type(string_if_invalid).__name__)
  27. errors.append(error)
  28. return errors