
    WwgL                     H    d dl mZ d dlmZ d dlmZ d dlmZ  G d d      Zy)    )settings)get_user_model)set_cid)	set_actorc                   >    e Zd ZdZddZed        Zed        Zd Zy)AuditlogMiddlewarez
    Middleware to couple the request's user to log items. This is accomplished by currying the
    signal receiver with the user from the request (or None if the user is not authenticated).
    Nc                 d    || _         t        t        j                  t              st        d      y )Nz8Setting 'AUDITLOG_DISABLE_REMOTE_ADDR' must be a boolean)get_response
isinstancer   AUDITLOG_DISABLE_REMOTE_ADDRbool	TypeError)selfr
   s     J/var/www/horilla/myenv/lib/python3.12/site-packages/auditlog/middleware.py__init__zAuditlogMiddleware.__init__   s,    ((??FVWW G    c                 `   t         j                  ry | j                  j                  d      s| j                  j                  d      S | j                  j                  d      j                  d      d   }d|v rd|v r|j                  d      d   }|S d|v r|dd  j                  d	      d   }|S )
NzX-Forwarded-ForREMOTE_ADDR,r   .:[   ])r   r   headersgetMETAsplit)requestremote_addrs     r   _get_remote_addrz#AuditlogMiddleware._get_remote_addr   s    00 ""#45<<##M22 #??../@AGGLQO +#"4%++C03K  K%ab///4Q7Kr   c                 b    t        | dd       }t        |t                     r|j                  r|S y )Nuser)getattrr   r   is_authenticated)r   r#   s     r   
_get_actorzAuditlogMiddleware._get_actor'   s-    w-dN,-$2G2GKr   c                     | j                  |      }| j                  |      }t        |       t        ||      5  | j	                  |      cd d d        S # 1 sw Y   y xY w)N)actorr    )r!   r&   r   r   r
   )r   r   r    r#   s       r   __call__zAuditlogMiddleware.__call__.   sU    ++G4w'T{; 	.$$W-	. 	. 	.s   AA)N)	__name__
__module____qualname____doc__r   staticmethodr!   r&   r)    r   r   r   r      s:    
X
  &  .r   r   N)	django.confr   django.contrib.authr   auditlog.cidr   auditlog.contextr   r   r/   r   r   <module>r4      s      .   &-. -.r   