Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

34 righe
1013 B

  1. from __future__ import unicode_literals
  2. import webnotes
  3. import os
  4. from werkzeug.wsgi import SharedDataMiddleware
  5. from webnotes.utils import get_site_name, get_site_path, get_site_base_path, get_path, cstr
  6. class StaticDataMiddleware(SharedDataMiddleware):
  7. def __call__(self, environ, start_response):
  8. self.environ = environ
  9. return super(StaticDataMiddleware, self).__call__(environ, start_response)
  10. def get_directory_loader(self, directory):
  11. def loader(path):
  12. import conf
  13. path = cstr(path)
  14. fail = True
  15. if hasattr(conf, 'sites_dir'):
  16. site = get_site_name(self.environ.get('HTTP_HOST'))
  17. possible_site_path = get_path(directory, path, base=os.path.join(conf.sites_dir, site))
  18. if os.path.isfile(possible_site_path):
  19. path = possible_site_path
  20. fail = False
  21. if fail and os.path.isfile(get_path(directory, path)):
  22. path = get_path(directory, path)
  23. fail = False
  24. if fail:
  25. return None, None
  26. return os.path.basename(path), self._opener(path)
  27. return loader