
    Bsi+                         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      ^/var/www/python-projects/worksol/worksolenv/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                 x    |r8t        t        j                  j                  || d|t        j
                         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use_json_for_changes)_create_log_entryr   ActionCREATEr   AUDITLOG_STORE_JSON_CHANGES)r   r   createdr   s       r   
log_creater&       s6     ??))!)!E!E	
 r   c           	      H   |j                   j                  s|j                  |j                  dd      }| j                  j                  |j                        j                         }t        t        j                  j                  || |||t        j                         y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.
    Nupdate_fields)pk)r   r   r   r   r   fields_to_checkr    )_stateaddingr)   r   _default_managerfilterfirstr!   r   r"   UPDATEr   r$   )r   r   r   r(   olds        r   
log_updater2   2   s     ??!!hkk&=

?D9%%,,,<BBD??)))!)!E!E	
 '>!r   c                     |j                   8t        t        j                  j                  || |dt
        j                         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"   DELETEr   r$   r   r   r   s      r   
log_deleter6   G   s=     {{??))!)!E!E	
 r   c           	          |j                   9t        t        j                  j                  || dddt
        j                         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_logr    )r)   r!   r   r"   ACCESSr   r$   r5   s      r   
log_accessr:   Y   s@     {{??))!)!E!E	
 r   Nc                    t        j                  |||       }t        d |D              ry d }	d }
d }	 t        ||||      }|s|r#t        j
                  j                  || ||      }
|
s|	r/t        j                  |||| |	|||
|
d ut        j                  
       |	r|	y # t        $ r}|}	Y d }~Hd }~ww xY w# |
s|	r/t        j                  |||| |	|||
|
d ut        j                  
       |	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>{   s     
847e
8s   )r*   r    )r   changesr8   )	r   instance_oldr   errorpre_log_resultsrB   	log_entrylog_createdr    )r
   sendanyr   r   objectsr&   BaseExceptionr	   r   r$   )r   r   r   r   r   r*   r8   r    rE   rD   rF   rB   es                r   r!   r!   k   s4    llO 
8
88EIG %+!5	
  ((33#	 4 I MM!% /#%T1%-%I%I K !   MM!% /#%T1%-%I%I K s)   6B! !	B6*B1,B9 1B66B9 99C2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_removeNrP   modelpk_set)pk__in)rO   r   add)rQ   rP   delete)r-   allr.   r   rJ   log_m2m_changes)signalr   r   changed_queryset
field_names       r   rX   z-make_log_m2m_changes.<locals>.log_m2m_changes   s     BB\!%g??CCE%g??FFh'  G   \!,, z"	 44,, z"	 5r   )r   )r[   rX   s   ` r   make_log_m2m_changesr\      s      6 r   )NFF)	functoolsr   django.confr   auditlog.contextr   auditlog.diffr   auditlog.modelsr   auditlog.signalsr	   r
   r   r&   r2   r6   r:   r!   r\   r>   r   r   <module>rc      ss       . - $ .* 
 
" 
 
( 
 
"
0 6rr   