PageRenderTime 125ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/django/contrib/staticfiles/storage.py

https://code.google.com/p/mango-py/
Python | 56 lines | 32 code | 7 blank | 17 comment | 5 complexity | 9a1f41fd5b0629cfb56365571d2dc186 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. import os
  2. from django.conf import settings
  3. from django.core.exceptions import ImproperlyConfigured
  4. from django.core.files.storage import FileSystemStorage
  5. from django.utils.importlib import import_module
  6. from django.contrib.staticfiles import utils
  7. class StaticFilesStorage(FileSystemStorage):
  8. """
  9. Standard file system storage for static files.
  10. The defaults for ``location`` and ``base_url`` are
  11. ``STATIC_ROOT`` and ``STATIC_URL``.
  12. """
  13. def __init__(self, location=None, base_url=None, *args, **kwargs):
  14. if location is None:
  15. location = settings.STATIC_ROOT
  16. if base_url is None:
  17. base_url = settings.STATIC_URL
  18. if not location:
  19. raise ImproperlyConfigured("You're using the staticfiles app "
  20. "without having set the STATIC_ROOT setting.")
  21. # check for None since we might use a root URL (``/``)
  22. if base_url is None:
  23. raise ImproperlyConfigured("You're using the staticfiles app "
  24. "without having set the STATIC_URL setting.")
  25. utils.check_settings()
  26. super(StaticFilesStorage, self).__init__(location, base_url, *args, **kwargs)
  27. class AppStaticStorage(FileSystemStorage):
  28. """
  29. A file system storage backend that takes an app module and works
  30. for the ``static`` directory of it.
  31. """
  32. prefix = None
  33. source_dir = 'static'
  34. def __init__(self, app, *args, **kwargs):
  35. """
  36. Returns a static file storage if available in the given app.
  37. """
  38. # app is the actual app module
  39. self.app_module = app
  40. # We special case the admin app here since it has its static files
  41. # in 'media' for historic reasons.
  42. if self.app_module == 'django.contrib.admin':
  43. self.prefix = 'admin'
  44. self.source_dir = 'media'
  45. mod = import_module(self.app_module)
  46. mod_path = os.path.dirname(mod.__file__)
  47. location = os.path.join(mod_path, self.source_dir)
  48. super(AppStaticStorage, self).__init__(location, *args, **kwargs)