ó
ÄlUdc           @   s|   d  d l  m Z d  d l m Z d  d l m Z d  d l m Z d  d l m	 Z	 d „  Z
 d „  Z d e f d	 „  ƒ  YZ d
 S(   iÿÿÿÿ(   t   signals(   t   curry(   t   registration(   t   fields(   t   AuditLogManagerc         C   sa   xZ t  |  ƒ D]L } y2 t t |  | ƒ t ƒ rD t |  | ƒ j ƒ  n  Wq t k
 rX q Xq Wd  S(   N(   t   dirt
   isinstancet   getattrR   t   disable_trackingt   AttributeError(   t   instancet   attr(    (    sB   /var/www/html/phendo-backend/phendo_python/audit_log/middleware.pyt   _disable_audit_log_managers	   s    c         C   sa   xZ t  |  ƒ D]L } y2 t t |  | ƒ t ƒ rD t |  | ƒ j ƒ  n  Wq t k
 rX q Xq Wd  S(   N(   R   R   R   R   t   enable_trackingR	   (   R
   R   (    (    sB   /var/www/html/phendo-backend/phendo_python/audit_log/middleware.pyt   _enable_audit_log_managers   s    t   UserLoggingMiddlewarec           B   s,   e  Z d  „  Z d „  Z d „  Z d „  Z RS(   c         C   sÆ   | j  d k rÂ t | d ƒ r9 | j j ƒ  r9 | j } n d  } | j j } t |  j | | ƒ } t |  j	 | | ƒ } t
 j j | d |  j | f d t ƒt
 j j | d |  j | f d t ƒn  d  S(	   Nt   GETt   HEADt   OPTIONSt   TRACEt   usert   dispatch_uidt   weak(   R   R   R   R   (   t   methodt   hasattrR   t   is_authenticatedt   Nonet   sessiont   session_keyR   t   _update_pre_save_infot   _update_post_save_infoR    t   pre_savet   connectt	   __class__t   Falset	   post_save(   t   selft   requestR   R   t   update_pre_save_infot   update_post_save_info(    (    sB   /var/www/html/phendo-backend/phendo_python/audit_log/middleware.pyt   process_request   s    %c         C   s<   t  j j d |  j | f ƒ t  j j d |  j | f ƒ | S(   NR   (   R    R   t
   disconnectR!   R#   (   R$   R%   t   response(    (    sB   /var/www/html/phendo-backend/phendo_python/audit_log/middleware.pyt   process_response+   s    c         K   s    t  j t j ƒ } | | k rN x- | j | ƒ D] } t | | j | ƒ q. Wn  t  j t j ƒ } | | k rœ x- | j | ƒ D] } t | | j | ƒ q| Wn  d  S(   N(   R   t   FieldRegistryR   t   LastUserFieldt
   get_fieldst   setattrt   namet   LastSessionKeyField(   R$   R   R   t   senderR
   t   kwargst   registryt   field(    (    sB   /var/www/html/phendo-backend/phendo_python/audit_log/middleware.pyR   0   s    c   	      K   så   | rá t  j t j ƒ } | | k rr xK | j | ƒ D]7 } t | | j | ƒ t | ƒ | j ƒ  t	 | ƒ q4 Wn  t  j t j
 ƒ } | | k rá xK | j | ƒ D]7 } t | | j | ƒ t | ƒ | j ƒ  t	 | ƒ q  Wqá n  d  S(   N(   R   R,   R   t   CreatingUserFieldR.   R/   R0   R   t   saveR   t   CreatingSessionKeyField(	   R$   R   R   R2   R
   t   createdR3   R4   R5   (    (    sB   /var/www/html/phendo-backend/phendo_python/audit_log/middleware.pyR   ;   s    



(   t   __name__t
   __module__R(   R+   R   R   (    (    (    sB   /var/www/html/phendo-backend/phendo_python/audit_log/middleware.pyR      s   			N(   t   django.db.modelsR    t   django.utils.functionalR   t	   audit_logR   t   audit_log.modelsR   t   audit_log.models.managersR   R   R   t   objectR   (    (    (    sB   /var/www/html/phendo-backend/phendo_python/audit_log/middleware.pyt   <module>   s   				