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.
 
 
 

19 lines
555 B

from django.http import Http404
from django.utils.deprecation import MiddlewareMixin
from leftists.models import Domain
class DomainAutoCreateMiddleware(MiddlewareMixin):
def __init__(self, get_response):
super().__init__(get_response)
self.cache = set()
def process_request(self, r):
if (host := r.get_host()) in self.cache:
return
try:
Domain.get_from_request(r)
self.cache.add(host)
except Domain.DoesNotExist:
Domain.objects.create(fqdn=host.lower())