o
    šhQ  ã                   @   s<   d dl mZ ddlmZ ddlmZ dZG dd„ deƒZd	S )
é    )Úunset_valueé   )Úwidgetsé   )ÚField)Ú	FormFieldc                       s|   e Zd ZdZe ¡ Z	d‡ fdd„	Zedfdd„Z	dd	d
„Z
dd„ Zdd„ Zdd„ Zdd„ Zedd„ ƒZedd„ ƒZ‡  ZS )r   a-  
    Encapsulate a form as a field in another form.

    :param form_class:
        A subclass of Form that will be encapsulated.
    :param separator:
        A string which will be suffixed to this field's name to create the
        prefix to enclosed fields. The default is fine for most uses.
    Nú-c                    sF   t ƒ j||fi |¤Ž || _|| _d | _| jrtdƒ‚|r!tdƒ‚d S )NzGFormField cannot take filters, as the encapsulated data is not mutable.zTFormField does not accept any validators. Instead, define them on the enclosed form.)ÚsuperÚ__init__Ú
form_classÚ	separatorÚ_objÚfiltersÚ	TypeError)Úselfr   ÚlabelZ
validatorsr   Úkwargs©Ú	__class__© úF/var/www/html/venv/lib/python3.10/site-packages/wtforms/fields/form.pyr
      s   ÿÿÿzFormField.__init__c                 C   sŽ   |rt dƒ‚|tu r z|  ¡ }W n t y   | j}Y nw || _|| _| j| j }t|tƒr<| j	d||dœ|¤Ž| _
d S | j	|||d| _
d S )NzFFormField cannot take filters, as the encapsulateddata is not mutable.)ÚformdataÚprefix)r   Úobjr   r   )r   r   Údefaultr   Zobject_dataÚnamer   Ú
isinstanceÚdictr   Úform)r   r   ÚdataZextra_filtersr   r   r   r   Úprocess(   s    ÿ
ÿ
zFormField.processr   c                 C   s   |rt dƒ‚| j ¡ S )NzWFormField does not accept in-line validators, as it gets errors from the enclosed form.)r   r   Úvalidate)r   r   Zextra_validatorsr   r   r   r!   >   s
   ÿ
zFormField.validatec                 C   sH   t ||d ƒ}|d u r| jd u rtdƒ‚| j}| j |¡ t|||ƒ d S )NzZpopulate_obj: cannot find a value to populate from the provided obj or input data/defaults)Úgetattrr   r   r   Úpopulate_objÚsetattr)r   r   r   Ú	candidater   r   r   r#   F   s   
ÿzFormField.populate_objc                 C   s
   t | jƒS ©N)Úiterr   ©r   r   r   r   Ú__iter__S   ó   
zFormField.__iter__c                 C   s
   | j | S r&   )r   ©r   r   r   r   r   Ú__getitem__V   r*   zFormField.__getitem__c                 C   s   t | j|ƒS r&   )r"   r   r+   r   r   r   Ú__getattr__Y   s   zFormField.__getattr__c                 C   ó   | j jS r&   )r   r   r(   r   r   r   r   \   ó   zFormField.datac                 C   r.   r&   )r   Úerrorsr(   r   r   r   r0   `   r/   zFormField.errors)NNr   )r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ZTableWidgetZwidgetr
   r   r    r!   r#   r)   r,   r-   Úpropertyr   r0   Ú__classcell__r   r   r   r   r   	   s    
ÿ

r   N)Zwtforms.utilsr   Ú r   Úcorer   Ú__all__r   r   r   r   r   Ú<module>   s
    