選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

33 行
986 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
  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. fail = True
  14. if hasattr(conf, 'sites_dir'):
  15. site = get_site_name(self.environ.get('HTTP_HOST'))
  16. possible_site_path = get_path(directory, path, base=os.path.join(conf.sites_dir, site))
  17. if os.path.isfile(possible_site_path):
  18. path = possible_site_path
  19. fail = False
  20. if fail and os.path.isfile(get_path(directory, path)):
  21. path = get_path(directory, path)
  22. fail = False
  23. if fail:
  24. return None, None
  25. return os.path.basename(path), self._opener(path)
  26. return loader