HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberCP/lib/python3.10/site-packages/django/forms/__pycache__/models.cpython-310.pyc
o

�h���@sJdZddlmZddlmZmZmZmZddlm	Z	ddl
mZmZddl
mZmZddlmZmZddlmZdd	lmZmZmZmZdd
lmZmZddlmZddlmZ d
Z!dZ"d>dd�Z#d>dd�Z$dd�Z%									d?dd�dd�Z&Gdd�d�Z'Gdd�de�Z(Gdd�dee	�Z)Gd d!�d!e)e(d"�Z*e*dddddddddf
d#d$�Z+Gd%d&�d&ee	�Z,e*de,d'd(d(ddddd(dddddd(ddddd(fd)d*�Z-Gd+d,�d,e,�Z.d@d-d.�Z/e*e.dddd/d(ddddd(dddddd(ddddd(fd0d1�Z0Gd2d3�d3e�Z1Gd4d5�d5�Z2Gd6d7�d7�Z3Gd8d9�d9e�Z4Gd:d;�d;e4�Z5d<d=�Z6dS)Az[
Helper functions for creating Form classes from Django models
and database field objects.
�)�chain)�NON_FIELD_ERRORS�
FieldError�ImproperlyConfigured�ValidationError)�
AltersData)�ChoiceField�Field)�BaseForm�DeclarativeFieldsMetaclass)�BaseFormSet�formset_factory)�	ErrorList)�HiddenInput�MultipleHiddenInput�RadioSelect�SelectMultiple)�capfirst�
get_text_list��gettext)�gettext_lazy)�	ModelForm�
BaseModelForm�
model_to_dict�fields_for_model�ModelChoiceField�ModelMultipleChoiceField�
ALL_FIELDS�BaseModelFormSet�modelformset_factory�BaseInlineFormSet�inlineformset_factory�modelform_factory�__all__Nc	Cs�ddlm}|j}|j}g}|jD]\}|jr!t||j�s!|j|vr"q|dur,|j|vr,q|r4|j|vr4q|�	�rX||jj
j�|j
|j|�|j��rX|�|j�||jj
jvrXqt||j�rd|�|�q|�|||j�q|D]}|�|||j�qp|S)z�
    Construct and return a model instance from the bound ``form``'s
    ``cleaned_data``, but do not save the returned instance to the database.
    r)�modelsN)�	django.dbr%�_meta�cleaned_data�fields�editable�
isinstance�	AutoField�name�has_default�field�widget�value_omitted_from_data�data�files�
add_prefix�get�empty_values�	FileField�append�save_form_data)	�form�instancer)�excluder%�optsr(�file_field_list�f�r@�F/usr/local/CyberCP/lib/python3.10/site-packages/django/forms/models.py�construct_instance.s:
�
�
���rBcCsh|j}i}t|j|j|j�D]#}t|dd�sq|dur!|j|vr!q|r)|j|vr)q|�|�||j<q|S)a�
    Return a dict containing the data in ``instance`` suitable for passing as
    a Form's ``initial`` keyword argument.

    ``fields`` is an optional list of field names. If provided, return only the
    named.

    ``exclude`` is an optional list of field names. If provided, exclude the
    named from the returned dict, even if they are listed in the ``fields``
    argument.
    r*FN)r'r�concrete_fields�private_fields�many_to_many�getattrr-�value_from_object)r;r)r<r=r2r?r@r@rAr^srcCs�ddlm}m}m}t|d�rBt|d�rD|��}|rF|}t||�s(|di|��}|||d�d�M}|j�||jj	j
�|���|_dSdSdSdS)	z=Apply limit_choices_to to the formfield's queryset if needed.r)�Exists�OuterRef�Q�queryset�get_limit_choices_to�pk�rMNr@)�django.db.modelsrHrIrJ�hasattrrLr+rK�filter�model�
_base_manager)�	formfieldrHrIrJ�limit_choices_to�complex_filterr@r@rA�#apply_limit_choices_to_to_formfieldws

��rWT��apply_limit_choices_toc
s�i�g�|j}ddlm��fdd�|jD�}tt|j||j��D]�}
t|
dd�sF|durE|
j	|vrE�dus;|
j	�vrEt
d|
j	|jf��q!|durP|
j	|vrPq!�rX|
j	�vrXq!i}|rh|
j	|vrh||
j	|d	<|tkss|rw|
j	|vrwd
|d<|r�|
j	|vr�||
j	|d<|r�|
j	|vr�||
j	|d
<|r�|
j	|vr�||
j	|d<|	r�|
j	|	vr�|	|
j	|d<|dur�|
j
di|��}nt|�s�td��||
fi|��}|r�|
r�t|�|�|
j	<q!��|
j	�q!|r���fdd�|D���S)a4
    Return a dictionary containing form fields for the given model.

    ``fields`` is an optional list of field names. If provided, return only the
    named fields.

    ``exclude`` is an optional list of field names. If provided, exclude the
    named fields from the returned fields, even if they are listed in the
    ``fields`` argument.

    ``widgets`` is a dictionary of model field names mapped to a widget.

    ``formfield_callback`` is a callable that takes a model field and returns
    a form field.

    ``localized_fields`` is a list of names of fields which should be localized.

    ``labels`` is a dictionary of model field names mapped to a label.

    ``help_texts`` is a dictionary of model field names mapped to a help text.

    ``error_messages`` is a dictionary of model field names mapped to a
    dictionary of error messages.

    ``field_classes`` is a dictionary of model field names mapped to a form
    field class.

    ``apply_limit_choices_to`` is a boolean indicating if limit_choices_to
    should be applied to a field's queryset.
    r)r	csg|]	}t|��r|�qSr@)r+��.0r?)�
ModelFieldr@rA�
<listcomp>�s

��z$fields_for_model.<locals>.<listcomp>r*FNzH'%s' cannot be specified for %s model form as it is a non-editable fieldr0T�localize�label�	help_text�error_messages�
form_classz1formfield_callback must be a function or callablecs,i|]}�r
|�vr|�vr|��|��qSr@)r5rZ)r<�
field_dict�ignoredr@rA�
<dictcomp>�s�
�z$fields_for_model.<locals>.<dictcomp>r@)r'rOr	rD�sortedrrCrErFr-r�__name__rrT�callable�	TypeErrorrWr8)rRr)r<�widgets�formfield_callback�localized_fields�labels�
help_textsra�
field_classesrYr=�sortable_private_fieldsr?�kwargsrTr@)r\r<rcrdrAr�sn,
��

���
�rc@seZdZddd�ZdS)�ModelFormOptionsNcCs�t|dd�|_t|dd�|_t|dd�|_t|dd�|_t|dd�|_t|dd�|_t|dd�|_t|dd�|_t|d	d�|_	t|d
d�|_
dS)NrRr)r<rjrlrmrnrarork)rFrRr)r<rjrlrmrnrarork)�self�optionsr@r@rA�__init__�szModelFormOptions.__init__�N)rg�
__module__�__qualname__rur@r@r@rArr�srrcseZdZ�fdd�Z�ZS)�ModelFormMetaclassc

s@t��||||�}|tfkr|Stt|dd��}|_dD]}t||�}t|t�r:|tkr:d|j	||d�}t
|��q|jr�|jdurN|j
durNtd|��|jtkrVd|_t|j|j|j
|j|j|j|j|j|j|jdd�}	dd	�|	��D�}
|
�|j�}|r�d
}|d�|�|jj	f;}t|��|	�|j�n|j}	|	|_|S)N�Meta)r)r<rlzP%(model)s.Meta.%(opt)s cannot be a string. Did you mean to type: ('%(value)s',)?)rR�opt�valuez|Creating a ModelForm without either the 'fields' attribute or the 'exclude' attribute is prohibited; form %s needs updating.FrXcSsh|]\}}|s|�qSr@r@)r[�k�vr@r@rA�	<setcomp><sz-ModelFormMetaclass.__new__.<locals>.<setcomp>z&Unknown field(s) (%s) specified for %sz, )�super�__new__rrrrFr'r+�strrrgrirRr)r<rrrjrkrlrmrnraro�items�
difference�declared_fields�joinr�update�base_fields)
�mcsr-�bases�attrs�	new_classr=r{r|�msgr)�none_model_fields�missing_fields�message��	__class__r@rAr�s`

���	���
�zModelFormMetaclass.__new__)rgrwrxr��
__classcell__r@r@r�rArysrycsteZdZdddddedddddf�fdd�	Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
ddd�Zde_�Z
S)rN�id_%sFcs�|j}|jdurtd��|	dur|��|_i}
n|	|_t|	|j|j�}
|dur,|
�|�d|_t	�j
|||||
||||
|d�
|j��D]}t|�qDdS)Nz'ModelForm has no model class specified.F)�use_required_attribute�renderer)
r'rR�
ValueErrorr;rr)r<r��_validate_uniquer�ru�valuesrW)rsr2r3�auto_id�prefix�initial�error_class�label_suffix�empty_permittedr;r�r�r=�object_datarTr�r@rAruNs4


�
�zBaseModelForm.__init__cCs�t�}|jjjD][}|j}||jvr|�|j�q|jjr*||jjvr*|�|j�q|jjr;||jjvr;|�|j�q||jvrG|�|j�q|j|}|j�	|�}|j
sc|jsc||jvrc|�|j�q|S)z�
        For backwards-compatibility, exclude several types of fields from model
        validation. See tickets #12507, #12521, #12553.
        )
�setr;r'r)r-�addr<�_errorsr(r5�blank�requiredr6)rsr<r?r/�
form_field�field_valuer@r@rA�_get_validation_exclusions|s*


	��
�z(BaseModelForm._get_validation_exclusionscCsd|_|jS)NT)r�r(�rsr@r@rA�clean�szBaseModelForm.cleancCs�|j}t|d�r|j}nt|i}|��D]8\}}|tkr*|jr*t|jvr*|jt}n
||jvr6|j|j}nq|D]}t|t�rK|j	|vrK||j	|_
q9q|�d|�dS)N�
error_dict)r'rPr�rr�rar)r+r�coder��	add_error)rs�errorsr=r�r/�messagesrar�r@r@rA�_update_errors�s*
�

�
��zBaseModelForm._update_errorsc
Cs�|j}|��}|j��D]\}}t|t�r|�|�qz
t||j|j|j	�|_Wnt
y?}z|�|�WYd}~nd}~wwz
|jj|dd�Wnt
ya}z|�|�WYd}~nd}~ww|j
rk|��dSdS)NF)r<�validate_unique)r'r�r)r�r+�InlineForeignKeyFieldr�rBr;r<rr��
full_cleanr�r�)rsr=r<r-r/�er@r@rA�_post_clean�s.	

�
������zBaseModelForm._post_cleanc
CsN|��}z
|jj|d�WdSty&}z|�|�WYd}~dSd}~ww)z�
        Call the instance's validate_unique() method and update the form's
        validation errors if any were raised.
        )r<N)r�r;r�rr�)rsr<r�r@r@rAr��s��zBaseModelForm.validate_uniquecCs�|j}|jj}|jj}|jj}t|j|j�D]'}t|d�sq|r&|j	|vr&q|r.|j	|vr.q|j	|vr=|�
|j||j	�qdS)zS
        Save the many-to-many fields and generic relations for this form.
        r9N)r(r'r<r)r;rrErDrPr-r9)rsr(r<r)r=r?r@r@rA�	_save_m2m�s

��zBaseModelForm._save_m2mTcCsZ|jrtd|jjj|jjjrdf��df��|r&|j��|��|jS|j|_	|jS)z�
        Save this form's self.instance object if commit=True. Otherwise, add
        a save_m2m() method to the form which can be called after the instance
        is saved manually at a later time. Return the model instance.
        z8The %s could not be %s because the data didn't validate.�created�changed)
r�r�r;r'�object_name�_state�adding�saver��save_m2m)rs�commitr@r@rAr�s$������
�zBaseModelForm.save�T)rgrwrxrrur�r�r�r�r�r�r��alters_datar�r@r@r�rArMs*�.-! 
rc@seZdZdS)rN)rgrwrxr@r@r@rAr)sr)�	metaclasscCsd|i}|dur||d<|dur||d<|dur||d<|dur$||d<|dur,||d<|dur4||d<|	dur<|	|d	<|
durD|
|d
<t|d�rM|jfnd}td||�}
|r\t|�|
_|jd
}d|
i}t|
dd�duryt|
dd�durytd��t|�||f|�S)al
    Return a ModelForm containing form fields for the given model. You can
    optionally pass a `form` argument to use as a starting point for
    constructing the ModelForm.

    ``fields`` is an optional list of field names. If provided, include only
    the named fields in the returned fields. If omitted or '__all__', use all
    fields.

    ``exclude`` is an optional list of field names. If provided, exclude the
    named fields from the returned fields, even if they are listed in the
    ``fields`` argument.

    ``widgets`` is a dictionary of model field names mapped to a widget.

    ``localized_fields`` is a list of names of fields which should be localized.

    ``formfield_callback`` is a callable that takes a model field and returns
    a form field.

    ``labels`` is a dictionary of model field names mapped to a label.

    ``help_texts`` is a dictionary of model field names mapped to a help text.

    ``error_messages`` is a dictionary of model field names mapped to a
    dictionary of error messages.

    ``field_classes`` is a dictionary of model field names mapped to a form
    field class.
    rRNr)r<rjrlrmrnrarorzr@�FormzZCalling modelform_factory without defining 'fields' or 'exclude' explicitly is prohibited.)rPrz�type�staticmethodrkrgrFr)rRr:r)r<rkrjrlrmrnraror�r�rz�
class_name�form_class_attrsr@r@rAr#-s80

 �r#cs�eZdZdZdZdZe�Z					d+dd��fdd�Z�fdd	�Z	d
d�Z
dd
�Z�fdd�Zdd�Z
d,dd�Zd,dd�Zd,dd�Zd,dd�Zde_dd�Zdd�Zdd �Zd!d"�Zd#d$�Zd,d%d&�Zd,d'd(�Z�fd)d*�Z�ZS)-rzO
    A ``FormSet`` for editing a queryset and/or adding new objects to it.
    NFr�)r�cs0||_||_t�jdi||||d�|���dS)N)r2r3r�r�r@)rK�
initial_extrar�ru)rsr2r3r�r�rKr�rqr�r@rAru�s
��
�zBaseModelFormSet.__init__cs|js	t|���St���S)z=Return the number of forms that are required in this FormSet.)�is_bound�len�get_querysetr��initial_form_countr�r�r@rAr��s
z#BaseModelFormSet.initial_form_countcCs*t|d�sdd�|��D�|_|j�|�S)N�_object_dictcSsi|]}|j|�qSr@rN�r[�or@r@rAre��z5BaseModelFormSet._existing_object.<locals>.<dictcomp>)rPr�r�r5)rsrMr@r@rA�_existing_object�s
z!BaseModelFormSet._existing_objectcCs$|jdur|j��}|jdus|jS)z�
        If the field is a related field, fetch the concrete field's (that
        is, the ultimate pointed-to field's) to_python.
        N)�remote_field�get_related_field�	to_python�rsr/r@r@rA�_get_to_python�s


�zBaseModelFormSet._get_to_pythoncs||��k}|rR|jrId|�|�|jjjjf}z|j|}Wn	ty(YnDw|�	|jjj�}z||�}Wn	t
y@Yn,w|�|�|d<n#|��||d<n|j
rlz
|j
||��|d<Wn	tykYnwt�j|fi|��}|r�d|j|jjjj_|S)Nz%s-%sr;r�T)r�r�r4rRr'rMr-r2�KeyErrorr�rr�r�r��
IndexErrorr��_construct_formr)r�)rs�irq�pk_required�pk_keyrMr�r:r�r@rAr��s6���z BaseModelFormSet._construct_formcCsLt|d�s#|jdur|j}n|jj��}|js |�|jjjj	�}||_
|j
S)N�	_queryset)rPrKrR�_default_managerr��ordered�order_byr'rMr-r�)rs�qsr@r@rAr��s

zBaseModelFormSet.get_querysetTcCs|j|d�S)z8Save and return a new model instance for the given form.�r��r��rsr:r�r@r@rA�save_new��zBaseModelFormSet.save_newcCs|j|d�S)z>Save and return an existing model instance for the given form.r�r�)rsr:r;r�r@r@rA�
save_existing�r�zBaseModelFormSet.save_existingcCs|r|��dSdS)z#Deletes an existing model instance.N)�delete)rs�objr�r@r@rA�delete_existing�s�z BaseModelFormSet.delete_existingcs@|sg�_�fdd�}|�_�jr��|�S��|���|�S)z�
        Save model instances for every form, adding and changing instances
        as necessary, and return the list of instances.
        cs�jD]}|��qdSrv)�saved_formsr�)r:r�r@rAr�s

�z'BaseModelFormSet.save.<locals>.save_m2m)r�r��	edit_only�save_existing_objects�save_new_objects)rsr�r�r@r�rAr�s
zBaseModelFormSet.savecCs|��dSrv)r�r�r@r@rAr��zBaseModelFormSet.cleancs�t�}t�}�j��fdd��jD�}|D]����}�jj|dd�\}}|�|�|�|�qg}|D]R\}}	t�}
|D]H���fdd�|	D�}tdd�|D��}|r�d|vr�||
vr�|���	|	���j
���g�jd��j
t<|	D]}|�jvr�j|=qt|
�|�q=q4|D]g}
t�}
|
\}}}}|D]Y��jr�j|dur�j|dur�|d	kr��j|}|j|j|jf}n	t�j||�f}�j|f|}||
vr�|���|
���j
���g�jd��j
t<�j|=|
�|�q�q�|r�t|��dS)
Ncs g|]}|��r|�vr|�qSr@)�is_valid)r[r:)�forms_to_deleter@rAr]s��z4BaseModelFormSet.validate_unique.<locals>.<listcomp>T)r<�include_meta_constraintsc3s2�|]}|�jvr|�jvr|n�j|VqdSrv)r(�
unique_fields�r[r/)r:rsr@rA�	<genexpr>1s�
��z3BaseModelFormSet.validate_unique.<locals>.<genexpr>css8�|]}t|d�r
|��n
t|t�rt|�n|VqdS)�_get_pk_valN)rPr�r+�list�tuple)r[�dr@r@rAr�7s��
�)r��date)r��
deleted_forms�formsr�r;�_get_unique_checksr�r�r8�get_unique_error_messager��get_form_errorr�r�rr(r��year�month�dayrF�get_date_error_messager)rs�all_unique_checks�all_date_checks�valid_formsr<�
unique_checks�date_checksr��uclass�unique_check�	seen_data�row_datar/�
date_check�lookup�
unique_forr��	date_datar2r@)r:r�rsrAr�s�
�
�
���
�
��!�
�
���z BaseModelFormSet.validate_uniquecCs:t|�dkrtd�d|diStd�dt|td��iS)N�z0Please correct the duplicate data for %(field)s.r/rzFPlease correct the duplicate data for %(field)s, which must be unique.�and)r�rr�_�rsr	r@r@rAr�ts����z)BaseModelFormSet.get_unique_error_messagecCs$td�|d|dt|d�d�S)NzoPlease correct the duplicate data for %(field_name)s which must be unique for the %(lookup)s in %(date_field)s.��r)�
field_name�
date_fieldr
)rr�)rsrr@r@rAr�s�
��z'BaseModelFormSet.get_date_error_messagecCstd�S)Nz*Please correct the duplicate values below.rr�r@r@rAr��szBaseModelFormSet.get_form_errorcCs�g|_g|_|jsgSg}|j}|jD]=}|j}|jdurq||vr0|j�|�|j||d�q|��rP|j�||j	f�|�|j
|||d��|sP|j�|�q|S�Nr�)�changed_objects�deleted_objects�
initial_formsr�r;rMr8r��has_changed�changed_datar�r�)rsr��saved_instancesr�r:r�r@r@rAr��s(

�z&BaseModelFormSet.save_existing_objectscCsZg|_|jD]#}|��s
q|jr|�|�rq|j�|j||d��|s)|j�|�q|jSr)�new_objects�extra_formsr�
can_delete�_should_delete_formr8r�r�)rsr�r:r@r@rAr��s
�z!BaseModelFormSet.save_new_objectsc	s$ddlm�m}m}|jjj|_}��fdd���|�s#|j|j	vr�|j
r2|jjj
r-dn|jj}nz|dur?|��|j}nd}WntyMd}Ynwt|||f�r]|jjj��}n|jj��}|�|jjj�}|jjrz|jj�|jjt�}nt}t||d|d�|j	|jj<t��||�dS)z0Add a hidden field for the object's primary key.r)r,�
ForeignKey�
OneToOneFieldcs6|jp|jpt|��p|jo|jjo�|jjjj�Srv)r*�auto_createdr+r��parent_linkrRr'rMrN�r,�pk_is_not_editabler@rAr(�s���z7BaseModelFormSet.add_fields.<locals>.pk_is_not_editableNF)r�r�r0)rOr,r#r$rRr'rM�	_pk_fieldr-r)r�r;r�r�r�r�r+r�r��using�dbrjr5rrr��
add_fields)	rsr:�indexr#r$rM�pk_valuer�r0r�r'rAr,�s2���zBaseModelFormSet.add_fields)NNr�NNr�)rgrwrx�__doc__rRr�r�r�rur�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�r,r�r@r@r�rAr�s>��	"



]


rrFcCs�t|dd�}t|d|�durt|d|	�durtd��t||||	||
||
|||d�}t||||||||||||d�}||_||_|S)z8Return a FormSet class for the given Django model class.rzNr)r<z]Calling modelformset_factory without defining 'fields' or 'exclude' explicitly is prohibited.)
r:r)r<rkrjrlrmrnraro)
�extra�min_num�max_num�	can_orderr!�validate_min�validate_max�absolute_max�can_delete_extrar�)rFrr#r
rRr�)rRr:rk�formsetr0r!r3r2r)r<rjr5rlrmrnrar1r4ror6r7r�r��meta�FormSetr@r@rAr �sH��
�r csxeZdZdZ						d�fdd�	Z�fdd�Z�fdd	�Zed
d��Zd�fd
d�	Z	�fdd�Z
�fdd�Z�ZS)r!z0A formset for child objects related to a parent.NFc	s�|dur|jj��|_n||_||_|dur|jj}|jjdur.|jdi|jj|ji��}n|�	�}|jjh|_
t�j||f||d�|��|j
jjrr|jj|j
jjvrtt|j
jjt�rft|j
jj�|j
j_|j
jj�|jj�dSdSdS)N)r�rKr@)�fkr�rRr;�save_as_newr�rMrQr-�noner�r�rur:r'r)r+r�r�r8)	rsr2r3r;r<r�rKrqr�r�r@rAru2s 
�zBaseInlineFormSet.__init__cs|jrdSt���S)Nr)r<r�r�r�r�r@rAr�Qs
z$BaseInlineFormSet.initial_form_countcs�t�j|fi|��}|jr8t|jdd�}|durd|j_d|j|�|jj�<d|j|�|j	j�<|dur8||j_|j
j}|j	jj
|j	jjjjjkrXt|j
|j	jj
�}t|d|�}t|j
|j	��|�|S)N�_mutableTrM)r�r�r<rFr2r>r4r)r-r;r;rMr�rrRr'�setattr�get_attname)rsr�rqr:�mutable�fk_valuer�r@rAr�Vsz!BaseInlineFormSet._construct_formcCs|jjj|jd��dd�S)N)rR�+�)r;r��get_accessor_namerR�replace)�clsr@r@rA�get_default_prefixmsz$BaseInlineFormSet.get_default_prefixTcs$t|j|jj|j�t�j||d�Sr)r?r;r;r-r�r�r�r�r@rAr�qszBaseInlineFormSet.save_newcs�t��||�|j|jkr|jj}ddi}n|jj}dt|j�|�dt|jj	��i}|jj
j|jj
jj
jjkr>|jj
j|d<|jjjre|�d�durT|jj
�|d�}n|jj
j}|��ret|j|jd�t|jfi|��|j|<dS)N�pk_fieldTr_�to_field)r�r,r)r;r-rFr)r5r�verbose_namer�rrRr'rMr;r�r��	get_fieldr.r?�attnamer�)rsr:r-r-rqrJr�r@rAr,xs$
��	

zBaseInlineFormSet.add_fieldscs�fdd�|D�}t��|�S)Ncsg|]
}|�jjkr|�qSr@)r;r-r�r�r@rAr]�sz>BaseInlineFormSet.get_unique_error_message.<locals>.<listcomp>)r�r�rr�r�rAr��sz*BaseInlineFormSet.get_unique_error_message)NNNFNNr�)
rgrwrxr/rur�r��classmethodrHr�r,r�r�r@r@r�rAr!/s �
!r!cs<ddlm�|j}�rc�fdd�|jD�}t|�dkrU|d}�j���t|��rI|jjjj	r7|jjjj
�vsI|jjjj	sS|jj�krS|jj�vrStd��jjf��|S|satd|jj�f��|S�j������fdd�|jD�}t|�dkr�|d}|S|s�|r�d	Std
|jj�jjf��td|jj�jjf��)aD
    Find and return the ForeignKey from model to parent if there is one
    (return None if can_fail is True and no such field exists). If fk_name is
    provided, assume it is the name of the ForeignKey field. Unless can_fail is
    True, raise an exception if there isn't a ForeignKey from model to
    parent_model.
    r)r#csg|]	}|j�kr|�qSr@)r-rZ��fk_namer@rAr]��z$_get_foreign_key.<locals>.<listcomp>rz)fk_name '%s' is not a ForeignKey to '%s'.z'%s' has no field named '%s'.csNg|]#}t|��r%|jj�ks#|jj�vs#|jjjjr%|jjjj�vr|�qSr@)r+r�rRr'�proxy�proxy_for_modelrZ)r#�parent_list�parent_modelr@rAr]�s�
��Nz'%s' has no ForeignKey to '%s'.zR'%s' has more than one ForeignKey to '%s'. You must specify a 'fk_name' attribute.)
rOr#r'r)r��get_parent_listr+r�rRrRrSr�r_)rUrRrP�can_failr=�
fks_to_parentr;r@)r#rPrTrUrA�_get_foreign_key�sf	
�
�
�
��-��(
��
�������rYrcCs�t|||d�}|jrd}
id|�d|�d|�d|�d|	�d|�d	|�d
|�d|�d|
�d
|�d|�d|
�d|�d|�d|�d|�|||||d��}t|fi|��}||_|S)z�
    Return an ``InlineFormSet`` for the given kwargs.

    ``fk_name`` must be provided if ``model`` has more than one ``ForeignKey``
    to ``parent_model``.
    rOrr:rkr8r0r!r3r)r<r1r2rjr4r5rlrmrnra)ror6r7r�r�)rY�uniquer r;)rUrRr:r8rPr)r<r0r3r!r2rkrjr5rlrmrnrar1r4ror6r7r�r�r;rqr:r@r@rAr"�s^!��������	�
���
������r"csHeZdZdZeZded�iZddd��fdd�
Zd	d
�Z	dd�Z
�ZS)
r�zw
    A basic integer field that deals with validating the given value to a
    given parent instance in an inline.
    �invalid_choicez3The inline value did not match the parent instance.FN)rIrJcs`||_||_||_|jdur!|jrt|j|j�|d<n|jj|d<d|d<t�j|i|��dS)Nr�Fr�)�parent_instancerIrJrFrMr�ru)rsr\rIrJ�argsrqr�r@rAru=s
zInlineForeignKeyField.__init__cCs`||jvr
|jr
dS|jS|jrt|j|j�}n|jj}t|�t|�kr-t|jddd��|jS)Nr[�r�)	r6rIr\rJrFrMr�rra)rsr|�origr@r@rAr�Is

�zInlineForeignKeyField.cleancCsdS�NFr@)rsr�r2r@r@rArZsz!InlineForeignKeyField.has_changed)rgrwrxr/rr0r�default_error_messagesrur�rr�r@r@r�rAr�2s�r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�ModelChoiceIteratorValuecCs||_||_dSrv)r|r;)rsr|r;r@r@rAru_s
z!ModelChoiceIteratorValue.__init__cC�
t|j�Srv)r�r|r�r@r@rA�__str__c�
z ModelChoiceIteratorValue.__str__cCrcrv)�hashr|r�r@r@rA�__hash__frez!ModelChoiceIteratorValue.__hash__cCst|t�r|j}|j|kSrv)r+rbr|)rs�otherr@r@rA�__eq__is

zModelChoiceIteratorValue.__eq__N)rgrwrxrurdrgrir@r@r@rArb^s
rbc@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ModelChoiceIteratorcCs||_|j|_dSrv)r/rKr�r@r@rArupszModelChoiceIterator.__init__ccsJ�|jjdurd|jjfV|j}|js|��}|D]}|�|�VqdS)NrD)r/�empty_labelrK�_prefetch_related_lookups�iterator�choice)rsrKr�r@r@rA�__iter__ts��zModelChoiceIterator.__iter__cCs |j��|jjdur
dSdS)Nrr)rK�countr/rkr�r@r@rA�__len__~s zModelChoiceIterator.__len__cCs|jjdup
|j��Srv)r/rkrK�existsr�r@r@rA�__bool__�szModelChoiceIterator.__bool__cCst|j�|�|�|j�|�fSrv)rbr/�
prepare_value�label_from_instance�rsr�r@r@rArn�s
�zModelChoiceIterator.choiceN)rgrwrxrurorqrsrnr@r@r@rArjos
rjc
s�eZdZdZded�iZeZdddddddddd	�	d
d�Zdd
�Z	�fdd�Z
dd�Zdd�Ze
ee�Zdd�Zdd�Ze
eej�Z�fdd�Zdd�Zdd�Zdd�Z�ZS) rz1A ChoiceField whose choices are a model QuerySet.r[zGSelect a valid choice. That choice is not one of the available choices.z	---------TNrDF)	rkr�r0r_r�r`�
to_field_namerUr�c	Ks^tj|f|||||d�|��|r|dust|jt�r!|
s!d|_n||_||_|	|_||_dS)N)r�r0r_r�r`)	r	rur+r0rrkrKrUrw)rsrKrkr�r0r_r�r`rwrUr�rqr@r@rAru�s*���	
��
zModelChoiceField.__init__cCst|j�r	|��S|jS)z�
        Return ``limit_choices_to`` for this form field.

        If it is a callable, invoke it and return the result.
        )rhrUr�r@r@rArL�s
z%ModelChoiceField.get_limit_choices_tocs*tt|��|�}|jdur|j��|_|Srv)r�r�__deepcopy__rK�all)rs�memo�resultr�r@rArx�s
zModelChoiceField.__deepcopy__cCs|jSrv)r�r�r@r@rA�
_get_queryset�szModelChoiceField._get_querysetcCs$|durdn|��|_|j|j_dSrv)ryr��choicesr0)rsrKr@r@rA�
_set_queryset�szModelChoiceField._set_querysetcCst|�S)z�
        Convert objects into strings and generate the labels for the choices
        presented by this object. Subclasses can override this method to
        customize the display of the choices.
        �r�rvr@r@rAru�sz$ModelChoiceField.label_from_instancecCst|d�r|jS|�|�S)N�_choices)rPr�rmr�r@r@rA�_get_choices�s

	zModelChoiceField._get_choicescs.t|d�r|jr|�|j�S|jSt��|�S�Nr')rPrw�serializable_valuerMr�rt�rsr|r�r@rArt�s

zModelChoiceField.prepare_valuec
Cs�||jvrdSz|jpd}t||jj�rt||�}|jjdi||i��}W|Stt|jjj	fy?t
|jddd|id��w)NrMr[r|�r��paramsr@)r6rwr+rKrRrFr5r�ri�DoesNotExistrra)rsr|�keyr@r@rAr��s


���zModelChoiceField.to_pythoncCst�||�Srv)r	�validater�r@r@rAr�r�zModelChoiceField.validatecCs@|jrdS|dur|nd}|dur|nd}t|�|��t|�kS)NFrD)�disabledr�rt)rsr�r2�
initial_value�
data_valuer@r@rArs
zModelChoiceField.has_changed)rgrwrxr/rrarjrmrurLrxr|r~�propertyrKrur�r�_set_choicesr}rtr�r�rr�r@r@r�rAr�s:���$

rcsleZdZdZeZeZed�ed�ed�d�Z	�fdd�Z
dd	�Zd
d�Zdd
�Z
�fdd�Zdd�Z�ZS)rz9A MultipleChoiceField whose choices are a model QuerySet.zEnter a list of values.zESelect a valid choice. %(value)s is not one of the available choices.u"“%(pk)s” is not a valid value.)�invalid_listr[�invalid_pk_valuecst�j|fddi|��dS)Nrk)r�ru)rsrKrqr�r@rAru#sz!ModelMultipleChoiceField.__init__cCs|sgSt|�|��Srv)r��
_check_valuesr�r@r@rAr�&sz"ModelMultipleChoiceField.to_pythoncCsr|�|�}|jr|st|jddd��|js|s|j��St|ttf�s-t|jddd��|�	|�}|�
|�|S)Nr�r^r�)rtr�rrarKr=r+r�r�r��run_validators)rsr|r�r@r@rAr�+s



�

zModelMultipleChoiceField.cleanc
s�|jpd�zt|�}Wntyt|jddd��w|D]$}z
|jjdi�|i��WqttfyBt|jddd|id��w|jjdid�|i��}�fdd�|D�}|D]}t|�|vrot|jd	d	d
|id��q[|S)
z�
        Given a list of possible PK values, return a QuerySet of the
        corresponding objects. Raise a ValidationError if a given value is
        invalid (not a valid PK, not in the queryset, etc.)
        rMr�r^r�r�z%s__incsh|]	}tt|����qSr@)r�rFr��r�r@rArWrQz9ModelMultipleChoiceField._check_values.<locals>.<setcomp>r[r|Nr@)	rw�	frozensetrirrarKrQr�r�)rsr|rMr��pks�valr@r�rAr�<s<
������z&ModelMultipleChoiceField._check_valuescsDt|d�rt|t�st|d�st�j��fdd�|D�St��|�S)Nror'csg|]}�|��qSr@r@)r[r~�rtr@rAr]hr�z:ModelMultipleChoiceField.prepare_value.<locals>.<listcomp>)rPr+r�r�rtr�r�r�rArtas���z&ModelMultipleChoiceField.prepare_valuecCs`|jrdS|durg}|durg}t|�t|�krdSdd�|�|�D�}dd�|D�}||kS)NFTcS�h|]}t|��qSr@r�r[r|r@r@rArtr�z7ModelMultipleChoiceField.has_changed.<locals>.<setcomp>cSr�r@rr�r@r@rArur�)r�r�rt)rsr�r2�initial_set�data_setr@r@rArksz$ModelMultipleChoiceField.has_changed)rgrwrxr/rr0r�
hidden_widgetrrarur�r�r�rtrr�r@r@r�rArs ��%
rcCs"t|d�o|jjdup|jjduSr�)rPr'r)r<)rbr@r@rA�modelform_defines_fieldsys
�r�)NN)	NNNNNNNNNr`)7r/�	itertoolsr�django.core.exceptionsrrrr�django.db.models.utilsr�django.forms.fieldsrr	�django.forms.formsr
r�django.forms.formsetsrr
�django.forms.utilsr�django.forms.widgetsrrrr�django.utils.textrr�django.utils.translationrrrr$rrBrrWrrrryrrr#rr r!rYr"r�rbrjrrr�r@r@r@rA�<module>s�

0��nI]
�[d
�G
oR
�E,	c