apps.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. from django.apps import AppConfig
  2. from django.core import checks
  3. from .checks import storage_check
  4. class S3FileConfig(AppConfig):
  5. name = "s3file"
  6. verbose_name = "S3File"
  7. def ready(self):
  8. from django import forms
  9. from django.core.files.storage import FileSystemStorage, default_storage
  10. from storages.backends.s3boto3 import S3Boto3Storage
  11. from .forms import S3FileInputMixin
  12. if (
  13. isinstance(default_storage, (S3Boto3Storage, FileSystemStorage))
  14. and S3FileInputMixin not in forms.ClearableFileInput.__bases__
  15. ):
  16. forms.ClearableFileInput.__bases__ = (
  17. S3FileInputMixin,
  18. ) + forms.ClearableFileInput.__bases__
  19. elif S3FileInputMixin in forms.ClearableFileInput.__bases__:
  20. forms.ClearableFileInput.__bases__ = tuple(
  21. cls
  22. for cls in forms.ClearableFileInput.__bases__
  23. if cls is not S3FileInputMixin
  24. )
  25. checks.register(storage_check, checks.Tags.security, deploy=True)