django scopes x django sites framework
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
from django.http import Http404
|
|
|
|
from django_scopes import scope
|
|
|
|
|
|
|
|
from scopedsites.models import Domain
|
|
|
|
|
|
|
|
|
|
|
|
class DomainScopeMiddleware:
|
|
|
|
def __init__(self, get_response):
|
|
|
|
self.get_response = get_response
|
|
|
|
|
|
|
|
def __call__(self, request):
|
|
|
|
d = Domain.get_from_request(request)
|
|
|
|
|
|
|
|
with scope(domain=d):
|
|
|
|
response = self.get_response(request)
|
|
|
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
|
|
class DomainAutoCreateMiddleware:
|
|
|
|
def __init__(self, get_response):
|
|
|
|
self.get_response = get_response
|
|
|
|
|
|
|
|
def __call__(self, request):
|
|
|
|
try:
|
|
|
|
Domain.get_from_request(request)
|
|
|
|
except Http404:
|
|
|
|
Domain.objects.create(fqdn=request.META.get('HTTP_HOST'))
|