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.
 
 
 
 

17 lines
656 B

# -*- coding: utf-8 -*-
from django.utils.functional import SimpleLazyObject
from .models import get_profile
def _get_profile(request):
if not hasattr(request, '_cached_profile'):
request._cached_profile = get_profile(request.user)
return request._cached_profile
class ProfileMiddleware(object):
def process_request(self, request):
assert hasattr(request, 'user'), "The Profile middleware requires authentication middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.auth.middleware.AuthenticationMiddleware'."
request.profile = SimpleLazyObject(lambda: _get_profile(request))