o
    »ïØe  ã                   @   sB   d Z ddlmZ G dd„ dƒZG dd„ deƒZG dd„ deƒZd	S )
z$Select2 field implementation module.é    )ÚChoiceFieldc                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚChoiceCallablez/Choices wrapper that supports callable choices.c                 C   s
   || _ dS )z0Instanciate with a callable or iterable choices.N)Úchoices)Úselfr   © r   ú^/var/www/html/Testing_prj/Navya-Bakers/venv/lib/python3.10/site-packages/dal_select2/fields.pyÚ__init__	   s   
zChoiceCallable.__init__c                 C   sV   g }t | jƒr|  ¡ n| j}|pg D ]}t|ttfƒr!| |¡ q| ||f¡ q|S )z2Call the callable if necessary and return choices.)Úcallabler   Ú
isinstanceÚlistÚtupleÚappend)r   Úresultr   Úchoicer   r   r   Ú__call__   s   zChoiceCallable.__call__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s    r   c                       s&   e Zd ZdZ		d‡ fdd„	Z‡  ZS )ÚSelect2ListChoiceFieldzÇAllows a list of values to be used with a ChoiceField.

    Avoids unusual things that can happen if Select2ListView is used for
    a form where the text and value for choices are not the same.
    NTÚ c           
   	      s0   t |ƒ}	tt| ƒj||	|||||dœ|¤Ž dS )zªUse a list to generate choices in a ChoiceField.

        .. py:param choice_list: The list to use to generate choices or a
        function that returns a list.
        )r   ÚrequiredÚwidgetÚlabelÚinitialÚ	help_textN)r   Úsuperr   r   )
r   Úchoice_listr   r   r   r   r   ÚargsÚkwargsr   ©Ú	__class__r   r   r       s   
ÿþ
þzSelect2ListChoiceField.__init__)NTNNNr   )r   r   r   r   r   Ú__classcell__r   r   r    r   r      s
    ÿr   c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚSelect2ListCreateChoiceFieldz5Skips validation of choices so any value can be used.c                    s   t t| ƒ |¡ dS )z,Do not validate choices but check for empty.N)r   r   Úvalidate)r   Úvaluer    r   r   r$   2   s   z%Select2ListCreateChoiceField.validate)r   r   r   r   r$   r"   r   r   r    r   r#   /   s    r#   N)r   Údjango.formsr   r   r   r#   r   r   r   r   Ú<module>   s
    