
    h                         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 Zdded	ed
ee   fdZ G d d      Z G d d      Z G d dej(                        Zy)    N)forms)apps)	force_str)gettext_lazy)EntangledModelFormc                     	 t        j                  |       j                  |   S # t        t        f$ r t        |di       cY S w xY w)N )	importlibimport_module__dict__ImportErrorKeyErrortype)modulenames     Q/home/dcms/DCMS/lib/python3.12/site-packages/djangocms_frontend/component_base.py_import_or_emptyr      sF    "&&v.77==" "D"b!!"s   !$ AAmixinssuffixreturnc                     t        |       D cg c]<  }d|v r-|j                  d      d   |j                  d      d    | dfnd| | df> } }| D cg c]  \  }}t        ||       c}}S c c}w c c}}w )z:Find and import mixin classes from a list of mixin strings.r   Mixinzdjangocms_frontend.common)reversedrsplitr   )r   r   mixinr   r   s        r   _get_mixin_classesr      s     f%	  %< 
c	1	%,,s"3B"7!8FG)eWVHE+BC	DF  @FF|vtVT*FF Gs   AA0A5c                       e Zd Zd Zd Zy)classpropertyc                     || _         y Nfget)selfr$   s     r   __init__zclassproperty.__init__   s	    	    c                 $    | j                  |      S r"   r#   )r%   objowners      r   __get__zclassproperty.__get__"   s    yyr'   N)__name__
__module____qualname__r&   r+   r	   r'   r   r    r       s     r'   r    c                       e Zd ZdZd Zy)SlotzASlat class as syntactic surgar to more easily define slot pluginsc                 .    || _         || _        || _        y r"   )r   verbose_namekwargs)r%   r   r2   r3   s       r   r&   zSlot.__init__)   s    	(r'   N)r,   r-   r.   __doc__r&   r	   r'   r   r0   r0   &   s
    Kr'   r0   c                       e Zd ZdZdZeZg Zg ZdZ	dZ
dZg dZedefd       Zedeee fd       Zedefd       Zedefd	       Zedee   fd
       Zedeeeee   f   fd       Zedej6                  e   fd       Zedeeej6                  e   ef      fd       ZdefdZdej@                  de!ddf fdZ" xZ#S )CMSFrontendComponentz#Base class for frontend components:zdjangocms_frontend/slot.htmlN)is_localdisable_editdisable_child_pluginsshow_add_formfrontend_editable_fieldslink_fieldset_positionrequire_parentparent_classesr   c                 R   | j                   ddlm} t        | j                  dg       }t        |d      }t        | j                   dg || | j                  i |dt        dd|dt        | j                  j                               id      i      | _         | j                   S )	Nr   FrontendUIItemr   FormMetar	   config)modelentangled_fields)_admin_formdjangocms_frontend.modelsrA   getattr_component_metar   r   r,   
_base_formlistdeclared_fieldskeys)clsr3   rA   r   s       r   admin_form_factoryz'CMSFrontendComponent.admin_form_factoryD   s    ??"@S00(B?F'7F"<<.% NN
D%3 ($s/B/B/G/G/I*J1	CO* r'   c                     t        | j                  dg       D cg c]  }t        |t              r|nt        |  }}|D ci c],  }| j                   |j
                  j                          d|. c}S c c}w c c}w )NslotsPlugin)rI   rJ   
isinstancer0   r,   r   
capitalize)rO   slotrR   s      r   get_slot_pluginsz%CMSFrontendComponent.get_slot_pluginsb   s     IPPSPcPcelnpHq
@DJtT*Dd;
 
 SXX$3<<.!5!5!7 8?EXX
 Ys   !A51A:c                    | j                   ddlm} t        j                  | j
                        }|t        d| j
                         t        | j                  g | j                  |t        dd|j                  ddt        | j                  d| j                        d	      | j                  | j
                  d
      | _         | j                   S )Nr   r@   zCannot find app_config for rC   r	   TFr   )	app_labelproxymanagedr2   )rC   get_short_descriptionr-   )_modelrH   rA   r   get_containing_app_configr-   
ValueErrorr   r,   _model_mixinslabelrI   rJ   r\   )rO   rA   
app_configs      r   plugin_model_factoryz)CMSFrontendComponent.plugin_model_factoryi   s    ::@77GJ! #>s~~>N!OPP&&"
 !)3)9)9%)',,3C4G4GQTQ]Q],^		 .1-F-F"%..CJ* zzr'   c                    ddl m} | j                  t        | j                  dg       }| j                         }t        |      }t        | j                  dz   g || j                  |t        | j                  d| j                        t        | j                  dt        d            | j                         | j                         |xs t        | j                  dd	      t        | j                  d
g       t        |j                               z   t        | j                  d|j                        t        | d| j!                               d|| j"                  d| j$                  D ci c]/  }t'        | j                  |      r|t        | j                  |      1 c}t'        | d      r| j(                  | j*                  dni ddi      | _        | j                  S c c}w )N   CMSUIComponentr   rS   r   r   
Componentsallow_childrenFchild_classesrender_template	fieldsetsz"djangocms_frontend/admin/base.html)r   r   rE   formri   rj   rk   rl   change_form_templaterR   
save_modelget_render_template)rp   	TEMPLATESr-   zdjangocms_frontend.cms_plugins)ui_plugin_baserg   _pluginrI   rJ   rW   r   r   r,   _plugin_mixins_rc   rP   rL   rN   rk   _generate_fieldsetro   META_FIELDShasattrrp   rq   )rO   rg   r   rR   fields        r   plugin_factoryz#CMSFrontendComponent.plugin_factory   s   2;;S00(B?F((*E'/Fx''' # $C$7$7N%c&9&98Q|_U 557224&+&dws7J7JL\^c/d%,S-@-@/SU%VY]^c^h^h^jYk%k'.s/B/BDUWeWuWu'v!(k3;Q;Q;S!T,P""%.. &)__!"3#6#6> ws':':EBB, #3(=> 473J3J),
  /2 !"B3"CKF {{!s   )4G!c                 T   ddl m} | j                         }|j                         D cg c]q  \  }}t	        ||ft        |j                        t        | j                  dt        d            dddd| j                  dz   g| j                  d|j                        s c}}S c c}}w )	Nr   )CMSPluginBaser   	ComponentTFrS   )r   r   ri   edit_disabledr7   r:   r>   rk   )cms.plugin_baser|   rW   itemsr   r   r2   rI   rJ   ru   r,   slot_templater3   )rO   r|   rR   r   rV   s        r   slot_plugin_factoryz(CMSFrontendComponent.slot_plugin_factory   s    1$$&" $kkm!
  d  %d&7&78%c&9&98Q{^T&*%) %%*'*||h'>&?'*'8'8
 kk

 	
 
s   A6B$c                 `    | j                         | j                         | j                         fS r"   )rc   rz   r   rO   s    r   get_registrationz%CMSFrontendComponent.get_registration   s2     $$& ##%
 	
r'   c                     t        | dd       S )NrC   )rI   r   s    r   rJ   z$CMSFrontendComponent._component_meta   s    sFD))r'   c                 @    d d| j                   j                         ifgS )Nfields)rM   rN   r   s    r   rv   z'CMSFrontendComponent._generate_fieldset   s$    #"5"5":":"<=>??r'   c                 :    | j                   j                  dd      S )Ntitle )rD   get)r%   s    r   r\   z*CMSFrontendComponent.get_short_description   s    {{w++r'   rm   changec                     ddl m} ddlm} t        ||   ||||       |s@| j                  j                         D ]"  } ||j                  ||j                  |       $ yy)zDAuto-creates slot plugins upon creation of component plugin instancer   )
add_pluginre   rf   )targetN)
cms.apir   rr   rg   superro   rR   rN   placeholderlanguage)	r%   requestr)   rm   r   r   rg   rV   	__class__s	           r   ro   zCMSFrontendComponent.save_model   sX    &2nd.wT6J

) L3??D#,,sKL r'   )$r,   r-   r.   r4   r   r   rK   rt   r`   rG   r]   rs   rw   classmethodr   rP   dictstrrW   rc   rz   rL   r   tupler   r    typingOptionalrJ   rv   r\   r   rB   boolro   __classcell__)r   s   @r   r6   r6   /   s~   -2M#JNMKFG	K T  : Yc# Y Y T  < +t + +Z 
DJ 
 
. 
tT4:'=!> 
 
 * 5 * * @4fooc.BD.H(I#J @ @,s ,	LUZZ 	L 	L$ 	L 	Lr'   r6   )r   )r
   r   djangor   django.appsr   django.utils.encodingr   django.utils.translationr   ru   entangled.formsr   r   rL   r   r   r   r    r0   rB   r6   r	   r'   r   <module>r      si        + 6 ."	Gt 	GS 	G$t* 	G    {L5:: {Lr'   