1
|
from django.conf import settings, UserSettingsHolder
|
2
|
|
3
|
from tenant_schemas.middleware import TenantMiddleware
|
4
|
|
5
|
SENTINEL = object()
|
6
|
|
7
|
class EOTenantMiddleware(TenantMiddleware):
|
8
|
def __init__(self, *args, **kwargs):
|
9
|
self.wrapped = settings._wrapped
|
10
|
|
11
|
def process_request(self, request):
|
12
|
super(EOTenantMiddleware, self).process_request(request)
|
13
|
override = UserSettingsHolder(self.wrapped)
|
14
|
for client_settings in request.tenant.clientsetting_set.all():
|
15
|
setattr(override, client_settings.name, client_settings.json)
|
16
|
settings._wrapped = override
|
17
|
|
18
|
def process_response(self, request, response):
|
19
|
settings._wrapped = self.wrapped
|
20
|
return response
|