
    og                         d dl Z d dl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 d	d
lmZ d Z ee      Z e       efd       ZddddedfdZd ZddZd Zd Zy)    N)	lru_cache)settings)flatatt)Contextget_template)SimpleLazyObject)
SafeString   )KeepContextc                  "    t        t        d      S )NCRISPY_TEMPLATE_PACK)getattrr        K/var/www/medrc_site/venv/lib/python3.12/site-packages/crispy_forms/utils.pyget_template_packr      s    8344r   c                     t        d| z        S )Nz%s/field.htmlr   template_packs    r   default_field_templater      s    -788r   c	                    |g n|j                         }
t        ||
      5  | t        d      cddd       S t        t        dd      }t        | d      r| j                  |||      cddd       S 	 ||    }|j                  }|)t        |j                  d|j                  g      }|}t        |t              r|gt        |      z  }t        t        ||            D ]  \  }\  }}t        |j                  d      rhd|v r1|d   d	k(  r)|j                  |      |j                  j                  |<   T|j                  j                  |   j                   j#                  |       d|v r|d   d	k(  r|j                  |      |_        |j                  j                   j#                  |        t        |d      rf| |j0                  vr|j0                  j3                  |        n<|st'        d| z        t)        j*                  d| z  t-        j.                                |t        d      }n|.|j4                  t7        |      }n!t9        |j4                        }nt9        |      }|Jt        |d      r6t        |j:                  t<              r|j:                  j?                         ng|_        |j#                  |tA        t        |t              r|ni       d       ||j#                  |       |j                  |jC                               }|cddd       S # t$        $ rB |st'        d
| z        d}t)        j*                  d
| z  t-        j.                                Y w xY w# 1 sw Y   yxY w)a  
    Renders a django-crispy-forms field

    :param field: Can be a string or a Layout object like `Row`. If it's a layout
        object, we call its render method, otherwise we instantiate a BoundField
        and render it using default template 'CRISPY_TEMPLATE_PACK/field.html'
        The field is added to a list that the form holds called `rendered_fields`
        to avoid double rendering fields.
    :param form: The form/formset to which that field belongs to.
    :template: Template used for rendering the field.
    :layout_object: If passed, it points to the Layout object that is being rendered.
        We use it to store its bound fields in a list called `layout_object.bound_fields`
    :attrs: Attributes for the field's widget
    :template_pack: Name of the template pack to be used for rendering `field`
    :extra_context: Dictionary to be added to context, added variables by the layout object
    N CRISPY_FAIL_SILENTLYTrenderr   widgetstypehiddenz"Could not resolve form field '%s'.)exc_inforendered_fieldsz(A field should only be rendered once: %sbound_fields)field
labelclass
flat_attrs)"keysr   r
   r   r   hasattrr   r"   widget
isinstancedictlen	enumerateziphidden_widgetr   attrsupdateKeyError	Exceptionloggingwarningsysr   r    addcrispy_field_templater   r   r!   listappendr   flatten)r"   formcontexttemplater#   layout_objectr.   r   extra_contextkwargs
added_keysFAIL_SILENTLYbound_fieldfield_instancer   
list_attrsindexr'   attrhtmls                       r   render_fieldrH      sS   8 %,-2D2D2FJ	Wj	) Q=b>Q Q  *@$G5(#<<g]<KQ Q	gu+K(..N !."7"7^EZEZD[\ #
eT*"'3w<!7J-6s7J7O-P E)E>FD~44i@!T>d6lh.FCQC_C_`dCeN1199%@ +1199%@FFMMdS!T>d6lh.F4B4P4PQU4VN1 +1177>>tDE* 4*+D000$$((/$#$NQV$VWWOO$NQV$Vadamamaop!b>D--55mDH+D,F,FGH'1 (=.9jIcIcei>j!..55kB2=M.NN(","):eT3J%PR"S (}-??7??#45DcQ QF  	g  Du LMM!% Du LWZWcWcWeff	gGQ Qs7   M20M23D=L$0E*M2$AM/+M2.M//M22M;c           
          t        | j                         D ci c]  \  }}|j                  dd      | c}}      S c c}}w )z
    Convert a dictionary of attributes to a single string.

    Passed attributes are redirected to `django.forms.utils.flatatt()`
    with replaced "_" (underscores) by "-" (dashes) in their names.
    _-)_flatattitemsreplace)r.   kvs      r   r   r      s7     F1QYYsC(!+FGGFs   >
c                     ddl m} |
 |dd      }n	 |dd      }t        |      }|j                  | |d       |j	                  |      S )z
    Renders a form and returns its HTML output.

    This function wraps the template logic in a function easy to use in a Django view.
    r   )CrispyFormNodeNr:   helper)r:   rS   )+crispy_forms.templatetags.crispy_forms_tagsrR   r   r/   r   )r:   rS   r;   rR   nodenode_contexts         r   render_crispy_formrW      sR     Kfh/fd+7#L89;;|$$r   c                 6    | D cg c]	  }||v s| c}S c c}w )z
    Take the not-in-place intersection of two lists, similar to sets but preserving order.
    Does not check unicity of list1.
    r   )list1list2items      r   list_intersectionr\      s    
 #4TdemD444s   	c                 |    t        |      }g }| D ])  }||vs|j                  |       |j                  |       + |S )zm
    Take the not-in-place difference of two lists (left - right), similar to sets but preserving order.
    )setr5   r8   )leftrightblocked
differencer[   s        r   list_differencerc      sK     %jGJ $wKKd#$ r   )NN)r2   r4   	functoolsr   django.confr   django.forms.utilsr   rL   django.templater   django.template.loaderr   django.utils.functionalr	   django.utils.safestringr
   baser   r   TEMPLATE_PACKr   rH   rW   r\   rc   r   r   r   <module>rm      s~     
    2 # / 4 . 5 !!23
 )6 9 9 
nbH%&5
r   