B
    CVvgWƒ  ã               @   sŠ  d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZmZmZ eG d	d
„ d
ƒƒZG dd„ 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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G d!d"„ d"eƒZG d#d$„ d$eƒZG d%d&„ d&eƒZ G d'd(„ d(ƒZ!G d)d*„ d*eƒZ"G d+d,„ d,e"ƒZ#d-S ).é    )Ú	dataclass)ÚList)ÚTemplate)Úrender_to_string)Úconditional_escape)Ú
SafeString)Úslugify)ÚTEMPLATE_PACKÚflatattÚrender_fieldc               @   s"   e Zd ZU ee ed< eed< dS )ÚPointerZ	positionsÚnameN)Ú__name__Ú
__module__Ú__qualname__r   ÚintÚ__annotations__Ústr© r   r   úD/tmp/pip-install-o3oxmrkh/django-crispy-forms/crispy_forms/layout.pyr      s   
r   c               @   s   e Zd Zdd„ ZdS )ÚTemplateNameMixinc             C   s    d| j kr| j | }n| j }|S )Nz%s)Útemplate)ÚselfÚtemplate_packr   r   r   r   Úget_template_name   s    
z#TemplateNameMixin.get_template_nameN)r   r   r   r   r   r   r   r   r      s   r   c               @   s\   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zddd„Zddddœdd„Z	e
fdd„ZdS )ÚLayoutObjectc             C   s
   | j | S )N)Úfields)r   Úslicer   r   r   Ú__getitem__   s    zLayoutObject.__getitem__c             C   s   || j |< d S )N)r   )r   r   Úvaluer   r   r   Ú__setitem__!   s    zLayoutObject.__setitem__c             C   s   | j |= d S )N)r   )r   r   r   r   r   Ú__delitem__$   s    zLayoutObject.__delitem__c             C   s
   t | jƒS )N)Úlenr   )r   r   r   r   Ú__len__'   s    zLayoutObject.__len__c             C   s2   d| j kr"t| j|ƒr"t| j|ƒS t | |¡S dS )zŒ
        This allows us to access self.fields list methods like append or insert, without
        having to declare them one by one
        r   N)Ú__dict__Úhasattrr   ÚgetattrÚobjectÚ__getattribute__)r   r   r   r   r   Ú__getattr__*   s    zLayoutObject.__getattr__Nc             C   s   | j tddd�S )a  
        Returns a list of Pointers. First parameter is the location of the
        field, second one the name of the field. Example::

            [
                Pointer([0,1,2], 'field_name1'),
                Pointer([0,3], 'field_name2'),
            ]
        NT)ÚindexÚgreedy)Úget_layout_objectsr   )r   r*   r   r   r   Úget_field_names5   s    
zLayoutObject.get_field_namesr   F)r*   Ú	max_levelr+   c      
      G   sÞ   g }|dk	rt |tƒs|g}n|dkr*g }t|ƒdko@|d tk}x–t| jƒD ]ˆ\}}t ||ƒrš|r|| t||g |ƒ¡ n| t||g |jj	 
¡ ƒ¡ t|dƒrNt|ƒ|k s´|rN||g ||dœ}	||j||	Ž }qNW |S )aÅ  
        Returns a list of Pointers pointing to layout objects of any type matching
        `LayoutClasses`::

            [
                Pointer([0,1,2], 'div']),
                Pointer([0,3], 'field_name'),
            ]

        :param max_level: An integer that indicates max level depth to reach when
        traversing a layout.
        :param greedy: Boolean that indicates whether to be greedy. If set, max_level
        is skipped.
        Né   r   r-   )r*   r.   r+   )Ú
isinstanceÚlistr"   r   Ú	enumerater   Úappendr   Ú	__class__r   Úlowerr%   r,   )
r   r*   r.   r+   ZLayoutClassesZpointersZ	str_classÚiÚlayout_objectZ
new_kwargsr   r   r   r,   A   s    
zLayoutObject.get_layout_objectsc                s$   t d ‡ ‡‡‡fdd„| jD ƒ¡ƒS )NÚ c             3   s&   | ]}t |ˆˆ fd ˆiˆ—ŽV  qdS )r   N)r   )Ú.0Úfield)ÚcontextÚformÚkwargsr   r   r   ú	<genexpr>i   s    z3LayoutObject.get_rendered_fields.<locals>.<genexpr>)r   Újoinr   )r   r<   r;   r   r=   r   )r;   r<   r=   r   r   Úget_rendered_fieldsg   s    z LayoutObject.get_rendered_fields)N)r   r   r   r   r    r!   r#   r)   r-   r,   r	   r@   r   r   r   r   r      s   
&r   c               @   s$   e Zd ZdZdd„ Zefdd„ZdS )ÚLayouta×  
    Form Layout. It is conformed by Layout objects: `Fieldset`, `Row`, `Column`, `MultiField`,
    `HTML`, `ButtonHolder`, `Button`, `Hidden`, `Reset`, `Submit` and fields. Form fields
    have to be strings.
    Layout objects `Fieldset`, `Row`, `Column`, `MultiField` and `ButtonHolder` can hold other
    Layout objects within. Though `ButtonHolder` should only hold `HTML` and BaseInput
    inherited classes: `Button`, `Hidden`, `Reset` and `Submit`.

    Example::

        helper.layout = Layout(
            Fieldset('Company data',
                'is_company'
            ),
            Fieldset(_('Contact details'),
                'email',
                Row('password1', 'password2'),
                'first_name',
                'last_name',
                HTML('<img src="/media/somepicture.jpg"/>'),
                'company'
            ),
            ButtonHolder(
                Submit('Save', 'Save', css_class='button white'),
            ),
        )
    c             G   s   t |ƒ| _d S )N)r1   r   )r   r   r   r   r   Ú__init__Š   s    zLayout.__init__c             K   s   | j |||f|ŽS )N)r@   )r   r<   r;   r   r=   r   r   r   Úrender�   s    zLayout.renderN)r   r   r   Ú__doc__rB   r	   rC   r   r   r   r   rA   m   s   rA   c               @   s2   e Zd ZdZdZddddœdd„Zefdd„ZdS )	ÚButtonHolderag  
    Layout object. It wraps fields in a <div class="buttonHolder">

    This is where you should put Layout objects that render to form buttons

    Attributes
    ----------
    template: str
        The default template which this Layout Object will be rendered
        with.

    Parameters
    ----------
    *fields : HTML or BaseInput
        The layout objects to render within the ``ButtonHolder``. It should
        only hold `HTML` and `BaseInput` inherited objects.
    css_id : str, optional
        A custom DOM id for the layout object. If not provided the name
        argument is slugified and turned into the id for the submit button.
        By default None.
    css_class : str, optional
        Additional CSS classes to be applied to the ``<input>``. By default
        None.
    template : str, optional
        Overrides the default template, if provided. By default None.

    Examples
    --------

    An example using ``ButtonHolder`` in your layout::

        ButtonHolder(
            HTML(<span style="display: hidden;">Information Saved</span>),
            Submit('Save', 'Save')
        )
    z%s/layout/buttonholder.htmlN)Úcss_idÚ	css_classr   c            G   s&   t |ƒ| _|| _|| _|p| j| _d S )N)r1   r   rF   rG   r   )r   rF   rG   r   r   r   r   r   rB   ¹   s    
zButtonHolder.__init__c             K   s:   | j |||f|Ž}|  |¡}| | |dœ¡ t|| ¡ ƒS )N)ZbuttonholderÚfields_output)r@   r   Úupdater   Úflatten)r   r<   r;   r   r=   Úhtmlr   r   r   r   rC   ¿   s    
zButtonHolder.render)r   r   r   rD   r   rB   r	   rC   r   r   r   r   rE   ‘   s   $rE   c               @   s6   e Zd ZdZdZdZddddœdd„Zefdd	„ZdS )
Ú	BaseInputa  
    A base class to reduce the amount of code in the Input classes.

    Attributes
    ----------
    template: str
        The default template which this Layout Object will be rendered
        with.
    field_classes: str
        CSS classes to be applied to the ``<input>``.

    Parameters
    ----------
    name : str
        The name attribute of the button.
    value : str
        The value attribute of the button.
    css_id : str, optional
        A custom DOM id for the layout object. If not provided the name
        argument is slugified and turned into the id for the submit button.
        By default None.
    css_class : str, optional
        Additional CSS classes to be applied to the ``<input>``. By default
        None.
    template : str, optional
        Overrides the default template, if provided. By default None.
    **kwargs : dict, optional
        Additional attributes are passed to `flatatt` and converted into
        key="value", pairs. These attributes are added to the ``<input>``.
    z%s/layout/baseinput.htmlr8   N)rF   rG   r   c            K   sl   || _ || _|r|| _nt| j ƒ}| j› d|› �| _i | _|rR|  jd|› �7  _|pZ| j| _t|ƒ| _	d S )Nz-id-ú )
r   r   Úidr   Ú
input_typeÚattrsÚfield_classesr   r
   Ú
flat_attrs)r   r   r   rF   rG   r   r=   Zslugr   r   r   rB   ë   s    
zBaseInput.__init__c             K   s<   t t| jƒƒ |¡| _|  |¡}| d| i¡ t|| ¡ ƒS )zŠ
        Renders an `<input />` if container is used as a Layout object.
        Input button value can be a variable in context.
        Úinput)r   r   r   rC   r   rI   r   rJ   )r   r<   r;   r   r=   r   r   r   r   rC   û   s    
zBaseInput.render)	r   r   r   rD   r   rQ   rB   r	   rC   r   r   r   r   rL   È   s
   rL   c               @   s   e Zd ZdZdZdZdS )ÚSubmitaÂ  
    Used to create a Submit button descriptor for the {% crispy %} template tag.

    Attributes
    ----------
    template: str
        The default template which this Layout Object will be rendered
        with.
    field_classes: str
        CSS classes to be applied to the ``<input>``.
    input_type: str
        The ``type`` attribute of the ``<input>``.

    Parameters
    ----------
    name : str
        The name attribute of the button.
    value : str
        The value attribute of the button.
    css_id : str, optional
        A custom DOM id for the layout object. If not provided the name
        argument is slugified and turned into the id for the submit button.
        By default None.
    css_class : str, optional
        Additional CSS classes to be applied to the ``<input>``. By default
        None.
    template : str, optional
        Overrides the default template, if provided. By default None.
    **kwargs : dict, optional
        Additional attributes are passed to `flatatt` and converted into
        key="value", pairs. These attributes are added to the ``<input>``.

    Examples
    --------
    Note: ``form`` arg to ``render()`` is not required for ``BaseInput``
    inherited objects.

    >>> submit = Submit('Search the Site', 'search this site')
    >>> submit.render("", "", Context())
    '<input type="submit" name="search-the-site" value="search this site" '
    'class="btn btn-primary" id="submit-id-search-the-site"/>'

    >>> submit = Submit('Search the Site', 'search this site', css_id="custom-id",
                         css_class="custom class", my_attr=True, data="my-data")
    >>> submit.render("", "", Context())
    '<input type="submit" name="search-the-site" value="search this site" '
    'class="btn btn-primary custom class" id="custom-id" data="my-data" my-attr/>'

    Usually you will not call the render method on the object directly. Instead
    add it to your ``Layout`` manually or use the `add_input` method::

        class ExampleForm(forms.Form):
        [...]
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.helper = FormHelper()
            self.helper.add_input(Submit('submit', 'Submit'))
    Zsubmitzbtn btn-primaryN)r   r   r   rD   rO   rQ   r   r   r   r   rT     s   :rT   c               @   s   e Zd ZdZdZdZdS )ÚButtonai  
    Used to create a button descriptor for the {% crispy %} template tag.

    Attributes
    ----------
    template: str
        The default template which this Layout Object will be rendered
        with.
    field_classes: str
        CSS classes to be applied to the ``<input>``.
    input_type: str
        The ``type`` attribute of the ``<input>``.

    Parameters
    ----------
    name : str
        The name attribute of the button.
    value : str
        The value attribute of the button.
    css_id : str, optional
        A custom DOM id for the layout object. If not provided the name
        argument is slugified and turned into the id for the submit button.
        By default None.
    css_class : str, optional
        Additional CSS classes to be applied to the ``<input>``. By default
        None.
    template : str, optional
        Overrides the default template, if provided. By default None.
    **kwargs : dict, optional
        Additional attributes are passed to `flatatt` and converted into
        key="value", pairs. These attributes are added to the ``<input>``.

    Examples
    --------
    Note: ``form`` arg to ``render()`` is not required for ``BaseInput``
    inherited objects.

    >>> button = Button('Button 1', 'Press Me!')
    >>> button.render("", "", Context())
    '<input type="button" name="button-1" value="Press Me!" '
    'class="btn" id="button-id-button-1"/>'

    >>> button = Button('Button 1', 'Press Me!', css_id="custom-id",
                         css_class="custom class", my_attr=True, data="my-data")
    >>> button.render("", "", Context())
    '<input type="button" name="button-1" value="Press Me!" '
    'class="btn custom class" id="custom-id" data="my-data" my-attr/>'

    Usually you will not call the render method on the object directly. Instead
    add it to your ``Layout`` manually or use the `add_input` method::

        class ExampleForm(forms.Form):
        [...]
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.helper = FormHelper()
            self.helper.add_input(Button('Button 1', 'Press Me!'))
    ÚbuttonZbtnN)r   r   r   rD   rO   rQ   r   r   r   r   rU   G  s   :rU   c               @   s   e Zd ZdZdZdZdS )ÚHiddenaó  
    Used to create a Hidden input descriptor for the {% crispy %} template tag.

    Attributes
    ----------
    template: str
        The default template which this Layout Object will be rendered
        with.
    field_classes: str
        CSS classes to be applied to the ``<input>``.
    input_type: str
        The ``type`` attribute of the ``<input>``.

    Parameters
    ----------
    name : str
        The name attribute of the button.
    value : str
        The value attribute of the button.
    css_id : str, optional
        A custom DOM id for the layout object. If not provided the name
        argument is slugified and turned into the id for the submit button.
        By default None.
    css_class : str, optional
        Additional CSS classes to be applied to the ``<input>``. By default
        None.
    template : str, optional
        Overrides the default template, if provided. By default None.
    **kwargs : dict, optional
        Additional attributes are passed to `flatatt` and converted into
        key="value", pairs. These attributes are added to the ``<input>``.

    Examples
    --------
    Note: ``form`` arg to ``render()`` is not required for ``BaseInput``
    inherited objects.

    >>> hidden = Hidden("hidden", "hide-me")
    >>> hidden.render("", "", Context())
    '<input type="hidden" name="hidden" value="hide-me"/>'

    Usually you will not call the render method on the object directly. Instead
    add it to your ``Layout`` manually or use the `add_input` method::

        class ExampleForm(forms.Form):
        [...]
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.helper = FormHelper()
            self.helper.add_input(Hidden("hidden", "hide-me"))
    ÚhiddenN)r   r   r   rD   rO   rQ   r   r   r   r   rW   ‡  s   3rW   c               @   s   e Zd ZdZdZdZdS )ÚResetaµ  
    Used to create a reset button descriptor for the {% crispy %} template tag.

    Attributes
    ----------
    template: str
        The default template which this Layout Object will be rendered
        with.
    field_classes: str
        CSS classes to be applied to the ``<input>``.
    input_type: str
        The ``type`` attribute of the ``<input>``.

    Parameters
    ----------
    name : str
        The name attribute of the button.
    value : str
        The value attribute of the button.
    css_id : str, optional
        A custom DOM id for the layout object. If not provided the name
        argument is slugified and turned into the id for the submit button.
        By default None.
    css_class : str, optional
        Additional CSS classes to be applied to the ``<input>``. By default
        None.
    template : str, optional
        Overrides the default template, if provided. By default None.
    **kwargs : dict, optional
        Additional attributes are passed to `flatatt` and converted into
        key="value", pairs. These attributes are added to the ``<input>``.

    Examples
    --------
    Note: ``form`` arg to ``render()`` is not required for ``BaseInput``
    inherited objects.

    >>> reset = Reset('Reset This Form', 'Revert Me!')
    >>> reset.render("", "", Context())
    '<input type="reset" name="reset-this-form" value="Revert Me!" '
    'class="btn btn-inverse" id="reset-id-reset-this-form"/>'

    >>> reset = Reset('Reset This Form', 'Revert Me!', css_id="custom-id",
                         css_class="custom class", my_attr=True, data="my-data")
    >>> reset.render("", "", Context())
    '<input type="reset" name="reset-this-form" value="Revert Me!" '
    'class="btn btn-inverse custom class" id="custom-id" data="my-data" my-attr/>'

    Usually you will not call the render method on the object directly. Instead
    add it to your ``Layout`` manually manually or use the `add_input` method::

        class ExampleForm(forms.Form):
        [...]
        def __init__(self, *args, **kwargs):
            super().__init__(*args, **kwargs)
            self.helper = FormHelper()
            self.helper.add_input(Reset('Reset This Form', 'Revert Me!'))
    Úresetzbtn btn-inverseN)r   r   r   rD   rO   rQ   r   r   r   r   rY   À  s   :rY   c               @   s2   e Zd ZdZdZddddœdd„Zefdd„ZdS )	ÚFieldsetaí  
    A layout object which wraps fields in a ``<fieldset>``

    Parameters
    ----------
    legend : str
        The content of the fieldset's ``<legend>``. This text is context
        aware, to bring this to life see the examples section.
    *fields : str
        Any number of fields as positional arguments to be rendered within
        the ``<fieldset>``
    css_class : str, optional
        Additional CSS classes to be applied to the ``<input>``. By default
        None.
    css_id : str, optional
        A custom DOM id for the layout object. If not provided the name
        argument is slugified and turned into the id for the submit button.
        By default None.
    template : str, optional
        Overrides the default template, if provided. By default None.
    **kwargs : dict, optional
        Additional attributes are passed to ``flatatt`` and converted into
        key="value", pairs. These attributes are added to the ``<fieldset>``.

    Examples
    --------

    The Fieldset Layout object is added to your ``Layout`` for example::

        Fieldset("Text for the legend",
            "form_field_1",
            "form_field_2",
            css_id="my-fieldset-id",
            css_class="my-fieldset-class",
            data="my-data"
        )

    The above layout will be rendered as::

        '''
        <fieldset id="fieldset-id" class="my-fieldset-class" data="my-data">
           <legend>Text for the legend</legend>
           # form fields render here
        </fieldset>
        '''

    The first parameter is the text for the fieldset legend. This text is context aware,
    so you can do things like::

        Fieldset("Data for {{ user.username }}",
            'form_field_1',
            'form_field_2'
        )
    z%s/layout/fieldset.htmlN)rG   rF   r   c            O   s6   t |ƒ| _|| _|| _|| _|p$| j| _t|ƒ| _d S )N)r1   r   ÚlegendrG   rF   r   r
   rR   )r   r\   rG   rF   r   r   r=   r   r   r   rB   :  s    
zFieldset.__init__c             K   sR   | j |||f|Ž}| jr.tt| jƒƒ |¡}ntdƒ}|  |¡}t|| ||dœƒS )Nr8   )Úfieldsetr\   r   )r@   r\   r   r   rC   r   r   r   )r   r<   r;   r   r=   r   r\   r   r   r   r   rC   B  s    
zFieldset.render)r   r   r   rD   r   rB   r	   rC   r   r   r   r   r[      s   6r[   c               @   s<   e Zd ZdZdZdZdddddddœdd„Zefdd	„ZdS )
Ú
MultiFielda‚  
    MultiField container for Bootstrap3. Renders to a MultiField <div>.

    Attributes
    ----------
    template: str
        The default template which this Layout Object will be rendered
        with.
    field_template: str
        The template which fields will be rendered with.

    Parameters
    ----------
    label: str
        The label for the multifield.
    *fields: str
        The fields to be rendered within the multifield.
    label_class: str, optional
        CSS classes to be added to the multifield label. By default None.
    help_text: str, optional
        Help text will be available in the context of the multifield template.
        This is unused in the bootstrap3 template provided. By default None.
    css_class : str, optional
        Additional CSS classes to be applied to the ``<input>``. By default
        None.
    css_id : str, optional
        A DOM id for the layout object which will be added to the wrapping
        ``<div>`` if provided. By default None.
    template : str, optional
        Overrides the default template, if provided. By default None.
    field_template : str, optional
        Overrides the default template, if provided. By default None.
    **kwargs : dict, optional
        Additional attributes are passed to ``flatatt`` and converted into
        key="value", pairs. These attributes are added to the wrapping
        ``<div>``.

    z%s/layout/multifield.htmlz%s/multifield.htmlN)Úlabel_classÚ	help_textrG   rF   r   Úfield_templatec      
      O   sV   t |ƒ| _|| _|pd| _|p d| _|| _|| _|p8| j| _|pD| j| _t	|	ƒ| _
d S )NZ
blockLabelZ
ctrlHolder)r1   r   Z
label_htmlr_   rG   rF   r`   r   ra   r
   rR   )
r   Úlabelr_   r`   rG   rF   r   ra   r   r=   r   r   r   rB   y  s    


zMultiField.__init__c       	      K   sŽ   |d r<x2dd„ |   ¡ D ƒD ]}||jkr|  jd7  _qW | j| }| j|||f|| j| dœ|—Ž}|  |¡}| | |dœ¡ t|| 	¡ ƒS )NZform_show_errorsc             s   s   | ]}|j V  qd S )N)r   )r9   Úpointerr   r   r   r>   ’  s    z$MultiField.render.<locals>.<genexpr>z error)r   Z
labelclassr7   )Z
multifieldrH   )
r-   ÚerrorsrG   ra   r@   r_   r   rI   r   rJ   )	r   r<   r;   r   r=   r:   ra   rH   r   r   r   r   rC   �  s     


zMultiField.render)	r   r   r   rD   r   ra   rB   r	   rC   r   r   r   r   r^   N  s   &r^   c               @   s6   e Zd ZdZdZdZddddœdd„Zefdd„ZdS )	ÚDivaÝ  
    Layout object. It wraps fields in a ``<div>``.

    Attributes
    ----------
    template : str
        The default template which this Layout Object will be rendered
        with.
    css_class : str, optional
        CSS classes to be applied to the ``<div>``. By default None.

    Parameters
    ----------
    *fields : str, LayoutObject
        Any number of fields as positional arguments to be rendered within
        the ``<div>``.
    css_id : str, optional
        A DOM id for the layout object which will be added to the ``<div>`` if
        provided. By default None.
    css_class : str, optional
        Additional CSS classes to be applied in addition to those declared by
        the class itself. By default None.
    template : str, optional
        Overrides the default template, if provided. By default None.
    **kwargs : dict, optional
        Additional attributes are passed to ``flatatt`` and converted into
        key="value", pairs. These attributes are added to the ``<div>``.

    Examples
    --------

    In your ``Layout`` you can::

        Div(
            'form_field_1',
            'form_field_2',
            css_id='div-example',
            css_class='divs',
        )

    It is also possible to nest Layout Objects within a Div::

        Div(
            Div(
                Field('form_field', css_class='field-class'),
                css_class='div-class',
            ),
            Div('form_field_2', css_class='div-class'),
        )
    z%s/layout/div.htmlN)rF   rG   r   c            O   sT   t |ƒ| _| jr*|r*|  jd|› �7  _n
|r4|| _|| _|pB| j| _t|ƒ| _d S )NrM   )r1   r   rG   rF   r   r
   rR   )r   rF   rG   r   r   r=   r   r   r   rB   Þ  s    

zDiv.__init__c             K   s,   | j |||f|Ž}|  |¡}t|| |dœƒS )N)Údivr   )r@   r   r   )r   r<   r;   r   r=   r   r   r   r   r   rC   ê  s    
z
Div.render)	r   r   r   rD   r   rG   rB   r	   rC   r   r   r   r   re   §  s
   2re   c               @   s   e Zd ZdZdZdS )ÚRowa  
    Layout object. It wraps fields in a ``<div>`` and the template adds the
    appropriate class to render the contents in a row. e.g. ``form-row`` when
    using the Bootstrap4 template pack.

    Attributes
    ----------
    template : str
        The default template which this Layout Object will be rendered
        with.
    css_class : str, optional
        CSS classes to be applied to the ``<div>``. By default None.

    Parameters
    ----------
    *fields : str, LayoutObject
        Any number of fields as positional arguments to be rendered within
        the ``<div>``.
    css_id : str, optional
        A DOM id for the layout object which will be added to the ``<div>`` if
        provided. By default None.
    css_class : str, optional
        Additional CSS classes to be applied in addition to those declared by
        the class itself. By default None.
    template : str, optional
        Overrides the default template, if provided. By default None.
    **kwargs : dict, optional
        Additional attributes are passed to ``flatatt`` and converted into
        key="value", pairs. These attributes are added to the ``<div>``.

    Examples
    --------

    In your ``Layout`` you can::

        Row('form_field_1', 'form_field_2', css_id='row-example')

    It is also possible to nest Layout Objects within a Row::

        Row(
            Div(
                Field('form_field', css_class='field-class'),
                css_class='div-class',
            ),
            Div('form_field_2', css_class='div-class'),
        )
    z%s/layout/row.htmlN)r   r   r   rD   r   r   r   r   r   rg   ñ  s   /rg   c               @   s   e Zd ZdZdZdS )ÚColumna©  
    Layout object. It wraps fields in a ``<div>`` and the template adds the
    appropriate class to render the contents in a column. e.g. ``col-md`` when
    using the Bootstrap4 template pack.

    Attributes
    ----------
    template : str
        The default template which this Layout Object will be rendered
        with.
    css_class : str, optional
        CSS classes to be applied to the ``<div>``. By default None.

    Parameters
    ----------
    *fields : str, LayoutObject
        Any number of fields as positional arguments to be rendered within
        the ``<div>``.
    css_id : str, optional
        A DOM id for the layout object which will be added to the ``<div>`` if
        provided. By default None.
    css_class : str, optional
        Additional CSS classes to be applied in addition to those declared by
        the class itself. If using the Bootstrap4 template pack the default
        ``col-md`` is removed if this string contins another ``col-`` class.
        By default None.
    template : str, optional
        Overrides the default template, if provided. By default None.
    **kwargs : dict, optional
        Additional attributes are passed to ``flatatt`` and converted into
        key="value", pairs. These attributes are added to the ``<div>``.

    Examples
    --------

    In your ``Layout`` you can::

        Column('form_field_1', 'form_field_2', css_id='col-example')

    It is also possible to nest Layout Objects within a Row::

        Div(
            Column(
                Field('form_field', css_class='field-class'),
                css_class='col-sm,
            ),
            Column('form_field_2', css_class='col-sm'),
        )
    z%s/layout/column.htmlN)r   r   r   rD   r   r   r   r   r   rh   %  s   1rh   c               @   s$   e Zd ZdZdd„ Zefdd„ZdS )ÚHTMLa#  
    Layout object. It can contain pure HTML and it has access to the whole
    context of the page where the form is being rendered.

    Examples::

        HTML("{% if saved %}Data saved{% endif %}")
        HTML('<input type="hidden" name="{{ step_field }}" value="{{ step0 }}" />')
    c             C   s
   || _ d S )N)rK   )r   rK   r   r   r   rB   f  s    zHTML.__init__c             K   s   t t| jƒƒ |¡S )N)r   r   rK   rC   )r   r<   r;   r   r=   r   r   r   rC   i  s    zHTML.renderN)r   r   r   rD   rB   r	   rC   r   r   r   r   ri   [  s   	ri   c               @   s8   e Zd ZdZdZi Zddddœdd„Zedfdd„ZdS )	ÚFielda“  
    A Layout object, usually containing one field name, where you can add
    attributes to it easily.

    Attributes
    ----------
    template : str
        The default template which this Layout Object will be rendered
        with.
    attrs : dict
        Attributes to be applied to the field. These are converted into html
        attributes. e.g. ``data_id: 'test'`` in the attrs dict will become
        ``data-id='test'`` on the field's ``<input>``.

    Parameters
    ----------
    *fields : str
        Usually a single field, but can be any number of fields, to be rendered
        with the same attributes applied.
    css_class : str, optional
        CSS classes to be applied to the field. These are added to any classes
        included in the ``attrs`` dict. By default ``None``.
    wrapper_class: str, optional
        CSS classes to be used when rendering the Field. This class is usually
        applied to the ``<div>`` which wraps the Field's ``<label>`` and
        ``<input>`` tags. By default ``None``.
    template : str, optional
        Overrides the default template, if provided. By default ``None``.
    **kwargs : dict, optional
        Additional attributes are converted into key="value", pairs. These
        attributes are added to the ``<div>``.

    Examples
    --------

    Example::

        Field('field_name', style="color: #333;", css_class="whatever", id="field_name")
    z%s/field.htmlN)rG   Úwrapper_classr   c            O   sx   t |ƒ| _| j ¡ | _|rHd| jkr>| jd  d|› �7  < n
|| jd< || _|pV| j| _| j dd„ | ¡ D ƒ¡ d S )NÚclassrM   c             S   s"   i | ]\}}t |ƒ| d d¡“qS )Ú_ú-)r   Úreplace)r9   ÚkÚvr   r   r   ú
<dictcomp>¨  s    z"Field.__init__.<locals>.<dictcomp>)r1   r   rP   Úcopyrk   r   rI   Úitems)r   rG   rk   r   r   r=   r   r   r   rB   ™  s    


zField.__init__c             K   sF   |d kri }| j r| j |d< |  |¡}| j|||f|| j|dœ|—ŽS )Nrk   )r   rP   Úextra_context)rk   r   r@   rP   )r   r<   r;   r   ru   r=   r   r   r   r   rC   ª  s    

zField.render)	r   r   r   rD   r   rP   rB   r	   rC   r   r   r   r   rj   m  s
   'rj   c               @   s"   e Zd ZdZddddœdd„ZdS )ÚMultiWidgetFielda±  
    Layout object. For fields with :class:`~django.forms.MultiWidget` as
    ``widget``, you can pass additional attributes to each widget.

    Attributes
    ----------
    template : str
        The default template which this Layout Object will be rendered
        with.

    Parameters
    ----------
    *fields : str
        Usually a single field, but can be any number of fields, to be rendered
        with the same attributes applied.
    attrs : str, optional
        Additional attrs to be added to each widget. These are added to any
        classes included in the ``attrs`` dict. By default ``None``.
    wrapper_class: str, optional
        CSS classes to be used when rendering the Field. This class is usually
        applied to the ``<div>`` which wraps the Field's ``<label>`` and
        ``<input>`` tags. By default ``None``.
    template : str, optional
        Overrides the default template, if provided. By default ``None``.

    Examples
    --------

    Example::

        MultiWidgetField(
            'multiwidget_field_name',
            attrs=(
                {'style': 'width: 30px;'},
                {'class': 'second_widget_class'}
            ),
        )
    N)rP   r   rk   c            G   s*   t |ƒ| _|pi | _|p| j| _|| _d S )N)r1   r   rP   r   rk   )r   rP   r   rk   r   r   r   r   rB   å  s    

zMultiWidgetField.__init__)r   r   r   rD   rB   r   r   r   r   rv   ½  s   &rv   N)$Zdataclassesr   Útypingr   Zdjango.templater   Zdjango.template.loaderr   Zdjango.utils.htmlr   Zdjango.utils.safestringr   Zdjango.utils.textr   Zcrispy_forms.utilsr	   r
   r   r   r   r   rA   rE   rL   rT   rU   rW   rY   r[   r^   re   rg   rh   ri   rj   rv   r   r   r   r   Ú<module>   s2   
P$7?@@9@NYJ46P