
    Wwg                         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 dl
mZmZ d Zed        Zed	        Zed
        Zd Z	 ddZd Zy)    wraps)settings)auditlog_disabled)model_instance_diff)LogEntry)post_logpre_logc                 .     t                fd       }|S )z
    Decorator that passes along disabled in kwargs if any of the following is true:
    - 'auditlog_disabled' from threadlocal is true
    - raw = True and AUDITLOG_DISABLE_ON_RAW_SAVE is True
    c                      	 t        j                         }|s+|j                  d      rt        j                  s	 | i | y y y # t        $ r d}Y ;w xY w)NFraw)r   getLookupErrorr   AUDITLOG_DISABLE_ON_RAW_SAVE)argskwargsauditlog_disabled_valuesignal_handlers      I/var/www/horilla/myenv/lib/python3.12/site-packages/auditlog/receivers.pywrapperzcheck_disable.<locals>.wrapper   s_    	,&7&;&;&=# 'JJu("G"GD+F+ #H '  	,&+#	,s   A AAr   )r   r   s   ` r   check_disabler      s#     >, , N    c                 Z    |r)t        t        j                  j                  || d|       yy)z
    Signal receiver that creates a log entry when a model instance is first saved to the database.

    Direct use is discouraged, connect your model through :py:func:`auditlog.registry.register` instead.
    Nactioninstancesenderdiff_olddiff_new)_create_log_entryr   ActionCREATE)r   r   createdr   s       r   
log_creater$       s-     ??))	
 r   c                    |j                   j                  sp|j                  dd      }| j                  j	                  |j
                        j                         }t        t        j                  j                  || |||       yy)z
    Signal receiver that creates a log entry when a model instance is changed and saved to the database.

    Direct use is discouraged, connect your model through :py:func:`auditlog.registry.register` instead.
    update_fieldsN)pk)r   r   r   r   r   fields_to_check)_stateaddingr   objectsfilterr'   firstr    r   r!   UPDATE)r   r   r   r&   olds        r   
log_updater0   1   sn     ??!!

?D9nn##x{{#399;??)))	
 "r   c                 n    |j                   )t        t        j                  j                  || |d       yy)z
    Signal receiver that creates a log entry when a model instance is deleted from the database.

    Direct use is discouraged, connect your model through :py:func:`auditlog.registry.register` instead.
    Nr   )r'   r    r   r!   DELETEr   r   r   s      r   
log_deleter4   E   s4     {{??))	
 r   c                 p    |j                   *t        t        j                  j                  || ddd       yy)z
    Signal receiver that creates a log entry when a model instance is accessed in a AccessLogDetailView.

    Direct use is discouraged, connect your model through :py:func:`auditlog.registry.register` instead.
    NT)r   r   r   r   r   	force_log)r'   r    r   r!   ACCESSr3   s      r   
log_accessr8   V   s7     {{??))	
 r   Nc                    t        j                  |||       }t        d |D              ry d }d }	d }
	 t        |||      }
|s|
r#t        j
                  j                  || |
|      }	|	s|r t        j                  |||| |||
|	|	d u	       |r|y # t        $ r}|}Y d }~9d }~ww xY w# |	s|r t        j                  |||| |||
|	|	d u	       |r|w xY w)N)r   r   c              3   *   K   | ]  }|d    du   yw)   FN ).0items     r   	<genexpr>z$_create_log_entry.<locals>.<genexpr>p   s     
847e
8s   )r(   )r   changesr6   )r   instance_oldr   errorpre_log_resultsr@   	log_entrylog_created)	r
   sendanyr   r   r+   r$   BaseExceptionr	   )r   r   r   r   r   r(   r6   rC   rB   rD   r@   es               r   r    r    g   s    llO 
8
88EIG%h
  ((33#	 4 I MM!% /#%T1
 K    MM!% /#%T1
 K s)   5B 	B&B!B) !B&&B) )*Cc                 $     t          fd       }|S )z:Return a handler for m2m_changed with field_name enclosed.c                 B   |dvry|dk(  r|d   j                   j                         }n"|d   j                   j                  |d         }|dv r&t        j                   j	                  ||d   d	       y|d
v r&t        j                   j	                  ||d   d       yy)zGHandle m2m_changed and call LogEntry.objects.log_m2m_changes as needed.)post_add
post_clearpost_removeNrM   modelpk_set)pk__in)rL   r   add)rN   rM   delete)r+   allr,   r   log_m2m_changes)signalr   r   changed_queryset
field_names       r   rU   z-make_log_m2m_changes.<locals>.log_m2m_changes   s     BB\!%g66::<%g66==VHEU=V\!,, z"	 44,, z"	 5r   )r   )rX   rU   s   ` r   make_log_m2m_changesrY      s      2 r   )NF)	functoolsr   django.confr   auditlog.contextr   auditlog.diffr   auditlog.modelsr   auditlog.signalsr	   r
   r   r$   r0   r4   r8   r    rY   r<   r   r   <module>r`      so       . - $ .* 
 
  
 
& 
 
 
$ SX+\r   