https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/django/db/models/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/django/db/models/__pycache__/deletion.cpython-310.pyc
o

3�a&M�@s�ddlZddlmZmZddlmZmZddlmZddlm	Z	ddl
mZmZm
Z
ddlmZmZmZGdd	�d	e�ZGd
d�de�Zdd
�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZGdd�d�ZdS)�N)�Counter�defaultdict)�partial�reduce)�chain)�
attrgetter)�IntegrityError�connections�transaction)�query_utils�signals�sqlc�eZdZ�fdd�Z�ZS)�ProtectedErrorc�||_t��||�dS�N)�protected_objects�super�__init__)�self�msgr��	__class__��;/usr/lib/python3/dist-packages/django/db/models/deletion.pyr�zProtectedError.__init__��__name__�
__module__�__qualname__r�
__classcell__rrrrr�rcr)�RestrictedErrorcrr)�restricted_objectsrr)rrr#rrrrrzRestrictedError.__init__rrrrrr"r!r"cCsH|j||jj|j|jdd�|jr t|jjs"|�|d|�dSdSdS)NF)�source�source_attr�nullable�fail_on_restricted)	�collect�remote_field�model�name�nullr	�features�can_defer_constraint_checks�add_field_update��	collector�field�sub_objs�usingrrr�CASCADEs��r5cCs$td|jjj|djj|jf|��)NzoCannot delete some instances of model '%s' because they are referenced through a protected foreign key: '%s.%s'r)rr)r*rrr+r0rrr�PROTECT s���r6cCs"|�||�|�|jj|j�dSr)�add_restricted_objects�add_dependencyr)r*r0rrr�RESTRICT*sr9cs4t��r�fdd�}n�fdd�}�fdd�|_|S)Ncs|�|��|�dSr�r/r0��valuerr�
set_on_delete1szSET.<locals>.set_on_deletecs|�|�|�dSrr:r0r;rrr=4�csd�fifS)Nzdjango.db.models.SETrrr;rr�<lambda>6szSET.<locals>.<lambda>)�callable�deconstruct)r<r=rr;r�SET/s
rBcCs|�|d|�dSrr:r0rrr�SET_NULL:r>rCcCs|�||��|�dSr)r/�get_defaultr0rrr�SET_DEFAULT>srEcCsdSrrr0rrr�
DO_NOTHINGBsrFcCsdd�|jdd�D�S)Ncss,�|]}|jr|js|js|jr|VqdSr)�auto_created�concrete�
one_to_one�one_to_many)�.0�frrr�	<genexpr>Is�����
�z4get_candidate_relations_to_delete.<locals>.<genexpr>T)�include_hidden)�
get_fields)�optsrrr�!get_candidate_relations_to_deleteFs
�rQc@s�eZdZdd�Zd"dd�Zd#dd�Zd	d
�Zdd�Zd
d�Zdd�Z	dd�Z
d$dd�Zdd�Z			d%dd�Z
dd�Zdd�Zdd�Zd d!�ZdS)&�	CollectorcCsD||_tt�|_tttt��|_tttt��|_g|_tt�|_dSr)	r4r�set�datar�
field_updatesr#�fast_deletes�dependencies)rr4rrrrPs
zCollector.__init__NFc	Csf|sgSg}|dj}|j|}|D]}||vr|�|�q|�|�|dur1|s1|j|||d�|S)a7
        Add 'objs' to the collection of objects to be deleted.  If the call is
        the result of a cascade, 'source' should be the model that caused it,
        and 'nullable' should be set to True if the relation can be null.

        Return a list of all objects that were not already collected.
        rN��reverse_dependency)rrT�append�updater8)	r�objsr$r&rY�new_objsr*�	instances�objrrr�addcs


�
z
Collector.addcCs>|r||}}|j|jj�|jj�|j�||j���dSr)rW�_meta�concrete_modelr`rT�
setdefault�default_factory)rr*�
dependencyrYrrrr8{s
zCollector.add_dependencycCs.|sdS|dj}|j|||f�|�dS)z�
        Schedule a field update. 'objs' must be a homogeneous iterable
        collection of model instances (e.g. a QuerySet).
        Nr)rrUr[)rr2r<r\r*rrrr/�s
zCollector.add_field_updatecCs*|r|dj}|j||�|�dSdS)Nr)rr#r[)rr2r\r*rrrr7�s
�z Collector.add_restricted_objectscs4||jvr�fdd�|j|��D�|j|<dSdS)Ncsi|]	\}}||��qSrr)rKr2�items�r\rr�
<dictcomp>�s��z?Collector.clear_restricted_objects_from_set.<locals>.<dictcomp>)r#rf)rr*r\rrgr�!clear_restricted_objects_from_set�s


��z+Collector.clear_restricted_objects_from_setcCsB||jvrt|jdd�|j|��D�d��}|�||�dSdS)NcSsg|]
}|D]}|j�qqSr��pk)rKr\r_rrr�
<listcomp>�s���zDCollector.clear_restricted_objects_from_queryset.<locals>.<listcomp>)�pk__in)r#rS�filter�valuesri)rr*�qsr\rrr�&clear_restricted_objects_from_queryset�s
��z0Collector.clear_restricted_objects_from_querysetcCstj�|�ptj�|�Sr)r�
pre_delete�
has_listeners�post_delete)rr*rrr�_has_signal_listeners�s
�zCollector._has_signal_listenerscs��r
�jjtur
dSt|d�r|jj}nt|d�r"t|d�r"|j}ndS|�|�r+dS|j}t�fdd�|jjj	�
�D��oStdd�t|�D��oStdd�|j
D��S)	a�
        Determine if the objects in the given queryset-like or single object
        can be fast-deleted. This can be done if there are no cascades, no
        parents and no signal listeners for the object class.

        The 'from_field' tells where we are coming from - we need this to
        determine if the objects are in fact to be deleted. Allow also
        skipping parent -> child -> parent chain preventing fast delete of
        the child.
        Frar*�_raw_deletec3s�|]}|�kVqdSrr)rK�link��
from_fieldrrrM�s�z,Collector.can_fast_delete.<locals>.<genexpr>css�|]
}|jjjtuVqdSr)r2r)�	on_deleterF)rK�relatedrrrrM�s
��
�css�|]}t|d�VqdS)�bulk_related_objectsN)�hasattr�rKr2rrrrM�s�)r)rzr5r}rar*ru�allrb�parentsrorQ�any�private_fields)rr\ryr*rPrrxr�can_fast_delete�s"


 ���zCollector.can_fast_deletecsZdd�|D�}tt|jj�|��d��t���kr*��fdd�tdt����D�S�gS)zT
        Return the objs in suitably sized batches for the used connection.
        cS�g|]}|j�qSr)r+r~rrrrl��z-Collector.get_del_batches.<locals>.<listcomp>�csg|]
}�||���qSrr)rK�i��conn_batch_sizer\rrrl�s�r)�maxr	r4�ops�bulk_batch_size�len�range)rr\�fields�field_namesrr�r�get_del_batches�s��zCollector.get_del_batchesTc	sl|�|�r
|j�|�dS|j||||d�}	|	sdS|	dj}
|sF|
jj}|jj��D]��rE�fdd�|	D�}|j	||
�j
jdddd�q+|sJdS|rSt|
j�
��}
tt�}tt�}t|
j�D]�}|rj|j|
vrjq`|j}|j
jtkrtq`|j}|j||d	�r�||�|�q`|�|	|g�}|D]\}|�||g|�}|jjs�|�|�s�tt�d
d�t|j�D���}|jt|��}|r�z|j
�||||j�Wq�t y�}zd|jj!|j"f}|||j#7<WYd}~q�d}~wwq�q`|�rt d
|
j!d�$|�ftt�|������|�%�D]\}}|�|	|�}|D]}|�|||�}|j�|��q�q|
jj&D]}t'|d��rC|�(|	|j�}|j	||
ddd��q+|�r�|j)�%�D]\}}|�*||��qM|jD]
}|�+|j|��q\|j,���r�tt�}|j,�%�D]"\}}|�%�D]\}}|�r�d|j!|j"f}|||7<�q~�qv|�r�t-d|
j!d�$|�ftt�|������dSdSdS)a�
        Add 'objs' to the collection of objects to be deleted as well as all
        parent instances.  'objs' must be a homogeneous iterable collection of
        model instances (e.g. a QuerySet).  If 'collect_related' is True,
        related objects will be handled by their respective on_delete handler.

        If the call is the result of a cascade, 'source' should be the model
        that caused it and 'nullable' should be set to True, if the relation
        can be null.

        If 'reverse_dependency' is True, 'source' will be deleted before the
        current model, rather than after. (Needed for cascading to parent
        models, the one case in which the cascade follows the forwards
        direction of an FK rather than the reverse direction.)

        If 'keep_parents' is True, data of parent model's will be not deleted.

        If 'fail_on_restricted' is False, error won't be raised even if it's
        prohibited to delete such objects due to RESTRICT, that defers
        restricted object checking in recursive calls where the top-level call
        may need to collect more objects to determine whether restricted ones
        can be deleted.
        NrXrcsg|]}t|�j��qSr)�getattrr+�rKr_��ptrrrrl�z%Collector.collect.<locals>.<listcomp>FT)r$r%�collect_relatedrYr'rxcss"�|]}dd�|jjD�VqdS)css�|]}|jVqdSr)�attname)rK�rfrrrrM#s�z.Collector.collect.<locals>.<genexpr>.<genexpr>N)r2�foreign_related_fields)rK�relrrrrM"s
��
�z$Collector.collect.<locals>.<genexpr>z'%s.%s'zhCannot delete some instances of model %r because they are referenced through protected foreign keys: %s.z, r|)r$r&r'ziCannot delete some instances of model %r because they are referenced through restricted foreign keys: %s.).r�rVrZr`rrarbr�ror(r)�related_namerS�get_parent_listr�listrQr*r2rzrF�
related_modelr��related_objects�query�select_relatedrur�
from_iterable�only�tupler4rrr+r�joinrfr�r}r|rTrirqr#r")rr\r$r&r�r%rY�keep_parentsr'r]r*rb�parent_objsr��model_fast_deletesrr{r2r��batches�batchr3�referenced_fields�error�key�related_fieldsr^rpr#r�rr�rr(�s�

�
��
����������
������zCollector.collectcs.ttj�fdd�|D��}|j�|j��|�S)zQ
        Get a QuerySet of the related model to objs via related fields.
        c3s*�|]}tjdid|j�i��VqdS)z%s__inNr)r�Qr+)rK�
related_fieldrgrrrM^s
��
�z,Collector.related_objects.<locals>.<genexpr>)r�operator�or_�
_base_managerr4rn)rr�r�r\�	predicaterrgrr�Zs�zCollector.related_objectsccs.�|j��D]\}}|D]}||fVqqdSr)rTrf)rr*r^r_rrr�instances_with_modelds���zCollector.instances_with_modelcs�g}t�}t�j�}t|�t|�krGd}|D]$}||vrq�j�|jj�}|r,|�|�s:|�	|�|�
|jj�d}q|s?dSt|�t|�ks�fdd�|D��_dS)NFTcsi|]}|�j|�qSr)rT)rKr*�rrrrhyr�z"Collector.sort.<locals>.<dictcomp>)rSr�rTr�rW�getrarb�
differencerZr`)r�
sorted_models�concrete_models�models�foundr*rWrr�r�sortis$

��zCollector.sortc
Cs�|j��D]\}}t|td�d�|j|<q|��t�}t|j�dkrgt|�dkrgt|�d}|�|�rgt	�
|j��t�
|��|jg|j�}Wd�n1sQwYt||jjjd�||jj|ifSt	j|jdd���|��D]\}}|jjs�tjj|||jd�qt|jD]}|j|jd�}|r�||jjj|7<q�|j��D]$\}}|��D]\\}	}
}t�|�}|�d	d
�|D�|	j |
i|j�q�q�|j�!�D]}|�"�q�|j��D]8\}}t�
|�}dd
�|D�}|�||j�}|r�||jj|7<|jj�s|D]
}tj#j|||jd��qq�Wd�n	1�s wY|j�!�D]}|��D]\\}	}
}|D]
}t||	j|
��q8�q0�q*|j��D]\}}|D]}t||jjjd��qR�qLt$|�!��t%|�fS)Nrk)r�r�rF)r4�	savepoint)�sender�instancer4)r4cSr�rrjr�rrrrl�r�z$Collector.delete.<locals>.<listcomp>cSr�rrjr�rrrrl�r�)&rTrf�sortedrr�rr�r�r�r
�mark_for_rollback_on_errorr4r
�DeleteQuery�delete_batchrk�setattrrar��label�atomicr�rGrrr�sendrVrvr*rU�UpdateQuery�update_batchr+ro�reversert�sum�dict)
rr*r^�deleted_counterr��countr_rp�instances_for_fieldvaluesr2r<r��pk_listrrr�delete{st
���
�
��



����(���zCollector.delete)NFF)Fr)NFTNFFT)rrrrr`r8r/r7rirqrur�r�r(r�r�r�r�rrrrrROs(



$

�
rR)r��collectionsrr�	functoolsrr�	itertoolsrr�	django.dbrr	r
�django.db.modelsrrr
rr"r5r6r9rBrCrErFrQrRrrrr�<module>s$	
	

https://t.me/RX1948 - 2025