2023-05-04 04:42:37 +00:00
|
|
|
from users.models import Domain
|
2022-11-17 04:42:25 +00:00
|
|
|
|
2022-11-06 20:48:04 +00:00
|
|
|
|
2023-05-04 04:42:37 +00:00
|
|
|
class DomainMiddleware:
|
2022-11-06 20:48:04 +00:00
|
|
|
"""
|
2023-05-04 04:42:37 +00:00
|
|
|
Tries to attach a Domain object to every incoming request, if one matches.
|
2022-11-06 20:48:04 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, get_response):
|
|
|
|
self.get_response = get_response
|
|
|
|
|
|
|
|
def __call__(self, request):
|
2023-05-04 04:42:37 +00:00
|
|
|
request.domain = None
|
|
|
|
if "host" in request.headers:
|
|
|
|
request.domain = Domain.get_domain(request.headers["host"])
|
2022-11-06 20:48:04 +00:00
|
|
|
response = self.get_response(request)
|
|
|
|
return response
|