Revision 73b85f5d
Added by Benjamin Dauvergne over 11 years ago
| entrouvert/djommon/multitenant/app_settings.py | ||
|---|---|---|
|
import sys
|
||
|
|
||
|
|
||
|
class AppSettings:
|
||
|
@property
|
||
|
def settings(self):
|
||
|
if not hasattr(self, '_settings'):
|
||
|
from django.conf import settings
|
||
|
self._settings = settings
|
||
|
return self._settings
|
||
|
|
||
|
@property
|
||
|
def MULTITENANT_TEMPLATE_DIRS(self):
|
||
|
return self.settings.MULTITENANT_TEMPLATE_DIRS
|
||
|
|
||
|
|
||
|
app_settings = AppSettings()
|
||
|
app_settings.__name__ = __name__
|
||
|
sys.modules[__name__] = app_settings
|
||
| entrouvert/djommon/multitenant/template_loader.py | ||
|---|---|---|
|
from django.utils._os import safe_join
|
||
|
from django.db import connection
|
||
|
|
||
|
from . import app_settings
|
||
|
|
||
|
class CachedLoader(BaseLoader):
|
||
|
is_usable = True
|
||
|
|
||
| ... | ... | |
|
return
|
||
|
if not template_dirs:
|
||
|
try:
|
||
|
template_dirs = app_settings.MULTITENANT_TEMPLATE_DIRS
|
||
|
template_dirs = settings.TENANT_TEMPLATE_DIRS
|
||
|
except AttributeError:
|
||
|
raise ImproperlyConfigured('To use %s.%s you must define the MULTITENANT_TEMPLATE_DIRS' % (__name__, FilesystemLoader.__name__))
|
||
|
raise ImproperlyConfigured('To use %s.%s you must define the TENANT_TEMPLATE_DIRS' % (__name__, FilesystemLoader.__name__))
|
||
|
for template_dir in template_dirs:
|
||
|
try:
|
||
|
yield safe_join(template_dir, connection.tenant.domain_url, template_name)
|
||
| ... | ... | |
|
if tried:
|
||
|
error_msg = "Tried %s" % tried
|
||
|
else:
|
||
|
error_msg = "Your TEMPLATE_DIRS setting is empty. Change it to point to at least one template directory."
|
||
|
error_msg = "Your TENANT_TEMPLATE_DIRS setting is empty. Change it to point to at least one template directory."
|
||
|
raise TemplateDoesNotExist(error_msg)
|
||
|
load_template_source.is_usable = True
|
||
Also available in: Unified diff
In FileSystemLoader rename settings from MULTITENANT_TEMPLATE_DIRS to TENANT_TEMPLATE_DIRS to unformize with other settings
refs #5106