Ver Mensaje Individual
  #1 (permalink)  
Antiguo 15/01/2014, 10:04
minimal
 
Fecha de Ingreso: diciembre-2011
Mensajes: 408
Antigüedad: 13 años
Puntos: 18
django modo dificl donde esta _cached_user

hola estoy sobreescribiendo el la app de auth de django es que me he creado un modelo llamado customer el cual heredo de user abstract he sobrescribido algunos metodos pero revisando el middleware de django de app auth


Código Python:
Ver original
  1. from django.contrib import auth
  2. from django.contrib.auth import load_backend
  3. from django.contrib.auth.backends import RemoteUserBackend
  4. from django.core.exceptions import ImproperlyConfigured
  5. from django.utils.functional import SimpleLazyObject
  6.  
  7.  
  8. def get_user(request):
  9.     if not hasattr(request, '_cached_user'):
  10.         request._cached_user = auth.get_user(request)
  11.     return request._cached_user
  12.  
  13.  
  14. class AuthenticationMiddleware(object):
  15.     def process_request(self, request):
  16.         assert hasattr(request, 'session'), "The Django authentication middleware requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.sessions.middleware.SessionMiddleware'."
  17.  
  18.         request.user = SimpleLazyObject(lambda: get_user(request))
  19.  
  20.  
  21. class RemoteUserMiddleware(object):
  22.     """
  23.    Middleware for utilizing Web-server-provided authentication.
  24.  
  25.    If request.user is not authenticated, then this middleware attempts to
  26.    authenticate the username passed in the ``REMOTE_USER`` request header.
  27.    If authentication is successful, the user is automatically logged in to
  28.    persist the user in the session.
  29.  
  30.    The header used is configurable and defaults to ``REMOTE_USER``.  Subclass
  31.    this class and change the ``header`` attribute if you need to use a
  32.    different header.
  33.    """
  34.  
  35.     # Name of request header to grab username from.  This will be the key as
  36.     # used in the request.META dictionary, i.e. the normalization of headers to
  37.     # all uppercase and the addition of "HTTP_" prefix apply.
  38.     header = "REMOTE_USER"
  39.  
  40.     def process_request(self, request):
  41.         # AuthenticationMiddleware is required so that request.user exists.
  42.         if not hasattr(request, 'user'):
  43.             raise ImproperlyConfigured(
  44.                 "The Django remote user auth middleware requires the"
  45.                 " authentication middleware to be installed.  Edit your"
  46.                 " MIDDLEWARE_CLASSES setting to insert"
  47.                 " 'django.contrib.auth.middleware.AuthenticationMiddleware'"
  48.                 " before the RemoteUserMiddleware class.")
  49.         try:
  50.             username = request.META[self.header]
  51.         except KeyError:
  52.             # If specified header doesn't exist then remove any existing
  53.             # authenticated remote-user, or return (leaving request.user set to
  54.             # AnonymousUser by the AuthenticationMiddleware).
  55.             if request.user.is_authenticated():
  56.                 try:
  57.                     stored_backend = load_backend(request.session.get(
  58.                         auth.BACKEND_SESSION_KEY, ''))
  59.                     if isinstance(stored_backend, RemoteUserBackend):
  60.                         auth.logout(request)
  61.                 except ImproperlyConfigured as e:
  62.                     # backend failed to load
  63.                     auth.logout(request)
  64.             return
  65.         # If the user is already authenticated and that user is the user we are
  66.         # getting passed in the headers, then the correct user is already
  67.         # persisted in the session and we don't need to continue.
  68.         if request.user.is_authenticated():
  69.             if request.user.get_username() == self.clean_username(username, request):
  70.                 return
  71.         # We are seeing this user for the first time in this session, attempt
  72.         # to authenticate the user.
  73.         user = auth.authenticate(remote_user=username)
  74.         if user:
  75.             # User is valid.  Set request.user and persist user in the session
  76.             # by logging the user in.
  77.             request.user = user
  78.             auth.login(request, user)
  79.  
  80.     def clean_username(self, username, request):
  81.         """
  82.        Allows the backend to clean the username, if the backend defines a
  83.        clean_username method.
  84.        """
  85.         backend_str = request.session[auth.BACKEND_SESSION_KEY]
  86.         backend = auth.load_backend(backend_str)
  87.         try:
  88.             username = backend.clean_username(username)
  89.         except AttributeError:  # Backend has no clean_username method.
  90.             pass
  91.         return username


no se en que clase esta _cached_user

lo que quiero crear es una variable del tipo request.customer ya tengo el context procesor es este