Ë
    £2Úi=  ã                   ó�   — d dl mZ d dlmZmZmZmZmZ d dlm	Z	 d dl
mZmZ d„ Zd„ Zd„ Zd„ Zd	„ Z	 	 	 	 	 dd„Z	 	 	 	 	 dd„Zd„ Zy
)é    )Útransaction)ÚCaseÚ
ForeignKeyÚManyToManyFieldÚQÚWhen)Úmodel_to_dict)ÚAlternativeManagerErrorÚNotHistoricalModelErrorc                 ó8  — i }t        | «      }| j                  �| n|}t        |«      }|j                  j                  j
                  D �cg c]  }|j                  ‘Œ }}| j                  j
                  D ]W  }|j                  |vrŒt        | |j                  «      }|j                  du r|€Œ9|||j                  <   ŒI|||j                  <   ŒY  |j                  di |¤Žj                  d«      j                  «       }	||	_        |	j                  «        y c c}w )NTz-history_date© )ÚtypeÚpkÚget_history_manager_for_modelÚmodelÚ_metaÚfieldsÚattnameÚgetattrÚprimary_keyÚfilterÚorder_byÚfirstÚhistory_change_reasonÚsave)
ÚinstanceÚreasonÚattrsr   ÚmanagerÚhistoryÚfieldÚhistory_fieldsÚvalueÚrecords
             úK/var/www/html/acx/venv/lib/python3.12/site-packages/simple_history/utils.pyÚupdate_change_reasonr&      sù   € Ø€EÜ�‹N€EØ"Ÿ+™+Ð1‰h°u€GÜ+¨GÓ4€GØ18·±×1DÑ1D×1KÑ1KÖL¨�e—m“mÐL€NÐLØ—‘×&Ñ&ò )ˆØ�=‰= Ñ.ØÜ˜ %§-¡-Ó0ˆØ×Ñ Ñ$ØÑ Ø',��e—m‘mÒ$à#(ˆE�%—-‘-Ò ð)ð ˆW�^‰^Ñ$˜eÑ$×-Ñ-¨oÓ>×DÑDÓF€FØ#)€FÔ Ø
‡K�K…Mùò Ms   ÁDc                 ó€   — 	 | j                   j                  }t	        | |«      S # t        $ r t        d| › d�«      ‚w xY w)z1Return the history manager for a given app model.z#Cannot find a historical model for ú.)r   Ú simple_history_manager_attributeÚAttributeErrorr   r   )r   Úmanager_names     r%   r   r      sO   € ðVØ—{‘{×CÑCˆô �5˜,Ó'Ð'øô ò VÜ%Ð(KÈEÈ7ÐRSÐ&TÓUÐUðVús   ‚$ ¤=c           	      óŽ   — t        | j                  «      } t        | j                  «      j                  di |t	        | |«      i¤ŽS )zL
    Return the history manager, based on an existing history instance.
    r   )Úget_app_model_primary_key_nameÚinstance_typer   r   r   )Úhistory_instanceÚkey_names     r%   Ú get_history_manager_from_historyr1   &   sL   € ô .Ð.>×.LÑ.LÓM€HØOÔ(Ð)9×)GÑ)GÓH×OÑOñ Ø”WÐ-¨xÓ8Ð
9ñð ó    c                 ó,   — t        | «      j                  S )z/Return the history model for a given app model.)r   r   ©r   s    r%   Úget_history_model_for_modelr5   0   s   € ä(¨Ó/×5Ñ5Ð5r2   c                 óÐ   — t        | j                  j                  t        «      r#| j                  j                  j                  dz   S | j                  j                  j                  S )z2Return the primary key name for a given app model.Ú_id)Ú
isinstancer   r   r   Únamer4   s    r%   r-   r-   5   sA   € ä�%—+‘+—.‘.¤*Ô-Ø�{‰{�~‰~×"Ñ" UÑ*Ð*Ø�;‰;�>‰>×ÑÐr2   Nc                 óx  — |j                   j                  «       D �cg c]  }t        |t        «      r|j                  ‘Œ  }}t        |«      }	|j                  }
d}t        j                  d¬«      5  |
j                  | ||¬«      }|r)|d   j                  r|sd}|	j                  |||||¬«       ddd«       |rât        j                  d¬«      5  d}g }t        «      D ]f  \  }}t        t        d„ t        ||¬	«      j!                  «       «      «      }t#        di |¤Ž}|r||z  n|}|j%                  t'        di |¤d
|i¤Ž«       Œh |r/t)        |
j                  |«      j+                  t-        |Ž «      «      ng }|	j                  |||||¬«       ddd«       }S c c}w # 1 sw Y   ŒôxY w# 1 sw Y   ŒxY w)a—  
    Bulk create the objects specified by objs while also bulk creating
    their history (all in one transaction).
    Because of not providing primary key attribute after bulk_create on any DB except
    Postgres (https://docs.djangoproject.com/en/2.2/ref/models/querysets/#bulk-create)
    Divide this process on two transactions for other DB's
    :param objs: List of objs (not yet saved to the db) of type model
    :param model: Model class that should be created
    :param batch_size: Number of objects that should be created in each batch
    :param default_user: Optional user to specify as the history_user in each historical
        record
    :param default_change_reason: Optional change reason to specify as the change_reason
        in each historical record
    :param default_date: Optional date to specify as the history_date in each historical
        record
    :return: List of objs with IDs
    TF©Ú	savepoint)Ú
batch_sizeÚignore_conflictsr   )r=   Údefault_userÚdefault_change_reasonÚdefault_dateNc                 ó   — | d   d uS )Né   r   )Úxs    r%   ú<lambda>z*bulk_create_with_history.<locals>.<lambda>w   s   €  ! A¡$¨dÐ"2€ r2   )ÚexcludeÚthenr   )r   Ú
get_fieldsr8   r   r9   r   Ú_default_managerr   ÚatomicÚbulk_creater   Úbulk_history_createÚ	enumerateÚdictr   r	   Úitemsr   Úappendr   Úlistr   r   )Úobjsr   r=   r>   r?   r@   rA   r!   Úexclude_fieldsÚhistory_managerÚmodel_managerÚsecond_transaction_requiredÚobjs_with_idÚcumulative_filterÚobj_when_listÚiÚobjÚ
attributesÚqÚobj_lists                       r%   Úbulk_create_with_historyr_   <   sú  € ð< —[‘[×+Ñ+Ó-öàÜ�eœ_Ô-ð 	�
‹
ð€Nð ô
 4°EÓ:€OØ×*Ñ*€Mà"&ÐÜ	×	Ñ	 eÔ	,ñ Ø$×0Ñ0Ø˜ZÐ:Jð 1ó 
ˆñ ˜L¨™O×.Ò.Ñ7GØ*/Ð'Ø×/Ñ/ØØ%Ø)Ø&;Ø)ð 0ô ÷ñ #Ü×Ñ¨%Ô0ñ #	ð !%ÐØˆMÜ# LÓ1ò A‘��3Ü!ÜÙ2Ü% c°>ÔB×HÑHÓJóó�
ô ‘O˜
‘O�Ù?PÐ%6¸Ò%:ÐVWÐ!ð ×$Ñ$¤TÑ%?¨JÑ%?¸QÒ%?Õ@ðAñ*  ô Ø!×(Ñ(Ð):Ó;×DÑDÜ˜mÐ,óôð ð ð ×/Ñ/ØØ%Ø)Ø&;Ø)ð 0ô ÷;#	ðH  ˆØÐùòy÷ð ú÷#	ð #	ús   �#FÁ1A F$ÃCF0Æ$F-Æ0F9c           	      ó  — t        |«      }|xs |j                  }	|	j                  |urt        d«      ‚t	        j
                  d¬«      5  |	j                  | ||¬«      }
|j                  | |d|||¬«       ddd«       |
S # 1 sw Y   
S xY w)ag  
    Bulk update the objects specified by objs while also bulk creating
    their history (all in one transaction).
    :param objs: List of objs of type model to be updated
    :param model: Model class that should be updated
    :param fields: The fields that are updated
    :param batch_size: Number of objects that should be updated in each batch
    :param default_user: Optional user to specify as the history_user in each historical
        record
    :param default_change_reason: Optional change reason to specify as the change_reason
        in each historical record
    :param default_date: Optional date to specify as the history_date in each historical
        record
    :param manager: Optional model manager to use for the model instead of the default
        manager
    :return: The number of model rows updated, not including any history objects
    z/The given manager does not belong to the model.Fr;   )r=   T)r=   Úupdater?   r@   rA   N)r   rI   r   r
   r   rJ   Úbulk_updaterL   )rR   r   r   r=   r?   r@   rA   r   rT   rU   Úrows_updateds              r%   Úbulk_update_with_historyrd   —   s¢   € ô6 4°EÓ:€OØÒ5˜u×5Ñ5€MØ×Ñ %Ñ'Ü%Ð&WÓXÐXä	×	Ñ	 eÔ	,ñ 	
Ø$×0Ñ0°°vÈ*Ð0ÓUˆØ×+Ñ+ØØ!ØØ%Ø"7Ø%ð 	,ô 	
÷	
ð Ð÷	
ð Ðús   Á,BÂBc                 ó4   — t        | d«      rt        | d«      S y )NÚ_change_reason)Úhasattrr   )r[   s    r%   Úget_change_reason_from_objectrh   Ä   s   € ÜˆsÐ$Ô%Ü�sÐ,Ó-Ð-àr2   )NFNNN)NNNNN)Ú	django.dbr   Údjango.db.modelsr   r   r   r   r   Údjango.forms.modelsr	   Úsimple_history.exceptionsr
   r   r&   r   r1   r5   r-   r_   rd   rh   r   r2   r%   ú<module>rm      sa   ðÝ !ß GÕ GÝ -ç Vòò*(òò6ò
ð ØØØØóXð~ ØØØØó*óZr2   