
    og
                        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mZ ddlmZmZmZ  G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d d e      Z G d! d"e      Z G d# d$e      Z  G d% d&e      Z! G d' d(e      Z" G d) d*e      Z# G d+ d,e      Z$y-).    )randint)Template)render_to_string)
SafeString)slugify   )DivFieldLayoutObjectTemplateNameMixin)TEMPLATE_PACKflatattrender_fieldc                   F     e Zd ZdZdZ	 	 	 dddddd fdZedfdZ xZS )	PrependedAppendedTexta  
    Layout object for rendering a field with prepended and appended text.

    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
    ----------
    field : str
        The name of the field to be rendered.
    prepended_text : str, optional
        The prepended text, can be HTML like, by default None
    appended_text : str, optional
        The appended text, can be HTML like, by default None
    input_size : str, optional
        For Bootstrap4+ additional classes to customise the input-group size
        e.g. ``input-group-sm``. By default None
    active : bool
        For Bootstrap3, a boolean to render the text active. By default
        ``False``.
    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::

         PrependedAppendedText('amount', '$', '.00')
    z&%s/layout/prepended_appended_text.htmlNF)active	css_classwrapper_classtemplatec                    || _         || _        || _        || _        || _        |rd|v rd| _        d|v rd| _        t        
|   |f|||d|	 y )Nzinput-lgzinput-smr   r   r   )fieldappended_textprepended_textr   
input_sizesuper__init__)selfr   r   r   r   r   r   r   r   kwargs	__class__s             O/var/www/medrc_site/venv/lib/python3.12/site-packages/crispy_forms/bootstrap.pyr   zPrependedAppendedText.__init__?   sh     
*,$Y&",Y&",n)=[cngmn    c           
      .   ||j                         ni }|j                  | j                  | j                  | j                  t        | dd      | j                  d       | j                  |      }t        | j                  ||f|| j                  ||d|S )Nr   F)crispy_appended_textcrispy_prepended_textr   r   r   )r   attrstemplate_packextra_context)copyupdater   r   r   getattrr   get_template_namer   r   r&   )r   formcontextr'   r(   r   r   s          r!   renderzPrependedAppendedText.render[   s    0=0I**,r(,(:(:)-)<)<"oo!$%8!%!3!3	
 ))-8JJ	
 **''	
 	
 		
r"   NNN	__name__
__module____qualname____doc__r   r   r   r/   __classcell__r    s   @r!   r   r      sB    .` 8H
 o o8 3@t 
r"   r   c                   0     e Zd ZdZdddddd fd
Z xZS )AppendedTexta.  
    Layout object for rendering a field with appended text.

    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
    ----------
    field : str
        The name of the field to be rendered.
    text : str
        The appended text, can be HTML like.
    input_size : str, optional
        For Bootstrap4+ additional classes to customise the input-group size
        e.g. ``input-group-sm``. By default None
    active : bool
        For Bootstrap3, a boolean to render the text active. By default
        ``False``.
    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::

         AppendedText('amount', '.00')
    NFr   r   r   r   r   c          
      B    || _         t        	|   |f||||||d| y )N)r   r   r   r   r   r   textr   r   
r   r   r=   r   r   r   r   r   r   r    s
            r!   r   zAppendedText.__init__   s=     			
!'		
 		
r"   r2   r3   r4   r5   r   r6   r7   s   @r!   r9   r9   s   $    ,f 
 
r"   r9   c                   0     e Zd ZdZdddddd fd
Z xZS )PrependedTexta/  
    Layout object for rendering a field with prepended text.

    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
    ----------
    field : str
        The name of the field to be rendered.
    text : str
        The prepended text, can be HTML like.
    input_size : str, optional
        For Bootstrap4+ additional classes to customise the input-group size
        e.g. ``input-group-sm``. By default None
    active : bool
        For Bootstrap3, a boolean to render the text active. By default
        ``False``.
    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::

         PrependedText('amount', '$')
    NFr:   c          
      B    || _         t        	|   |f||||||d| y )N)r   r   r   r   r   r   r<   r>   s
            r!   r   zPrependedText.__init__   s=     			
!'		
 		
r"   r?   r7   s   @r!   rB   rB      r@   r"   rB   c                   .    e Zd ZdZdZdddddZefdZy)FormActionsa  
    Bootstrap layout object. It wraps fields in a <div class="form-actions">

    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 which will be added to the
        ``<div>`` if provided. By default None.
    css_class : str, optional
        Additional CSS classes to be applied to the ``<div>``. 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
    --------

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

        FormActions(
            HTML(<span style="display: hidden;">Information Saved</span>),
            Submit('Save', 'Save', css_class='btn-primary')
        )
    z%s/layout/formactions.htmlNcss_idr   r   c                    t        |      | _        || _        || _        |xs | j                  | _        t        |      | _        y N)listfieldsidr   r   r   
flat_attrs)r   rG   r   r   rK   r   s         r!   r   zFormActions.__init__+  s6    6l" 1DMM!&/r"   c                      | j                   |||fi |}| j                  |      }|j                  | |d       t        ||j	                               S )N)formactionsfields_output)get_rendered_fieldsr,   r*   r   flatten)r   r-   r.   r'   r   htmlr   s          r!   r/   zFormActions.render2  sR    't''g}OO))-8tdCD'//*;<<r"   r2   r3   r4   r5   r   r   r   r/    r"   r!   rE   rE     s&    #J ,H'+td * 3@ =r"   rE   c                   *     e Zd ZdZdZef fd	Z xZS )InlineCheckboxesa-  
    Layout object for rendering checkboxes inline.

    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::

        InlineCheckboxes('field_name')
    z,%s/layout/checkboxselectmultiple_inline.htmlc                 .    t         |   |||ddi      S Ninline_classinline)r'   r(   r   r/   r   r-   r.   r'   r   r    s        r!   r/   zInlineCheckboxes.renderd  !    w~dG=YgiqXr~ssr"   r2   r3   r4   r5   r   r   r/   r6   r7   s   @r!   rW   rW   :  s    %N >H2? t tr"   rW   c                   *     e Zd ZdZdZef fd	Z xZS )InlineRadiosa+  
    Layout object for rendering radiobuttons inline.

    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::

        InlineRadios('field_name')
    z!%s/layout/radioselect_inline.htmlc                 .    t         |   |||ddi      S rY   r\   r]   s        r!   r/   zInlineRadios.render  r^   r"   r_   r7   s   @r!   ra   ra   h  s    %N 3H2? t tr"   ra   c                   B     e Zd ZdZdZdZddddd fd
ZedfdZ xZ	S )FieldWithButtonsa  
    A layout object for rendering a single field with any number of buttons.

    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 wrapping ``<div>``. By default None.

    Parameters
    ----------

    *fields : str or LayoutObject
        The first positional argument is the field. This can be either the
        name of the field as a string or an instance of `Field`. Following
        arguments will be rendered as buttons.
    input_size : str
        Additional CSS class to change the size of the input. e.g.
        "input-group-sm".
    css_id : str, optional
        A DOM id for the layout object which will be added to the wrapping
        ``<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 wrapping
        ``<div>``.

    Examples
    --------

    Example::

        FieldWithButtons(
            Field("password1", css_class="span4"),
            StrictButton("Go!", css_id="go-button"),
            input_size="input-group-sm",
        )
    z!%s/layout/field_with_buttons.htmlz%s/field.htmlN)r   rG   r   r   c                :    || _         t        |   ||||d| y )NrF   )r   r   r   )r   r   rG   r   r   rK   r   r    s          r!   r   zFieldWithButtons.__init__  s#    $&9xb[abr"   c           
           j                   z  t        dj                   fd j                  dd  D                    } |d} j	                        }t         j                  d   t              r:t         j                  d   d   |f j                  d   j                  |dS t         j                  d   |fd|iS )N c              3   B   K   | ]  }t        |fd   yw))layout_objectr'   N)r   ).0r   r.   field_templater-   r   r   r'   s     r!   	<genexpr>z*FieldWithButtons.render.<locals>.<genexpr>  sC        "	
 #'"/ s   r   )divbuttonsr   )r&   r'   r(   r(   )	rk   r   joinrK   r,   
isinstancer
   r   r&   )	r   r-   r.   r'   r(   r   rn   r   rk   s	   ```` `  @r!   r/   zFieldWithButtons.render  s    ,,}<GG   "[[_ 
 !%9))-8dkk!ne,  Aq!		
 kk!n**++	 	 	  AgxoWdohnoor"   )
r2   r3   r4   r5   r   rk   r   r   r/   r6   r7   s   @r!   rd   rd     s3    ,\ 3H$N+/W[ c 3@t #pr"   rd   c                   *    e Zd ZdZdZdZddZefdZy)StrictButtona  
    Layout object for rendering an HTML button in a ``<button>`` tag.

    Attributes
    ----------
    template: str
        The default template which this Layout Object will be rendered
        with.
    field_classes : str
        The CSS classes to be applied to the button. By defult "btn".

    Parameters
    ----------
    content : str
        The content of the button. This content is context aware, to bring
        this to life see the examples section.
    css_id : str, optional
        A custom DOM id for the layout object which will be added to the
        ``<button>`` if provided. By default None.
    css_class : str, optional
        Additional CSS classes to be applied to the ``<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 ``<button>``.

    Examples
    --------

    In your ``Layout``::

        StrictButton("button content", css_class="extra")

    The content of the button is context aware, so you can do things like::

        StrictButton("Button for {{ user.username }}")
    z%s/layout/button.htmlbtnNc                     || _         |xs | j                  | _        |j                  dd       |r||d<   | j                  |d<   |r|dxx   d| z  cc<   t	        |      | _        y )NtypebuttonrL   class )contentr   
setdefaultfield_classesr   rM   )r   ry   rG   r   r   r   s         r!   r   zStrictButton.__init__  sh     1DMM&(+ !F4L,,w7O9+.O!&/r"   c                     t        t        | j                              j                  |      | _        | j	                  |      }|j                  d| i       t        ||j                               S )Nrv   )r   strry   r/   r,   r*   r   rR   r   r-   r.   r'   r   r   s         r!   r/   zStrictButton.render.  sW    DLL 1299'B))-8$'('//*;<<r"   r0   )	r2   r3   r4   r5   r   r{   r   r   r/   rU   r"   r!   rr   rr     s$    &P 'HM*  3@ =r"   rr   c                   8     e Zd ZdZdZddddd fd
Zd Z xZS )	ContaineraW  
    Base class used for `Tab` and `AccordionGroup`, represents a basic
    container concept.

    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 "".

    Parameters
    ----------
    name : str
        The name of the container.
    *fields : str, LayoutObject
        Any number of fields as positional arguments to be rendered within
        the container.
    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>``.
    rg   N)rG   r   r   r   c                    t        |   ||||d| || _        |d u| _        |xs d| _        | j
                  st        | j                  d      | _        y y )NrF   FT)allow_unicode)r   r   name_active_originally_includedr   rG   r   )	r   r   rG   r   r   r   rK   r   r    s	           r!   r   zContainer.__init__Y  sY    &9xb[ab	+1+=(o{{!$))4@DK r"   c                 4    |d | j                         D        v S )z>
        check if field_name is contained within tab.
        c              3   4   K   | ]  }|j                     y wrI   )r   )rj   pointers     r!   rl   z)Container.__contains__.<locals>.<genexpr>e  s     QwgllQs   )get_field_names)r   
field_names     r!   __contains__zContainer.__contains__a  s     Q$:N:N:PQQQr"   )r2   r3   r4   r5   r   r   r   r6   r7   s   @r!   r   r   6  s&    @ I-1TDY] ARr"   r   c                       e Zd ZdZd Zd Zy)ContainerHoldera#  
    Base class used for `TabHolder` and `Accordion`, groups containers.

    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 or layout objects 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>``.
    c                 \    | j                   D ]  t        fd|D              }|sc S  y)zR
        Returns the first container with errors, otherwise returns None.
        c              3   &   K   | ]  }|v  
 y wrI   rU   )rj   errortabs     r!   rl   z>ContainerHolder.first_container_with_errors.<locals>.<genexpr>  s     ?uesl?s   N)rK   any)r   errorserrors_herer   s      @r!   first_container_with_errorsz+ContainerHolder.first_container_with_errors  s5     ;; 	C???K
	 r"   c                     | j                  |j                  j                               }|%| j                  d   }t	        |dd      sd|_        |S d|_        |S )z
        Makes sure that the first group that should be open is open.
        This is either the first group with errors or the first group
        in the container, unless that first group was originally set to
        active=False.
        Nr   r   T)r   r   keysrK   r+   r   )r   r-   targets      r!   open_target_group_for_formz*ContainerHolder.open_target_group_for_form  sX     11$++2B2B2DE>[[^F6#@$G $Mr"   N)r2   r3   r4   r5   r   r   rU   r"   r!   r   r   h  s    :r"   r   c                   8     e Zd ZdZdZdZefdZef fd	Z xZ	S )Taba  
    Tab object. It wraps fields in a div whose default class is "tab-pane" and
    takes a name as first argument.

    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 "".

    Parameters
    ----------
    name : str
        The name of the container.
    *fields : str, LayoutObject
        Any number of fields as positional arguments to be rendered within
        the container.
    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
    --------

    Example::

        Tab('tab_name', 'form_field_1', 'form_field_2', 'form_field_3')
    ztab-panez%s/layout/tab-link.htmlc                 <    | j                   |z  }t        |d| i      S )z
        Render the link for the tab-pane. It must be called after render so css_class is updated
        with active if needed.
        link)link_templater   )r   r'   r   r   s       r!   render_linkzTab.render_link  s%    
 **]:~>>r"   c                     | j                   r$d| j                  vr7| xj                  dz  c_        n!| j                  j                  dd      | _        t        |   |||      S )Nr   z activerg   )r   r   replacer   r/   r]   s        r!   r/   z
Tab.render  sO    ;;t~~-)+!^^33HbADNw~dG];;r"   )
r2   r3   r4   r5   r   r   r   r   r/   r6   r7   s   @r!   r   r     s-    %N I-M(5 ? 3@ < <r"   r   c                       e Zd ZdZdZefdZy)	TabHoldera  
    TabHolder object. It wraps Tab objects in a container.

    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 or layout objects 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
    --------
    Example::

        TabHolder(
            Tab('form_field_1', 'form_field_2'),
            Tab('form_field_3')
        )
    z%s/layout/tab.htmlc                 V   | j                   D ]	  }d|_         | j                  |       | j                  ||      }t	        dj                  fd| j                   D                    }|j                  | ||d       | j                        }t        ||j                               S )NFrg   c              3   @   K   | ]  }|j                          y wrI   )r   )rj   r   r'   s     r!   rl   z#TabHolder.render.<locals>.<genexpr>  s     "Yc3??=#A"Ys   )tabslinksry   )
rK   r   r   rQ   r   ro   r*   r,   r   rR   )	r   r-   r.   r'   r   r   ry   r   r   s	      `     r!   r/   zTabHolder.render  s    ;; 	CCJ	 	''-**4-H277"YT[["YYZuIJ))-8'//*;<<r"   N)r2   r3   r4   r5   r   r   r/   rU   r"   r!   r   r     s    $L $H2? =r"   r   c                       e Zd ZdZdZdZy)AccordionGroupaa  
    Accordion Group (pane) object. It wraps given fields inside an accordion
    tab. It takes accordion tab name as first argument.

    Tab object. It wraps fields in a div whose default class is "tab-pane" and
    takes a name as first argument.

    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 "".

    Parameters
    ----------
    name : str
        The name of the container.
    *fields : str, LayoutObject
        Any number of fields as positional arguments to be rendered within
        the container.
    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
    --------
    Example::

        AccordionGroup("group name", "form_field_1", "form_field_2")
    z%s/accordion-group.htmlrg   N)r2   r3   r4   r5   r   data_parentrU   r"   r!   r   r     s    'R )HKr"   r   c                   :     e Zd ZdZdZdddd fd
ZefdZ xZS )	Accordiona  
    Accordion menu object. It wraps `AccordionGroup` objects in a container

    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
    ----------
    *accordion_groups : str, LayoutObject
        Any number of layout objects 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
    --------

    Example::

        Accordion(
            AccordionGroup("group name", "form_field_1", "form_field_2"),
            AccordionGroup("another group name", "form_field")
        )
    z%s/accordion.htmlNrF   c          	          t        |   ||||d| | j                  s+dj                  dt	        t        dd            g      | _        |D ]  }| j                  |_         y )NrF   -	accordioni  i'  )r   r   rG   ro   r}   r   r   )r   rG   r   r   accordion_groupsr   accordion_groupr    s          r!   r   zAccordion.__init__m  se    *6YYalekl {{((KWT45H1I#JKDK  0 	6O*.++O'	6r"   c                 "   t        d      }| j                  |       | j                  D ]&  }| j                  |_        |t        |||fd|i|z  }( | j                  |      }|j                  | |d       t        ||j                               S )Nrg   r'   )r   ry   )
r   r   rK   rG   r   r   r,   r*   r   rR   )r   r-   r.   r'   r   ry   groupr   s           r!   r/   zAccordion.renderx  s    R. 	''-[[ 	aE $E|E4``Y_``G	a ))-8Tg>?'//*;<<r"   r1   r7   s   @r!   r   r   C  s(    %N #H15PT 	6 3@ =r"   r   c                   6     e Zd ZdZdZdZd fd	ZefdZ xZ	S )Alerta.  
    Generates markup in the form of an alert dialog.

    Attributes
    ----------
    template: str
        The default template which this Layout Object will be rendered
        with.
    css_class : str
        The CSS classes to be applied to the alert. By defult "alert".

    Parameters
    ----------
    content : str
        The content of the alert.
    dismiss : bool
        If true the alert contains a button to dismiss the alert. By default
        True.
    block : str, optional
        Additional CSS classes to be applied to the ``<button>``. By default
        None.
    css_id : str, optional
        A DOM id for the layout object which will be added to the alert 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 then available in the template
        context.

    Examples
    --------

    Example::

        Alert(content='<strong>Warning!</strong> Best check yo self, you're not looking too good.')

    z%s/layout/alert.htmlalertc                 z    g }|r| xj                   dz  c_         t        	|   ||||d| || _        || _        y )Nz alert-blockrF   )r   r   r   ry   dismiss)
r   ry   r   blockrG   r   r   r   rK   r    s
            r!   r   zAlert.__init__  s@    NNn,N&9xb[abr"   c                     | j                  |      }|j                  | | j                  | j                  d       t	        ||j                               S )N)r   ry   r   )r,   r*   ry   r   r   rR   r~   s         r!   r/   zAlert.render  sA    ))-8$,,4<<XY'//*;<<r"   )TFNNN)
r2   r3   r4   r5   r   r   r   r   r/   r6   r7   s   @r!   r   r     s%    )V &HI 3@ =r"   r   c                   (     e Zd ZdZdZd fd	Z xZS )UneditableFielda  
    Layout object for rendering fields as uneditable in bootstrap.

    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
        The name of the field.
    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::

        UneditableField('field_name', css_class="input-xlarge")
    z%s/layout/uneditable_input.htmlc                 @    ddi| _         t        |   |f|||d| y )Nrw   zuneditable-inputr   )r&   r   r   )r   r   r   r   r   r   r    s         r!   r   zUneditableField.__init__  s-    12
n)=[cngmnr"   r0   )r2   r3   r4   r5   r   r   r6   r7   s   @r!   r   r     s    $L 1Ho or"   r   c                       e Zd ZdZdZy)InlineFielda4  
    Layout object for rendering fields as Inline in bootstrap.

    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::

        InlineField('field_name')
    z%s/layout/inline_field.htmlN)r2   r3   r4   r5   r   rU   r"   r!   r   r     s    %N -Hr"   r   c                   4    e Zd ZdZdZddddddddZefd	Zy)
Modala|  
    Boostrap layout object for rendering crispy forms objects inside a
    bootstrap modal.

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

    Parameters
    ----------
    *fields : str
        The fields to be rendered within the modal.
    template : str, optional
        Overrides the default template, if provided. By default ``None``.
    css_id: str, optional
        The modal's DOM id. By default ``modal_id``.
    title: str, optional
        Text to display in the modal's header which will be wrapped in an
        ``<H5>`` tag. By default ``Modal Title``.
    title_id: str, optional
        The title's DOM id. By default ``modal_title_id``.
    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.
    title_class: str, optional
        Additional CSS classes to be applied to the title. By default None.
    **kwargs : dict, optional
        Additional attributes are converted into key="value", pairs. These
        attributes are added to the ``<div>``.

    Examples
    --------

    Example::

        Modal(
            'field1',
            Div('field2'),
            css_id="modal-id-ex",
            css_class="modal-class-ex,
            title="This is my modal",
        )
    z%s/layout/modal.htmlNmodal_idzModal Titlemodal_title_id)r   rG   titletitle_idr   title_classc                    t        |      | _        |xs | j                  | _        || _        |xs d| _        || _        || _        |xs d| _        i |ddd| j                  z  d}t        |      | _	        y )Nrg   z-1dialogz%s-label)tabindexrolezaria-labelledby)
rJ   rK   r   rG   r   r   r   r   r   rM   )	r   r   rG   r   r   r   r   rK   r   s	            r!   r   zModal.__init__P  sw     6l 1DMM"b
 &,"nFnhS]`d`m`mSmn!&/r"   c                 l     | j                   |||fi |}| j                  |      }t        || |d      S )N)modalrK   )rQ   r,   r   )r   r-   r.   r'   r   rK   r   s          r!   r/   zModal.renderg  s?    )))$Q&Q))-8DF*KLLr"   rT   rU   r"   r!   r   r     s4    ,\ &H
 !*. 3@ Mr"   r   N)%randomr   django.templater   django.template.loaderr   django.utils.safestringr   django.utils.textr   layoutr	   r
   r   r   utilsr   r   r   r   r9   rB   rE   rW   ra   rd   rr   r   r   r   r   r   r   r   r   r   r   rU   r"   r!   <module>r      s&    $ 3 . % ? ? 7 7d
E d
NE
( E
PE
) E
P4=, 4=n+tu +t\+t5 +t\Yps YpxA=$ A=H/R /Rd7c 7t9<) 9<x4= 4=n+Y +\B= B=J;=C ;=|+oe +o\(-% (-VLML LMr"   