# Path: tenant_schemas/postgresql_backend/base.py
# class FakeTenant:
#     """
#     We can't import any db model in a backend (apparently?), so this class is used
#     for wrapping schema names in a tenant-like structure.
#     """
#     def __init__(self, schema_name):
#         self.schema_name = schema_name


from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.db import connection
from django.template.loaders import cached, filesystem
from ordered_set import OrderedSet
from tenant_schemas.postgresql_backend.base import FakeTenant
"""
Adaptations of the cached and filesystem template loader working in a
multi-tenant setting
"""



class CachedLoader(cached.Loader):
    def cache_key(self, *args, **kwargs):
        key = super(CachedLoader, self).cache_key(*args, **kwargs)

        if not connection.tenant or isinstance(connection.tenant, FakeTenant):
            return key

        return "-".join([connection.tenant.schema_name, key])


class FilesystemLoader(filesystem.Loader):
    def get_dirs(self):
        dirs = OrderedSet(super(FilesystemLoader, self).get_dirs())


# Path: tenant_schemas/postgresql_backend/base.py
# class FakeTenant:
#     """
#     We can't import any db model in a backend (apparently?), so this class is used
#     for wrapping schema names in a tenant-like structure.
#     """
#     def __init__(self, schema_name):
#         self.schema_name = schema_name


# Path: tenant_schemas/template_loaders.py
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.db import connection
from django.template.loaders import cached, filesystem
from ordered_set import OrderedSet
from tenant_schemas.postgresql_backend.base import FakeTenant

"""
Adaptations of the cached and filesystem template loader working in a
multi-tenant setting
"""



class CachedLoader(cached.Loader):
    def cache_key(self, *args, **kwargs):
        key = super(CachedLoader, self).cache_key(*args, **kwargs)

        if not connection.tenant or isinstance(connection.tenant, FakeTenant):
            return key

        return "-".join([connection.tenant.schema_name, key])


class FilesystemLoader(filesystem.Loader):
    def get_dirs(self):
        dirs = OrderedSet(super(FilesystemLoader, self).get_dirs())


        if connection.tenant and not isinstance(connection.tenant, FakeTenant):