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/contrib/admin/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/django/contrib/admin/__pycache__/options.cpython-310.pyc
o

3�a�j�@sDddlZddlZddlZddlZddlmZmZmZddlm	Z
ddlmZddl
mZddlmZddlmZmZddlmZmZmZdd	lmZdd
lmZddlmZddlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m	Z	m&Z&dd
l'm(Z(m)Z)ddl*m+Z+ddl,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2ddl3m4Z4m5Z5m6Z6ddl7m8Z8ddl9m:Z:m;Z;ddl<m=Z=m>Z>m?Z?m@Z@mAZAddlBmCZCmDZDddlEmFZFddlGmHZHddlImJZJmKZKddlLmMZMddlNmOZOddlPmQZQddlRmSZSddlTmUZUddlVmWZWmXZXmYZYmZZZm[Z[ddl\m]Z^m_Z_dd l`maZadd!lbmcZcd"Zdd#Zed$\ZfZgd%d&�Zhd'd(�ZiGd)d*�d*ej�Zke4jlejmejnd+�e4jod,ejpie4jqd,ejrie4jsd,ejtie4jud,ejvie4jwd,ejxie4jyd,ejzie4j{d,ej|ie4j}d,ej~ie4jd,ej~ie4j�d,ej�ie4j�d,ej�iiZ�eOea�Z�Gd-d.�d.ej�d/�Z�Gd0d1�d1e��Z�Gd2d3�d3e��Z�Gd4d5�d5e��Z�Gd6d7�d7e��Z�dS)8�N)�partial�reduce�update_wrapper)�quote)�forms)�settings)�messages)�helpers�widgets)�BaseModelAdminChecks�InlineModelAdminChecks�ModelAdminChecks)�display)�DisallowedModelAdminToField)�add_preserved_filters)	�
NestedObjects�construct_change_message�flatten_fieldsets�get_deleted_objects�lookup_needs_distinct�model_format_dict�model_ngettextr�unquote)�AutocompleteSelect�AutocompleteSelectMultiple)�get_permission_codename)�FieldDoesNotExist�
FieldError�PermissionDenied�ValidationError)�	Paginator)�models�router�transaction)�
LOOKUP_SEP)�DELETION_FIELD_NAME�	all_valid)�BaseInlineFormSet�inlineformset_factory�modelform_defines_fields�modelform_factory�modelformset_factory)�CheckboxSelectMultiple�SelectMultiple)�HttpResponseRedirect)�HttpResponseBase)�SimpleTemplateResponse�TemplateResponse)�reverse)�method_decorator)�format_html)�	urlencode)�	mark_safe)�capfirst�format_lazy�
get_text_list�smart_split�unescape_string_literal)�gettext�ngettext)�csrf_protect)�RedirectView�_popup�	_to_field)��cCsddlm}|jj|dd�S)Nr)�ContentTypeF)�for_concrete_model)�"django.contrib.contenttypes.modelsrD�objects�
get_for_model)�objrD�rJ�>/usr/lib/python3/dist-packages/django/contrib/admin/options.py�get_content_type_for_model=srLcCs|tkrdSdS)N�	radiolistzradiolist inline)�VERTICAL)�radio_stylerJrJrK�get_ul_classD�rPc@seZdZdS)�IncorrectLookupParametersN)�__name__�
__module__�__qualname__rJrJrJrKrRHsrR)�
form_class�widgetrWc@sBeZdZdZdZdZdZdZdZe	j
ZdZdZ
iZiZiZdZdZdZdZdZeZdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�Zd;dd�Z dd�Z!d;dd�Z"d;dd�Z#d;dd�Z$dd �Z%d!d"�Z&d;d#d$�Z'd;d%d&�Z(d'd(�Z)d)d*�Z*d+d,�Z+d-d.�Z,d/d0�Z-d;d1d2�Z.d;d3d4�Z/d;d5d6�Z0d;d7d8�Z1d9d:�Z2dS)<�BaseModelAdminz8Functionality common to both ModelAdmin and InlineAdmin.rJNTcKs|��j|fi|��S�N)�checks_class�check)�self�kwargsrJrJrKr[y�zBaseModelAdmin.checkcCs:t�t�}|j��D]
\}}|�|i��|�q
||_dSrY)�copy�deepcopy�FORMFIELD_FOR_DBFIELD_DEFAULTS�formfield_overrides�items�
setdefault�update)r\�	overrides�k�vrJrJrK�__init__|s

zBaseModelAdmin.__init__cKsZ|jr
|j||fi|��St|tjtjf�r�|j|jvr&i|j|j�|�}t|tj�r7|j||fi|��}nt|tj�rG|j	||fi|��}|r�|j
|jvr�|jj
�|jj�}i}|rq|j|�|�|�|�|�|�|�|�d�tj|j|j|jfi|��|_|S|j��D]}||jvr�it�|j|��|�}|jdi|��Sq�|jdi|��S)z�
        Hook for specifying the form Field instance for a given database Field
        instance.

        If kwargs are given, they're passed to the form Field's constructor.
        )�can_add_related�can_change_related�can_delete_related�can_view_relatedNrJ)�choices�formfield_for_choice_field�
isinstancer!�
ForeignKey�ManyToManyField�	__class__rb�formfield_for_foreignkey�formfield_for_manytomany�name�
raw_id_fields�
admin_site�	_registry�get�remote_field�modelre�has_add_permission�has_change_permission�has_delete_permission�has_view_permissionr
�RelatedFieldWidgetWrapperrW�mror_r`�	formfield)r\�db_field�requestr]r��related_modeladmin�wrapper_kwargs�klassrJrJrK�formfield_for_dbfield�s>	���
�z$BaseModelAdmin.formfield_for_dbfieldcKsj|j|jvr-d|vrtjdt|j|j�id�|d<d|vr-|j|jdtd�fgd�|d<|jd	i|��S)
zR
        Get a form Field for a database Field that has declared choices.
        rW�class��attrsrn��None)�
include_blank�blank_choiceNrJ)	rv�radio_fieldsr
�AdminRadioSelectrP�get_choices�blank�_r�)r\r�r�r]rJrJrKro�s�
�z)BaseModelAdmin.formfield_for_choice_fieldcCsN|jj�|jj�}|dur%|�|�}|dur%|dkr%|jjj�|�j|�SdS)z�
        If the ModelAdmin specifies ordering, the queryset should respect that
        ordering.  Otherwise don't specify the queryset, let the field decide
        (return None in that case).
        NrJ)	rxryrzr{r|�get_ordering�_default_manager�using�order_by)r\�dbr�r��
related_admin�orderingrJrJrK�get_field_queryset�s
z!BaseModelAdmin.get_field_querysetcKs�|�d�}d|vrP|j|�|�vrt||j|d�|d<n4|j|jvr/tj|j|j|d�|d<n!|j|j	vrPtj
dt|j	|j�id�|d<|jrLt
d�nd|d<d	|vrc|�|||�}|durc||d	<|jd
i|��S)z4
        Get a form Field for a ForeignKey.
        r�rW�r�r�r�r�N�empty_label�querysetrJ)rzrv�get_autocomplete_fieldsrrxrwr
�ForeignKeyRawIdWidgetr{r�r�rPr�r�r�r�)r\r�r�r]r�r�rJrJrKrt�s 
�z'BaseModelAdmin.formfield_for_foreignkeyc
Ks|jjjjsdS|�d�}d|vrQ|�|�}|j|vr&t||j|d�|d<n+|j|j	vr9t
j|j|j|d�|d<n|jg|j�|j
�vrQt
�|j|j|jv�|d<d|vrd|�|||�}|durd||d<|jdi|��}t|jt�r�t|jttf�s�td�}|j}	|	r�td|	|�n||_|S)	z9
        Get a form Field for a ManyToManyField.
        Nr�rWr�r�uLHold down “Control”, or “Command” on a Mac, to select more than one.z{} {}rJ)r{�through�_meta�auto_createdrzr�rvrrxrwr
�ManyToManyRawIdWidget�filter_vertical�filter_horizontal�FilteredSelectMultiple�verbose_namer�r�rprWr-r,r��	help_textr8)
r\r�r�r]r��autocomplete_fieldsr��
form_field�msgr�rJrJrKru�sD


��
��z'BaseModelAdmin.formfield_for_manytomanycC�|jS)zw
        Return a list of ForeignKey and/or ManyToMany fields which should use
        an autocomplete widget.
        )r��r\r�rJrJrKr��z&BaseModelAdmin.get_autocomplete_fieldscCsN|dus|js	dSt|j�r|�|�St|d�r%tdt|�j|jd�d�SdS)N�get_absolute_urlzadmin:view_on_site)�content_type_id�	object_id)r])�view_on_site�callable�hasattrr2rL�pk�r\rIrJrJrK�get_view_on_site_url%s



��z#BaseModelAdmin.get_view_on_site_urlcCs,zt|j�WStyt|jj�YSw)zP
        Return the empty_value_display set on ModelAdmin or AdminSite.
        )r6�empty_value_display�AttributeErrorrx�r\rJrJrK�get_empty_value_display2s
�z&BaseModelAdmin.get_empty_value_displaycCr�)z.
        Hook for specifying exclude.
        )�exclude�r\r�rIrJrJrK�get_exclude;�zBaseModelAdmin.get_excludecCs.|jr|jS|�||�}g|j�|�||��S)z-
        Hook for specifying fields.
        )�fields�_get_form_for_get_fields�base_fields�get_readonly_fields)r\r�rI�formrJrJrK�
get_fieldsAszBaseModelAdmin.get_fieldscCs"|jr|jSdd|�||�ifgS)z0
        Hook for specifying fieldsets.
        Nr�)�	fieldsetsr�r�rJrJrK�
get_fieldsetsKszBaseModelAdmin.get_fieldsetscCr�)z#Hook for specifying custom inlines.)�inlinesr�rJrJrK�get_inlinesS�zBaseModelAdmin.get_inlinescCs
|jpdS)z5
        Hook for specifying field ordering.
        rJ)r�r�rJrJrKr�Ws
zBaseModelAdmin.get_orderingcCr�)z=
        Hook for specifying custom readonly fields.
        )�readonly_fieldsr�rJrJrKr�]r�z"BaseModelAdmin.get_readonly_fieldscCr�)zA
        Hook for specifying custom prepopulated fields.
        )�prepopulated_fieldsr�rJrJrK�get_prepopulated_fieldscr�z&BaseModelAdmin.get_prepopulated_fieldscCs(|jj��}|�|�}|r|j|�}|S)z�
        Return a QuerySet of all model instances that can be edited by the
        admin site. This is used by changelist_view.
        )r|r��get_querysetr�r�)r\r��qsr�rJrJrKr�is


zBaseModelAdmin.get_querysetcCs|jdur|jS|�|�S)zAHook for specifying which fields can be sorted in the changelist.N)�sortable_by�get_list_displayr�rJrJrK�get_sortable_byuszBaseModelAdmin.get_sortable_byc	Csbddlm}|j}|jjD]}t|�r|�}||ft�|���vr$dSq
g}d}|�	t
�D]:}z|j�|�}	Wn
tyBYn'w|rQ|j
rV|	|��djvrV|�|�t|	dd�s^n|	}|	��djj}q.t|�dkrqdS|jh}
|jD]'}t|t�r�t||�r�|
�|j�qxt|ttf�r�|
�|d�qx|
�|�qxt
�|�t
�||g�h�|
�S)Nr)�SimpleListFilterT����
get_path_inforB)�django.contrib.admin.filtersr�r|r��related_fkey_lookupsr�r
�url_params_from_lookup_dictrc�splitr$�	get_fieldr�is_relationr��
target_fields�append�getattr�to_opts�len�date_hierarchy�list_filterrp�type�
issubclass�add�parameter_name�list�tuple�join�
isdisjoint)r\�lookup�valuer�r|�	fk_lookup�relation_parts�
prev_field�part�field�
valid_lookups�filter_itemrJrJrK�lookup_allowedysJ��


��zBaseModelAdmin.lookup_allowedc
s�|jj}z|�|�}Wn
tyYdSw|jrdS|jD]}|��|kr)dSqt�}|jj	�
�D]\}}|�|�|jD]}	|�|	j�q?q3dd�|j
dd�D�}
|
D]"}|j�|jj}t�fdd�|D��rxt|d�rx|��|krxdSqVdS)z�
        Return True if the model associated with this admin should be
        allowed to be referenced by the specified field.
        FTcss �|]}|jr|js|VqdSrY)r��concrete��.0�frJrJrK�	<genexpr>�s���
�z2BaseModelAdmin.to_field_allowed.<locals>.<genexpr>)�include_hiddenc3s�|]}t|��VqdSrY)r�)r�r|��
related_modelrJrKr�����get_related_field)r|r�r�r�primary_key�many_to_many�m2m_target_field_name�setrxryrcr�r�r�r�r�r{�anyr�r)
r\r��to_field�optsr�r�registered_modelsr|�admin�inline�related_objects�related_objectr{rJr�rK�to_field_allowed�s>�
�

�
���zBaseModelAdmin.to_field_allowedcCs&|j}td|�}|j�d|j|f�S)z�
        Return True if the given request has permission to add an object.
        Can be overridden by the user in subclasses.
        r��%s.%s�rr�user�has_perm�	app_label)r\r�r�codenamerJrJrKr}�s
z!BaseModelAdmin.has_add_permissioncC�&|j}td|�}|j�d|j|f�S)a�
        Return True if the given request has permission to change the given
        Django model instance, the default implementation doesn't examine the
        `obj` parameter.

        Can be overridden by the user in subclasses. In such case it should
        return True if the given request has permission to change the `obj`
        model instance. If `obj` is None, this should return True if the given
        request has permission to change *any* object of the given type.
        �changerr�r\r�rIrrrJrJrKr~��
z$BaseModelAdmin.has_change_permissioncCr)a�
        Return True if the given request has permission to change the given
        Django model instance, the default implementation doesn't examine the
        `obj` parameter.

        Can be overridden by the user in subclasses. In such case it should
        return True if the given request has permission to delete the `obj`
        model instance. If `obj` is None, this should return True if the given
        request has permission to delete *any* object of the given type.
        �deleterrrrJrJrKr�rz$BaseModelAdmin.has_delete_permissioncCsF|j}td|�}td|�}|j�d|j|f�p"|j�d|j|f�S)a�
        Return True if the given request has permission to view the given
        Django model instance. The default implementation doesn't examine the
        `obj` parameter.

        If overridden by the user in subclasses, it should return True if the
        given request has permission to view the `obj` model instance. If `obj`
        is None, it should return True if the request has permission to view
        any object of the given type.
        �viewrrr)r\r�rIr�
codename_view�codename_changerJrJrKr�s

�z"BaseModelAdmin.has_view_permissioncCs|�||�p|�||�SrY)r�r~r�rJrJrK�has_view_or_change_permissionsz,BaseModelAdmin.has_view_or_change_permissioncCs|j�|jj�S)a�
        Return True if the given request has any permission in the given
        app label.

        Can be overridden by the user in subclasses. In such case it should
        return True if the given request has permission to view the module on
        the admin index page and access the module's index page. Overriding it
        does not restrict access to the add, change or delete views. Use
        `ModelAdmin.has_(add|change|delete)_permission` for that.
        )r�has_module_permsrrr�rJrJrK�has_module_permissionsz$BaseModelAdmin.has_module_permissionrY)3rSrTrU�__doc__r�rwr�r�r�r�	ModelFormr�r�r�r�r�rbr�r�r�r��show_full_result_countrrZr[rir�ror�rtrur�r�r�r�r�r�r�r�r�r�r�r�r�rr}r~rr�rrrJrJrJrKrXds\9
*

	




6-
	


rX)�	metaclasscs�eZdZdZdZdZdZdZdZdZ	dZ
dZdZdZ
dZdZeZdZgZdZdZdZdZdZdZdZgZejZdZdZ dZ!e"Z#�fd	d
�Z$dd�Z%d�d
d�Z&dd�Z'e(dd��Z)e(dd��Z*dd�Z+dd�Z,d�dd�Z-dd�Z.dd�Z/d�dd �Z0d!d"�Z1d#d$�Z2d�d%d&�Z3d�d(d)�Z4d*d+�Z5d,d-�Z6d.d/�Z7e8e9d0�d1�d2d3��Z:e;d4d5��Z<d6d7�Z=d8d9�Z>d:d;�Z?e@jAfd<d=�ZBd>d?�ZCd@dA�ZDdBdC�ZEdDdE�ZFdFdG�ZGdHdI�ZHdJdK�ZIdLdM�ZJd�dNdO�ZKeLjMdPdfdQdR�ZNdSdT�ZOdUdV�ZPdWdX�ZQdYdZ�ZRd[d\�ZSd]d^�ZTd�d_d`�ZUd�dadb�ZVdcdd�ZWdedf�ZXdgdh�ZYdidj�ZZdkdl�Z[dmdn�Z\dodp�Z]d�dqdr�Z^dsdt�Z_dudv�Z`ead�dwdx��Zbdydz�Zcd�d{d|�Zdd�d}d~�Zedd��Zfd�d��Zgead�d�d���Zhd�d��Ziead�d�d���Zjd�d��Zkd�d�d��Zld�d��Zm�ZnS)��
ModelAdminzBEncapsulate all admin options and functionality for a given model.)�__str__rJF�d��NTcs"||_|j|_||_t���dSrY)r|r�rrx�superri)r\r|rx�rsrJrKriKszModelAdmin.__init__cCsd|jjj|jjfS)Nr)r|r�rrsrSr�rJrJrKr%Qr^zModelAdmin.__str__cCsng}|�||�D],}||j|j�}|r/|�||�s&|�||�s&|�||�s&q|�||�s/d|_|�|�q|S)Nr)r�r|rxrr}r�max_numr�)r\r�rI�inline_instances�inline_classrrJrJrK�get_inline_instancesTs
�
�zModelAdmin.get_inline_instancescs�ddlm}�fdd�}�jjj�jjjf}|d|�j�d|d�|d|�j�d	|d�|d
|�j�d|d�|d|�j	�d
|d�|d|�j
�d|d�|d|tjd�j
jf|d���gS)Nr)�pathcs��fdd�}�|_t|��S)Ncs�j���|i|��SrY)rx�
admin_view)�argsr])r\rrJrK�wrappergr^z2ModelAdmin.get_urls.<locals>.wrap.<locals>.wrapper)�model_adminr)rr1r�)rrK�wrapfs
z!ModelAdmin.get_urls.<locals>.wrapr�z%s_%s_changelist)rvzadd/z	%s_%s_addz<path:object_id>/history/z
%s_%s_historyz<path:object_id>/delete/z%s_%s_deletez<path:object_id>/change/z%s_%s_changez<path:object_id>/z%s:%s_%s_change)�pattern_name)�django.urlsr.r|r�r�
model_name�changelist_view�add_view�history_view�delete_view�change_viewr?�as_viewrxrv)r\r.r3�inforJr�rK�get_urlscs
��zModelAdmin.get_urlscCs|��SrY)r>r�rJrJrK�urlszszModelAdmin.urlsc	Cs@tjrdnd}d|dddddd	d
|g}tjdd�|D�d
�S)Nr��.min�vendor/jquery/jquery%s.js�jquery.init.jszcore.jszadmin/RelatedObjectLookups.jsz
actions.jsz	urlify.jszprepopulate.jszvendor/xregexp/xregexp%s.jscS�g|]}d|�qS�zadmin/js/%srJ�r��urlrJrJrK�
<listcomp>��z$ModelAdmin.media.<locals>.<listcomp>��js)r�DEBUGr�Media�r\�extrarJrJrJrK�media~s�
zModelAdmin.mediacCs&|�|�|�|�|�|�|�|�d�S)z�
        Return a dict of all perms for this model. This dict has the keys
        ``add``, ``change``, ``delete``, and ``view`` mapping to the True/False
        for each of those actions.
        )r�rrr)r}r~rr�r�rJrJrK�get_model_perms�s
�zModelAdmin.get_model_permscCs|j||dd�S�N)r�)�get_formr�rJrJrKr��rQz#ModelAdmin._get_form_for_get_fieldsc

s`d|vr
|�d�}nt��||��}��||�}|durgnt|�}��||�}|�|�|r?t|d�r?��||�s?|�|�|durVt�j	d�rV�j	j
jrV|��j	j
j�|pYd}t�
�fdd�|D��}	t�j	j�j	f|	�}
|
||t�j|d�d�|�}|ddur�t|d	�s�tj|d<z
t�jfi|��WSty�}z
td
|�jjf��d}~ww)zv
        Return a Form class for use in the admin add view. This is used by
        add_view and change_view.
        r�Nrr�c3s �|]}|�jjvr|VqdSrY)r��declared_fieldsr�r�rJrKr��s�z&ModelAdmin.get_form.<locals>.<genexpr>�r�)r�r�r��formfield_callbackr�z:%s. Check fields/fieldsets/exclude attributes of class %s.)�poprr�r�r�r��extendr�r~r�r�r��dict�fromkeysr�rSrr�r)r�
ALL_FIELDSr*r|rrs)
r\r�rIrr]r��excludedr�r��	new_attrsr��defaults�erJr�rKrR�sB

��

����zModelAdmin.get_formcKsddlm}|S)zM
        Return the ChangeList class for use on the changelist page.
        r)�
ChangeList)�django.contrib.admin.views.mainr_)r\r�r]r_rJrJrK�get_changelist�szModelAdmin.get_changelistcCsz|�|�}|�||�}|�|�rdg|�}|�|�}|�|�}|||j|||�|�|j|�|�|�	|�|j
|j|j||�
S)zs
        Return a `ChangeList` instance based on `request`. May raise
        `IncorrectLookupParameters`.
        �action_checkbox)
r��get_list_display_links�get_actionsr�rar|�get_list_filterr��get_search_fields�get_list_select_related�
list_per_page�list_max_show_all�
list_editable)r\r��list_display�list_display_linksr�r_rJrJrK�get_changelist_instance�s*




�z"ModelAdmin.get_changelist_instancec
Csl|�|�}|j}|dur|jjn|j�|�}z|�|�}|jdi|j|i��WS|jt	t
fy5YdSw)z�
        Return an instance matching the field and value provided, the primary
        key is used if no field is provided. Return ``None`` if no match is
        found or the object_id fails validation.
        NrJ)r�r|r�r�r��	to_pythonrzrv�DoesNotExistr�
ValueError)r\r�r��
from_fieldr�r|r�rJrJrK�
get_object�s

�zModelAdmin.get_objectcKsNdt|j|d�i|�}|�d�durt|�d��stj|d<t|jfi|��S)zT
        Return a Form class for use in the Formset on the changelist page.
        rUrTr�Nr�)rr�rzr)rrZr*r|�r\r�r]r]rJrJrK�get_changelist_form�s��
zModelAdmin.get_changelist_formcKs8dt|j|d�i|�}t|j|�|�fd|jd�|��S)zi
        Return a FormSet class for use on the changelist page if list_editable
        is used.
        rUrTr)rNr�)rr�r+r|rtrjrsrJrJrK�get_changelist_formsets�����z!ModelAdmin.get_changelist_formsetccs*�|�||�D]}|�||�|fVqdS)z?
        Yield formsets and the corresponding inlines.
        N)r-�get_formset)r\r�rIrrJrJrK�get_formsets_with_inliness��z$ModelAdmin.get_formsets_with_inlinesrcCs|�||||�SrY)�	paginator)r\r�r��per_page�orphans�allow_empty_first_pagerJrJrK�
get_paginator!rQzModelAdmin.get_paginatorcC�8ddlm}m}|jj|jjt|�j|jt|�||d�S)z�
        Log that an object has been successfully added.

        The default implementation creates an admin LogEntry object.
        r)�ADDITION�LogEntry��user_idr�r��object_repr�action_flag�change_message)	�django.contrib.admin.modelsr~rrG�
log_actionrr�rL�str)r\r��object�messager~rrJrJrK�log_addition$��zModelAdmin.log_additioncCr})z�
        Log that an object has been successfully changed.

        The default implementation creates an admin LogEntry object.
        r)�CHANGErr�)	r�r�rrGr�rr�rLr�)r\r�r�r�r�rrJrJrK�
log_change4r�zModelAdmin.log_changecCs2ddlm}m}|jj|jjt|�j|j||d�S)z�
        Log that an object will be deleted. Note that this method must be
        called before the deletion.

        The default implementation creates an admin LogEntry object.
        r)�DELETIONr)r�r�r�r�r�)r�r�rrGr�rr�rL)r\r�r�r�r�rrJrJrK�log_deletionDs�zModelAdmin.log_deletionz*<input type="checkbox" id="action-toggle">)�descriptioncCstj�tjt|j��S)zE
        A list_display column containing a checkbox widget.
        )r	�checkbox�render�ACTION_CHECKBOX_NAMEr�r�r�rJrJrKrbTszModelAdmin.action_checkboxcCst|dt|�dd���S)N�short_descriptionr�� )r�r7�replace)�funcrvrJrJrK�_get_action_description[sz"ModelAdmin._get_action_descriptioncs~g}�fdd��jpgD�}dd�|D�}dd�|D�}�jjD]\}}||vr)q ��||�}|�|||f�q |�|�|S)zAReturn the list of actions, prior to any request-based filtering.c3s�|]}��|�VqdSrY)�
get_action�r��actionr�rJrKr�brz/ModelAdmin._get_base_actions.<locals>.<genexpr>cSsg|]}|r|�qSrJrJr�rJrJrKrGdrHz0ModelAdmin._get_base_actions.<locals>.<listcomp>cSsh|]\}}}|�qSrJrJ)r�r�rvrJrJrK�	<setcomp>esz/ModelAdmin._get_base_actions.<locals>.<setcomp>)�actionsrxr�r�rW)r\r��base_actions�base_action_namesrvr�r�rJr�rK�_get_base_actions_s
zModelAdmin._get_base_actionscsdg}|D]+}|d}t|d�s|�|�q�fdd�|jD�}t�fdd�|D��r/|�|�q|S)z<Filter out any actions that the user doesn't have access to.r�allowed_permissionsc3s�|]
}t�d|�VqdS)zhas_%s_permissionN)r�)r��
permissionr�rJrKr�ys
��
�z<ModelAdmin._filter_actions_by_permissions.<locals>.<genexpr>c3s�|]}|��VqdSrYrJ)r��has_permissionrTrJrKr�}��)r�r�r�r)r\r�r��filtered_actionsr�r��permission_checksrJ)r�r\rK�_filter_actions_by_permissionsqs


�
�z)ModelAdmin._filter_actions_by_permissionscCs6|jdus
t|jvriS|�||���}dd�|D�S)z�
        Return a dictionary mapping the names of all actions for this
        ModelAdmin to a tuple of (callable, name, description) for each action.
        NcSsi|]\}}}||||f�qSrJrJ)r�r�rv�descrJrJrK�
<dictcomp>��z*ModelAdmin.get_actions.<locals>.<dictcomp>)r��IS_POPUP_VAR�GETr�r�)r\r�r�rJrJrKrd�szModelAdmin.get_actionscCsBg|}|�|���D]\}}}||t|j�f}|�|�q|S)zy
        Return a list of choices for use in a form object.  Each choice is a
        tuple (name, description).
        )rd�valuesrrr�)r\r��default_choicesrnr�rvr��choicerJrJrK�get_action_choices�s
zModelAdmin.get_action_choicescCsjt|�r
|}|j}n t|j|�rt|j|�}nz|j�|�}Wn
ty)YdSw|�||�}|||fS)z�
        Return a given action from a parameter, which can either be a callable,
        or the name of a method on the ModelAdmin.  Return is a tuple of
        (callable, name, description).
        N)	r�rSr�rsr�rxr��KeyErrorr�)r\r�r�r�rJrJrKr��s�
zModelAdmin.get_actioncCr�)zd
        Return a sequence containing the fields to be displayed on the
        changelist.
        )rkr�rJrJrKr��r�zModelAdmin.get_list_displaycCs*|js
|jdus
|s
|jSt|�dd�S)z�
        Return a sequence containing the fields to be displayed as links
        on the changelist. The list_display parameter is the list of fields
        returned by get_list_display().
        NrB)rlr�)r\r�rkrJrJrKrc�sz!ModelAdmin.get_list_display_linkscCr�)z�
        Return a sequence containing the fields to be displayed as filters in
        the right sidebar of the changelist page.
        )r�r�rJrJrKre�r�zModelAdmin.get_list_filtercCr�)zt
        Return a list of fields to add to the select_related() part of the
        changelist items query.
        )�list_select_relatedr�rJrJrKrg�r�z"ModelAdmin.get_list_select_relatedcCr�)zz
        Return a sequence containing the fields to be searched whenever
        somebody submits a search query.
        )�
search_fieldsr�rJrJrKrf�r�zModelAdmin.get_search_fieldscs��fdd��d}��|�}|rQ|rQ�fdd�|D�}t|�D]%���d�r1�d�dkr1t����fd	d�|D�}��ttj|���q|t�fd
d�|D��O}�|fS)z�
        Return a tuple containing a queryset to implement the search
        and a boolean indicating if the results may contain duplicates.
        c	s�|�d�r
d|dd�S|�d�rd|dd�S|�d�r'd|dd�S�jj}|�t�}d}|D]6}|dkr>|jj}z|�|�}Wnty[|rY|�	|�rY|YSYq4w|}t
|d	�rj|��d
j}q4d|S)N�^z%s__istartswithrB�=z
%s__iexact�@z
%s__searchr�r�r�z
%s__icontains)
�
startswithr|r�r�r$r�rvr�r�
get_lookupr�r�r�)�
field_namer�
lookup_fieldsr��	path_partr��r�rJrK�construct_search�s0



��
�z7ModelAdmin.get_search_results.<locals>.construct_searchFcsg|]}�t|���qSrJ)r�)r��search_field)r�rJrKrGs�z1ModelAdmin.get_search_results.<locals>.<listcomp>)�"�'rr�cs g|]}tjdi|�i���qS)rJ)r!�Q)r��
orm_lookup)�bitrJrKrGs�c3s�|]	}t�j|�VqdSrY)rr)r��search_specr�rJrKr�	s
�
�
�z0ModelAdmin.get_search_results.<locals>.<genexpr>)	rfr:r�r;�filterr�operator�or_r)r\r�r��search_term�may_have_duplicatesr��orm_lookups�
or_queriesrJ)r�r�r�r\rK�get_search_results�s$

�
�
�zModelAdmin.get_search_resultscCsl|j}|jr4|r4|jj}d|j|jf}d|j|jf}||kr&|j�	�}n|j�
d�}|r4t	d|i�SdS)z;
        Return the preserved filters querystring.
        z%s:%s�admin:%s_%s_changelist�_changelist_filtersr�)�resolver_match�preserve_filtersr|r��app_name�url_namerr6r�r5rz)r\r��matchr�current_url�changelist_url�preserved_filtersrJrJrK�get_preserved_filterss
z ModelAdmin.get_preserved_filterscCst|||�S)zV
        Construct a JSON structure describing changes from a changed object.
        )r)r\r�r��formsetsr�rJrJrKr!�z#ModelAdmin.construct_change_messager�cCsvt|t�s/z
ttj|���}Wnty.tjj��}d�	dd�|D��}t
d||f��wtj|||||d�dS)a�
        Send a message to the user. The default implementation
        posts a message using the django.contrib.messages backend.

        Exposes almost the same API as messages.add_message(), but accepts the
        positional arguments in a different order to maintain backwards
        compatibility. For convenience, it accepts the `level` argument as
        a string rather than the usual level number.
        z, css�|]}d|VqdS)z`%s`NrJ)r��levelrJrJrKr�8r�z*ModelAdmin.message_user.<locals>.<genexpr>z7Bad message level string: `%s`. Possible values are: %s)�
extra_tags�
fail_silentlyN)rp�intr�r�	constants�upperr��DEFAULT_TAGSr�r�rp�add_message)r\r�r�r�r�r��levels�levels_reprrJrJrK�message_user's
���zModelAdmin.message_usercCs|jdd�S)z�
        Given a ModelForm return an unsaved instance. ``change`` is True if
        the object is being changed, and False if it's being added.
        F)�commit��save)r\r�r�rrJrJrK�	save_form@�zModelAdmin.save_formcC�|��dS)zA
        Given a model instance save it to the database.
        Nr�)r\r�rIr�rrJrJrK�
save_modelGr�zModelAdmin.save_modelcCr�)zE
        Given a model instance delete it from the database.
        N�rr�rJrJrK�delete_modelMr�zModelAdmin.delete_modelcCr�)z.Given a queryset, delete it from the database.Nr��r\r�r�rJrJrK�delete_querysetSszModelAdmin.delete_querysetcCs|��dS)zB
        Given an inline formset save it to the database.
        Nr�)r\r�r��formsetrrJrJrK�save_formsetWr�zModelAdmin.save_formsetcCs(|��|D]}|j||||d�qdS)aO
        Given the ``HttpRequest``, the parent ``ModelForm`` instance, the
        list of inline formsets and a boolean value based on whether the
        parent is being added or changed, save the related objects to the
        database. Note that at this point save_form() and save_model() have
        already been called.
        �rN)�save_m2mr�)r\r�r�r�rr�rJrJrK�save_related]s�zModelAdmin.save_relatedcCsn|jj}|j}|�|�}	t|	|d�|�}|�|�}
d}|dD]}|js*|js*|jr.d}nq|�	id|�d|�d|�
||��d|�|��d	|�||��d
|�||��d|�d|d
j��pht
dd�|dD���d|
du�d|
�d|�d|�dt|j�j�d|j�d|j�dt�dt�d|i��|r�|jdur�|j}
n|j}
|jj|_t||
p�d||jfd|dg|�S)N�r�rF�inline_admin_formsetsTr�rr�r}r~r�"has_editable_inline_admin_formsets�has_file_field�	adminformcss�|]}|j��VqdSrY)r��is_multipart)r��
admin_formsetrJrJrKr�|s
��
�z0ModelAdmin.render_change_form.<locals>.<genexpr>�has_absolute_url�absolute_url�form_urlrr��save_as�save_on_top�to_field_var�is_popup_varrzadmin/%s/%s/change_form.htmlzadmin/%s/change_form.htmlzadmin/change_form.html)r|r�rr�rr�r}r~rrer�r�r�rrLr�r�r�TO_FIELD_VARr��add_form_template�change_form_templaterxrv�current_appr1r6)r\r��contextr�rr�rIrrr��view_on_site_urlr�r�
form_templaterJrJrK�render_change_formisz

����
�������
���������
��zModelAdmin.render_change_formcCs�|j}|�|�}td|j|jft|j�f|jjd�}|�	||�r*t
dt|�|�}nt|�}|j
|d�}t|jvrs|j�t�}	|	rFt|	�}
n|jjj}
|�|
�}t�t|�t|�d��}t||jpnd|j|jfd|jdgd	|i�Sd
|jvs�d|jvr�|jr�|�	||�r�td�}
|�	||�r�|
d
td�7}
|�|t
|
fi|��tj�|dur�|}t||d�|�}t|�Sd|jvr�t
td�fi|��}
|�||
tj�|j}t||d�|�}t|�St
td�fi|��}
|�||
tj�|� ||�S)zD
        Determine the HttpResponse for the add_view stage.
        �admin:%s_%s_change�r0r�<a href="{}">{}</a>�rvrI)r�rI�admin/%s/%s/popup_response.html�admin/%s/popup_response.html�admin/popup_response.html�popup_response_data�	_continue�
_saveasnewu.The {name} “{obj}” was added successfully.r�zYou may edit it again below.Nr��_addanotheruPThe {name} “{obj}” was added successfully. You may add another {name} below.)!r�r�r2rr6rr�rxrvr~r4�urlquoter�r�r��POSTrzr�attname�serializable_value�json�dumpsr1�popup_response_template�save_as_continuer�r�r�SUCCESSrr.r.�response_post_save_add)r\r�rI�post_url_continuerr��obj_url�obj_repr�msg_dictr�attrr�rr��redirect_urlrJrJrK�response_add�s~

��



�
���

��
����zModelAdmin.response_addc
Cst|jvrJ|j}|j�t�}|rt|�n|jj}|jj	d}|�
|�}t�dt|�t|�t|�d��}t
||jpEd|j|jfd|jdgd|i�S|jj}|�|�}	|jtdt|j�|�d	�}
d
|jvr�ttd�fi|
��}|�||tj�|j}t|	|d�|�}t|�Sd
|jvr�ttd�fi|
��}|�||tj�td|j|jf|jf|jjd�}t|	|d�|�}t|�Sd|jvr�ttd�fi|
��}|�||tj�td|j|jf|jjd�}t|	|d�|�}t|�Sttd�fi|
��}|�||tj�|� ||�S)zG
        Determine the HttpResponse for the change_view stage.
        r�r)r�r�rI�	new_valuerrrrr
rruMThe {name} “{obj}” was changed successfully. You may edit it again below.r�ruKThe {name} “{obj}” was added successfully. You may edit it again below.rrruRThe {name} “{obj}” was changed successfully. You may add another {name} below.zadmin:%s_%s_add�ru0The {name} “{obj}” was changed successfully.)!r�rr�rzrr�r�rr�r]rrrr1rrr6r|r�r�r4rr.r�r�rrrr.r2rxrv�response_post_save_change)
r\r�rIrrr$r�r'rr�r#r�r%rJrJrK�response_change�s�

�
���
�
��
��
��
��
����zModelAdmin.response_changecCsh|jj}|�|�r(td|j|jf|jjd�}|�|�}t	||d�|�}t
|�Std|jjd�}t
|�S)Nr�r(r��admin:index)r|r�rr2rr6rxrvr�rr.)r\r�rIr�post_urlr�rJrJrK�_response_post_save0s

��
��zModelAdmin._response_post_savecC�|�||�S)zy
        Figure out where to redirect after the 'Save' button has been pressed
        when adding a new object.
        �r-r�rJrJrKr=r�z!ModelAdmin.response_post_save_addcCr.)z�
        Figure out where to redirect after the 'Save' button has been pressed
        when editing an existing object.
        r/r�rJrJrKr)Dr�z$ModelAdmin.response_post_save_changecCsTzt|j�dd��}Wntyd}Ynw|j��}|�tjd�|�dd�z|�d|�	d�|i�Wn	t
y@Ynw|j|dd�}|�|�|j
d_|��r�|jd}|jd}|�|�|d}|j�	tj�}	|	s�|s�td�}
|�||
tj�dS|s�|j|	d�}||||�}t|t�r�|St|���Std	�}
|�||
tj�dS)
z�
        Handle an admin action. This is called if a request is POSTed to the
        changelist; it returns an HttpResponse if the action was handled, and
        None otherwise.
        �indexrNr���auto_id�
select_across�WItems must be selected in order to perform actions on them. No items have been changed.��pk__inzNo action selected.)r�rrzrpr_rVr	r�re�getlist�
IndexError�action_formr�r�rn�is_valid�cleaned_datardr�r�r�WARNINGr�rpr/r.�
get_full_path)r\r�r��action_index�datar9r�r3r��selectedr��responserJrJrK�response_actionKsB
�
�


zModelAdmin.response_actioncCs�|jj}t|jvr*t�dt|�d��}t||jp%d|j	|j
fd|j	dgd|i�S|�|td�|j
|d�tj�|�|d	�r_td
|j	|j
f|jjd�}|�|�}t||d�|�}t|�Std
|jjd�}t|�S)zG
        Determine the HttpResponse for the delete_view stage.
        r)r�r�rrrru4The %(name)s “%(obj)s” was deleted successfully.rNr�r(r�r+)r|r�r�rrrr�r1rrr6r�r�r�rrr~r2rxrvr�rr.)r\r��obj_display�obj_idrrr,r�rJrJrK�response_delete�sD
�
�����	�

��zModelAdmin.response_deletecCsR|jj}|j}|jj|_|jtt|j	d�t
||jp&d�||j
�d�|�dg|�S)N)rrrOz$admin/{}/{}/delete_confirmation.htmlz!admin/{}/delete_confirmation.htmlzadmin/delete_confirmation.html)r|r�rrxrvrrerr�rOr1�delete_confirmation_template�formatr6)r\r�rrrrJrJrK�render_delete_form�s"
���zModelAdmin.render_delete_formc
Cs�|r|�||�n|�|�}g}t||�D]W\}}t|�||��}	t|�||��}
|r=|�||�}|�||�}|�||�}
nd}}}
d|_|_|�	||�}t
|�||��}tj
|||	||
||||
|d�
}|�|�q|S)NFr)r2r}r~rr�)r~r}�zipr�r�r�rrNr*r�rXr�r	�InlineAdminFormSetr�)r\r�r�r+rI�can_edit_parentr�rr�r��readonlyr}r~rr��prepopulated�inline_admin_formsetrJrJrK�get_inline_formsets�s(�zModelAdmin.get_inline_formsetsc	Cs`t|j���}|D]$}z	|jj�|�}Wn	tyYq	wt|tj	�r-||�
d�||<q	|S)zJ
        Get the initial form data from the request's GET params.
        �,)rXr�rcr|r�r�rrpr!rrr�)r\r��initialrgr�rJrJrK�get_changeform_initial_data�s��z&ModelAdmin.get_changeform_initial_datacCs@td�|jt|�d�}|�||tj�td|jjd�}t	|�S)z�
        Create a message informing the user that the object doesn't exist
        and return a redirect to the admin index page.
        uG%(name)s with ID “%(key)s” doesn’t exist. Perhaps it was deleted?)rv�keyr+r()
r�r�rr�rr<r2rxrvr.)r\r�rr�r�rFrJrJrK� _get_obj_does_not_exist_redirect�s�z+ModelAdmin._get_obj_does_not_exist_redirectcCsHtjt�|j�d��|�||||�Wd�S1swYdS�Nr�)r#�atomicr"�db_for_writer|�_changeform_view�r\r�r�r��
extra_contextrJrJrK�changeform_views$�zModelAdmin.changeform_viewcCs�|j�t|j�t��}|r|�||�std|��|j}|j}|jdkr+d|jvr+d}|du}|r;|�	|�s8t
�d}	n*|�|t|�|�}	|jdkrR|�
||	�sQt
�n|�||	�sZt
�|	dure|�|||�S|�||	�}
|j||	|t|
�d�}|jdkr�||j|j|	d�}|��}
|
r�|j|||d�}n|j}|j|||d�\}}t|�r�|
r�|�||||�|�||||�|�||||�}|r�|�|||�|�||�S|�|||�|�||�Sd}
n'|r�|� |�}||d�}|j||jdd�\}}n||	d�}|j||	d	d�\}}|�s|�
||	��st|
�}n|�!||	�}t"j#|t$|
�|�s.|�
||	��r4|�%||	�ni||d
�}|j&|j&}|�'||||	�}|D]}||j&}�qJ|�r[t(d�}n|�
||	��rgt(d�}nt(d
�}i|j)�*|��||j+|	�r}t,|	�nd|||	t-|jv�p�t-|jv|||t"�.||�|�/|�d��}|jdk�r�|
�s�d|jv�r�d|d<d|d<d}|�0|�p�i�|j1|||||	|d�S)N�"The field %s cannot be referenced.rr)rr�)�instancer�F)rQT)r2zAdd %sz	Change %szView %s)�title�subtitler�r��original�is_popuprrOr��errorsr��	show_save�show_save_and_continue)r�rrIr�)2rrzrr�rrr|r��methodr}rrrrr~rrTr�rRr�FILESr:r�r]�_create_formsetsr&r�r�rr�r&r�r*rRr�r	�	AdminFormr�r�rOrOr�rx�each_contextr�r�r��AdminErrorListr�rer
)r\r�r�r�rZrr|rr�rIr�r!r��form_validated�
new_objectr�r+r�rQr��	adminFormrO�inline_formsets�inline_formsetr^rrJrJrKrXs�

��




"�


�
�zModelAdmin._changeform_viewcCs|�|d||�SrY�r[)r\r�r�rZrJrJrKr8xrQzModelAdmin.add_viewcCs|�||||�SrYrprYrJrJrKr;{rQzModelAdmin.change_viewcs8t�d�t�|�|jjjj����fdd�|j�	�D�S)z6Return POST data values of list_editable primary keys.z
{}-\d+-{}$csg|]\}}��|�r|�qSrJ)r�)r�rSr���
pk_patternrJrKrG�r�z5ModelAdmin._get_edited_object_pks.<locals>.<listcomp>)
�re�compilerG�escaper|r�r�rvrrc)r\r��prefixrJrqrK�_get_edited_object_pks~s�z!ModelAdmin._get_edited_object_pkscCs\|�||�}|�|�}|jjjj}z|D]}||�qWnty'|YSw|j|d�S)zr
        Based on POST data, return a queryset of the objects that were edited
        via list_editable.
        r5)rwr�r|r�r�rnrr�)r\r�rv�
object_pksr��validater�rJrJrK�_get_list_editable_queryset�s

��z&ModelAdmin._get_list_editable_querysetcCsddlm}|jj}|j}|�|�st�z|�|�}Wn$ty?||j	vr2t
ddtd�i�YSt|j
d|d�YSwd}|j�tj�}|�|�}	|	r�|jd	kr�d
|jvr�d|jvr�|rr|j||�|�d�}
|
ro|
Sd
}ntd�}|�||tj�d
}|	r�|jd	kr�tj|jvr�d
|jvr�d|jvr�|r�|j||�|�d�}
|
r�|
Sd
}|r�t|���Sd}|_|jd	k�rD|j�rDd|jv�rD|�|�s�t�|�|�}
|�||
���}|
|j|j |d�}|_|�!��rCd}|j"D]3}|�#��r#|j$||d
d�}|j%|||d
d�|j&||gd
d�|�'||d�}|�(|||�|d7}q�|�r=t)dd|�|t*||�d�}|�||tj+�t|���Sn|j�r\|�|��r\|�|�}
|
|j,d�}|_|�rf|j-|j-}n|j-}|	�r�|j.dd�}|�/|�|j0d_1||j-7}nd}t)dd|j2�}i|j3�4|��idt5|j6��dtd�dt7|j,�i�d|d|j2i�d|j8�d d�d!|j9�d"|j:�d#|�d$|�d%|�;|��d&|j<�d'|�d(|j=�d)|j>�d*|j?�d+|�@|���|�p�i�}|j3jA|_BtC||jD�p�d,||jEfd-|d.g|�S)/z>
        The 'change list' admin view for this model.
        r)�
ERROR_FLAGzadmin/invalid_setup.htmlr^zDatabase error�?z=1Frr0�_saver�Tr4Nr�)r�rrBz,%(count)s %(name)s was changed successfully.z-%(count)s %(name)s were changed successfully.)�countrvr1r�z%(total_count)s selectedzAll %(total_count)s selected�module_name�selection_notez0 of %(cnt)s selected�cnt�selection_note_all�total_countr_rar�clrOr}rr9�actions_on_top�actions_on_bottom�actions_selection_counterr�zadmin/%s/%s/change_list.htmlzadmin/%s/change_list.htmlzadmin/change_list.html)Fr`r{r|r�rrrrmrRr�r0r�r.r.rr7r	r�rdrerBr�r�rr<r=r�rjr~rurz�get_default_prefixrfr:r�has_changedr�r�r�rr�r=rr�result_listrOr9r�r�rn�result_countrxrir��verbose_name_pluralr�r^rarr}rr�r�r�r�rvrr1�change_list_templater6)r\r�rZr{rrr��
action_failedr@r�rAr�r��FormSet�modified_objects�changecountr�rI�
change_msgrOr9r�rrJrJrKr7�s


��

 




�����
�
�
�������	�
�
��
����
��
��zModelAdmin.changelist_viewcCst|||j�S)zw
        Hook for customizing the delete process for the delete view and the
        "delete selected" action.
        )rrx)r\�objsr�rJrJrKr1szModelAdmin.get_deleted_objectscCsFtjt�|j�d��|�|||�Wd�S1swYdSrU)r#rVr"rWr|�_delete_view)r\r�r�rZrJrJrKr:8s$�zModelAdmin.delete_viewcCs||jj}|j}|j�t|j�t��}|r |�||�s td|��|�	|t
|�|�}|�||�s1t�|dur<|�
|||�S|�|g|�\}}	}
}|jrw|sw|
rPt�t|�}|rZt|�n|jj}
|�|
�}|�|||�|�||�|�|||�St|j�}|
s�|r�td�d|i}ntd�}i|j�|��|d|||t|	���|
||||�|�t|jvp�t|jv|d�
�|p�i�}|�||�S)z'The 'delete' admin view for this model.r\NzCannot delete %(name)srvz
Are you sure?)
r^r_�object_namer��deleted_objects�model_count�
perms_lacking�	protectedrrr�rar)r|r�rrrzrr�rrrrrrrrTrr�r�rrr�r�rEr�r�rxrirXrcr�r�rH)r\r�r�rZrrrrIr�r��perms_neededr�rCr$rDr�r^rrJrJrKr�=sX



�
��zModelAdmin._delete_viewc
Cs�ddlm}|j}|�|t|��}|dur|�||j|�S|�||�s%t�|j}|j	}|j
jt|�t|�d��
��d�}	i|j�|��td�|d|	tt|j��|||�|�d��|p\i�}
|jj|_t||jpsd||jfd	|d
g|
�S)z(The 'history' admin view for this model.r)rN)r��content_type�action_timezChange history: %s)r^r_�action_listrr�rr�zadmin/%s/%s/object_history.htmlzadmin/%s/object_history.htmlzadmin/object_history.html)r�rr|rrrrTr�rrrrGr�rL�select_relatedr�rxrir�r�r7r�r�rvrr1�object_history_templater6)r\r�r�rZrr|rIrrr�rrJrJrKr9xsH�
�
�
�	�

��zModelAdmin.history_viewcs(g}g}i}|g}|r|�|�|j|�D]z\}�|��}	|�|	d�d||	<||	dks/|	s7d|	||	f}	||	��|�d�}
|jdkrU|
�|j��|j	d|jvd��|di|
��}�fdd	�}��
||ri|nd
�s�t|j�D]\}
}|||||
�r}qqi|_
|j|_qq|�|�|���q||fS)z9Helper function to generate formsets for add/change_view.rrBz%s-%s)r]rvr�rr)r?�files�save_as_newcs ��||�od�|j|�|jvS)z0Return whether or not the user deleted the form.z{}-{}-DELETE)rrGrvr)r�rIr�r0�rrJrK�user_deleted_form�s�z6ModelAdmin._create_formsets.<locals>.user_deleted_formNrJ)r�rwr�rzr�rererr_rfr~�	enumerate�
initial_forms�_errorsrQr;)r\r�rIrr�r+�prefixes�get_formsets_argsr�rv�formset_paramsr�r�r0r�rJr�rKrg�s@
�
�	

zModelAdmin._create_formsetsrY�NF)rT)F)FFr�N)Nr�N)r�N)orSrTrUr rkrlr�r�rhrirjr�r�r�rrr rxr�r�rrr�rF�%delete_selected_confirmation_templater�rr�r	�
ActionFormr9r�r�r�r
rZrir%r-r>�propertyr?rOrPr�rRrarmrrrtrurwr|r�r�r�rr6rb�staticmethodr�r�r�rdr!�BLANK_CHOICE_DASHr�r�r�rcrergrfr�r�rr�INFOr�r�r�r�r�r�r�r
r&r*r-rr)rBrErHrOrRrT�csrf_protect_mr[rXr8r;rwrzr7rr:r�r9rg�
__classcell__rJrJr)rKr$'s�



0




4

�

/MK
C)


r

;)r$cs�eZdZdZdZdZeZdZdZ	dZ
dZdZdZ
dZdZeZdZ�fdd�Zedd	��Zd d
d�Zd dd
�Zd dd�Zd dd�Zd dd�Z�fdd�Zdd�Z�fdd�Zd �fdd�	Zd �fdd�	Zd �fdd�	Z �Z!S)!�InlineModelAdminz�
    Options for inline editing of ``model`` instances.

    Provide ``fk_name`` to specify the attribute name of the ``ForeignKey``
    from ``model`` to its parent. This is required if ``model`` has more than
    one ``ForeignKey`` to its parent.
    N�TFcsb||_||_|jj|_|�|j�|_t���|j	dur"|jjj	|_	|j
dur/|jjj
|_
dSdSrY)rx�parent_modelr|r�r�
is_registered�has_registered_modelr(rir�r�)r\r�rxr)rJrKri�s



�zInlineModelAdmin.__init__cCsftjrdnd}d|ddg}|js|jr|�ddg�|jr(d|jvr(|�d	�tjd
d�|D�d�S)
Nr�r@rArBz
inlines.jszSelectBox.jszSelectFilter2.js�collapsezcollapse.jscSrCrDrJrErJrJrKrG�rHz*InlineModelAdmin.media.<locals>.<listcomp>rI)	rrKr�r�rW�classesr�rrLrMrJrJrKrO�s
zInlineModelAdmin.mediacKr�)z6Hook for customizing the number of extra inline forms.)rN�r\r�rIr]rJrJrK�	get_extra�r�zInlineModelAdmin.get_extracKr�)z4Hook for customizing the min number of inline forms.)�min_numr�rJrJrK�get_min_num�r�zInlineModelAdmin.get_min_numcKr�)z:Hook for customizing the max number of extra inline forms.)r*r�rJrJrK�get_max_numr�zInlineModelAdmin.get_max_numcs�d|vr
|�d�}nt|�||��}|�||�}|durgnt|�}|�|�||��|durBt|jd�rB|jj	j
rB|�|jj	j
�|pEd}|joN|�||�}|j|j
|j||t|j|d�|j||fi|��|j||fi|��|j||fi|��|d�
|�}|d}	|r�|�||�nd�|r�|�||�nd�G��fdd	�d	|	�}
|
|d<|ddur�t|d�s�tj|d<t|j|jfi|��S)
zCReturn a BaseInlineFormSet class for use in admin add/change views.r�Nr�rT)
r�r��fk_namer�r�rUrNr�r*�
can_deleter�Tcs4eZdZdd�Z�fdd�Z���fdd�Z�ZS)z>InlineModelAdmin.get_formset.<locals>.DeleteProtectedModelFormcSs�|j�td�rUt�|jj�}t|d�}|jj	j
rdS|�|jg�|jrWg}|jD]}|�
td�|jj|d��q)|jjjj|jt|td��d�}td�}t|d	|d
��dSdS)z�
                We don't validate the 'DELETE' field itself because on
                templates it's not rendered using the field information, but
                just using a generic "deletion_field" of the InlineModelAdmin.
                Fr�Nz%(class_name)s %(instance)s)�
class_namer]�and)r�r]rzxDeleting %(class_name)s %(instance)s would require deleting the following protected related objects: %(related_objects)s�deleting_protected)�code�params)r;rzr%r"rWr�r|rr]�_state�adding�collectr�r�r�r�r9r)r\r��	collectorr��pr�r�rJrJrK�hand_clean_DELETE+s.


��
��zPInlineModelAdmin.get_formset.<locals>.DeleteProtectedModelForm.hand_clean_DELETEcst���}|��|SrY)r(r:r�)r\�resultr)rJrKr:Ks
zGInlineModelAdmin.get_formset.<locals>.DeleteProtectedModelForm.is_validcs.�s	|jjjs	dS�s|jjjrdSt���Sr�)r]r�r�r(r�r�)rs�can_add�
can_changerJrKr�Ps

zJInlineModelAdmin.get_formset.<locals>.DeleteProtectedModelForm.has_changed)rSrTrUr�r:r�r�rJ�r�r�r)rK�DeleteProtectedModelForm)s r�)rVrr�r�r�rWr�r�r�r�r�r�rr�r�rr�r�r�r�r~r}r)rrZr(r�r|)r\r�rIr]r�r[r�r�r]�base_model_formr�rJr�rKrvs>��/
zInlineModelAdmin.get_formsetcCs|j||dd�jSrQ)rvr�r�rJrJrKr�_sz)InlineModelAdmin._get_form_for_get_fieldscs"t��|�}|�|�s|��}|SrY)r(r�r�noner�r)rJrKr�bs
zInlineModelAdmin.get_querysetcsL|j��jD]}|jr|jj|jkr|jjj�nqt��fdd�|D��S)a1
        This method is called only when the ModelAdmin's model is for an
        ManyToManyField's implicit through model (if self.opts.auto_created).
        Return True if the user has any of the given permissions ('add',
        'change', etc.) for the model that points to the through model.
        c3s,�|]}�j�d�jt|��f�VqdS)rN)rrrr)r��perm�rr�rJrKr�us
��
�zCInlineModelAdmin._has_any_perms_for_target_model.<locals>.<genexpr>)rr�r{r|r�r�r)r\r��permsr�rJr�rK�_has_any_perms_for_target_modelhs

��z0InlineModelAdmin._has_any_perms_for_target_modelc�"|jjr|�|dg�St��|�S�Nr)rr�r�r(r}r�r)rJrKr}zsz#InlineModelAdmin.has_add_permissioncr�r�)rr�r�r(r~r�r)rJrKr~�sz&InlineModelAdmin.has_change_permissioncs$|jjr|�|dg�St��||�Sr�)rr�r�r(rr�r)rJrKr�sz&InlineModelAdmin.has_delete_permissioncs$|jjr|�|ddg�St��|�S)Nrr)rr�r�r(r�r�r)rJrKr��sz$InlineModelAdmin.has_view_permissionrY)"rSrTrUr r|r�r'r�rNr�r*�templater�r�r��show_change_linkrrZr�rir�rOr�r�r�rvr�r�r�r}r~rr�r�rJrJr)rKr��s:

	



Y	r�c@�eZdZdZdS)�
StackedInlinezadmin/edit_inline/stacked.htmlN�rSrTrUr�rJrJrJrKr���r�c@r�)�
TabularInlinezadmin/edit_inline/tabular.htmlNr�rJrJrJrKr��r�r�)�r_rr�rs�	functoolsrrr�urllib.parserr�djangor�django.confr�django.contribr�django.contrib.adminr	r
�django.contrib.admin.checksrrr
�django.contrib.admin.decoratorsr�django.contrib.admin.exceptionsr�,django.contrib.admin.templatetags.admin_urlsr�django.contrib.admin.utilsrrrrrrrr�django.contrib.admin.widgetsrr�django.contrib.authr�django.core.exceptionsrrrr�django.core.paginatorr �	django.dbr!r"r#�django.db.models.constantsr$�django.forms.formsetsr%r&�django.forms.modelsr'r(r)r*r+�django.forms.widgetsr,r-�django.httpr.�django.http.responser/�django.template.responser0r1r5r2�django.utils.decoratorsr3�django.utils.htmlr4�django.utils.httpr5�django.utils.safestringr6�django.utils.textr7r8r9r:r;�django.utils.translationr<r�r=�django.views.decorators.csrfr>�django.views.genericr?r�r�
HORIZONTALrNrLrP�	ExceptionrR�
DateTimeField�SplitDateTimeField�AdminSplitDateTime�	DateField�AdminDateWidget�	TimeField�AdminTimeWidget�	TextField�AdminTextareaWidget�URLField�AdminURLFieldWidget�IntegerField�AdminIntegerFieldWidget�BigIntegerField�AdminBigIntegerFieldWidget�	CharField�AdminTextInputWidget�
ImageField�AdminFileWidget�	FileField�
EmailField�AdminEmailInputWidget�	UUIDField�AdminUUIDInputWidgetrar��MediaDefiningClassrXr$r�r�r�rJrJrJrK�<module>s�,��F3I

https://t.me/RX1948 - 2025