o
    e                     @   sX   d Z G dd deZG dd deZG dd deZG dd deZG d	d
 d
eZdS )z,Classes for class-based forward declaration.c                   @   s$   e Zd ZdZedd Zdd ZdS )Forwardz0Base class for autocomplete forward declaration.c                 C   s   t d)z2Forward type. Should be implemented in subclasses.zPlease use one of my subclasses)NotImplementedErrorself r   W/var/www/html/Testing_prj/Navya-Bakers/venv/lib/python3.10/site-packages/dal/forward.pytype   s   zForward.typec                 C   s
   d| j iS )5Convert to dictionary which will be rendered as JSON.r   )r   r   r   r   r   to_dict   s   zForward.to_dictN)__name__
__module____qualname____doc__propertyr   r	   r   r   r   r   r      s
    
r   c                       .   e Zd ZdZdZdddZ fddZ  ZS )	Fielda  Forward field value.

    The type of the forwarded value from the field is either string, list of
    strings or boolean.

    The following rules are used to deduce the forwarded type.

     - If there is only one field in the form or subform with name ``src``
    and this field is a checkbox without ``value`` HTML-attribute,
    then boolean value indicating if this checkbox is checked is forwarded.

     - If there is only one field in the form or subform with name ``src``
    and it has ``multiple`` HTML-attribute, then this field is forwarded as a
    list of strings, containing values from this field.

    - If there are one or more fields in the form with name ``src`` and all of
    them are checkboxes with HTML-attribute ``value`` set the list of strings
    containing checked checkboxes is forwarded.

    - Otherwise ``src`` field value forwarded as a string.

    .. py:attribute:: src

        The name of the form field whose value will be forwarded to a view.

    .. py:attribute:: dst

        The name of the key of the forwarded value from the src field in the
        forwarded dictionary. If this value is ``None``, then the key is
        ``src``.
    fieldNc                 C      || _ || _dS z$Instantiate a forwarded field value.N)srcdst)r   r   r   r   r   r   __init__6      
zField.__init__c                    s8   t t|  }|j| jd | jdur|j| jd |S )r   )r   Nr   )superr   r	   updater   r   r   d	__class__r   r   r	   ;   s
   
zField.to_dictNr
   r   r   r   r   r   r	   __classcell__r   r   r   r   r      s
     
r   c                       s,   e Zd ZdZdZdd Z fddZ  ZS )ConstzForward arbitrary constant value.

    .. py:attribute:: val

        The value to forward. Must be JSON-serializable.

    .. py:attribute:: dst

        The name of the key of the forwarded value.
    constc                 C   r   )z'Instantiate a forwarded constant value.N)valr   )r   r$   r   r   r   r   r   T   r   zConst.__init__c                    .   t t|  }|j| jd |j| jd |S )r   )r$   r   )r   r"   r	   r   r$   r   r   r   r   r   r	   Y      zConst.to_dictr    r   r   r   r   r"   F   s
    r"   c                       r   )	
JavaScriptaH  Run registered javascript handler and forward its returned value.

    You can register custom forward handler in your JS code as follows:

    .. code-block:: javascript

    yl.registerForwardHandler("your_handler", function (autocompleteElement) {
        // your code here
    });

    Then if your add ``JavaScript("your_handler", "some_value")`` to your
    forwards declaration, your function will be called, autocomplete field
    HTML element will be passed as ``autocompleteElement`` and returned value
    will be added to forward dictionary with ``some_value`` key.

    .. py:attribute:: handler

    The name of the registered handler.

    .. py:attribute:: dst

    The name of the key of the forwarded value from the src field in the
    forwarded dictionary. If this value is ``None``, then the key is
    ``handler``
    
javascriptNc                 C   r   )zInitialize Javascript class.N)handlerr   )r   r)   r   r   r   r   r      r   zJavaScript.__init__c                    r%   )r   )r)   r   )r   r'   r	   r   r)   r   r   r   r   r   r	      r&   zJavaScript.to_dictr   r    r   r   r   r   r'   c   s
    
r'   c                       r   )	Selfa#  Forward own value.

    The same as :class:`Field`, except that `src` is always this field
    itself.

    .. py:attribute:: dst

    The name of the key of the forwarded value from the src field in the
    forwarded dictionary. If this value is ``None``, then the key is
    ``self``.
    r   Nc                 C   s
   || _ dS r   r   )r   r   r   r   r   r      s   
zSelf.__init__c                    s*   t t|  }| jdur|j| jd |S )r   Nr   )r   r*   r	   r   r   r   r   r   r   r	      s   
zSelf.to_dictr   r    r   r   r   r   r*      s
    
r*   N)r   objectr   r   r"   r'   r*   r   r   r   r   <module>   s    3,