
    Bh                     |    d dl mZ d dlmZ d dlmZ ddlmZ  G d de      Zd Z	 G d	 d
e      Z
 G d de      Zy)    )Page)	CMSPlugin)plugin_pool   )SubcommandsCommandc                       e Zd ZdZdZd Zy)ListApphooksCommandzLists all apphooks in pagesapphooksc                 T   t        t        j                  j                  d      j                  d      j	                  dd            }i }|D ])  \  }}||v r||   d   j                  d       "dg|g||<   + |j                         D ]  \  }}|d   j                          |d	   rB| j                  j                  d
j                  ||d	   dj                  |d                      `| j                  j                  dj                  |dj                  |d                       y )N )application_urlsT)application_urls__isnullr   application_namespacer   activer   z{}[instance: {}] ({})
/z{} ({})
)listr   objectsexcludevalues_listappenditemssortstdoutwriteformatjoin)selfargsoptionsurlsr
   apphookr   
attributess           X/home/dcms/DCMS/lib/python3.12/site-packages/cms/management/commands/subcommands/list.pyhandlezListApphooksCommand.handle   s3   LL  " 5==)- > k"$;
 .2 	H*G*("!!$++H5&.Z1F$G!		H
 $,>>#3 		GZqM !}!!";"B"BZ]CHHZ],C#  !!+"4"4SXXjm4# 		    N__name__
__module____qualname__help_stringcommand_namer$    r%   r#   r	   r	      s    /KLr%   r	   c                     g } t         j                  j                  d      }t        t	        |j                  dd                  }|j                          |D ]  }i }||d<   	 t         j                  j                  |      }||d<   t        j                  |      j                  |d<   |D cg c]  }|j                         d	   r| }}||d
<   | j                  |        | S c c}w # t        $ r d|d<   |d<   g |d
<   Y 4w xY w)a>  
    Returns a report of existing plugins

    structure of report:
    [
        {
            'type': CMSPlugin class,
            'model': plugin_type.model,
            'instances': instances in the CMSPlugin table,
            'unsaved_instances': those with no corresponding model instance,
        },
    ]
    plugin_typeT)flattype)r.   	instances)namemodelr   unsaved_instancesN)r   r   order_byr   setr   r   filterr   
get_pluginr3   get_plugin_instanceKeyErrorr   )plugin_reportall_pluginsplugin_typesr.   pluginpluginspr4   s           r#   r;   r;   &   s&    M##,,];KK33M3MNOL# %$v	-''..;.GG")F;)44+FLLF7O,3 Vq1;P;P;RST;U V V*;F&' 	V$%%(  !W  	-"F7O")F;*,F&'	-s+   $AC.0C)	C)C.)C..D	D	c                       e Zd ZdZdZd Zy)ListPluginsCommandzLists all plugins in CMSPluginr?   c                 L   | j                   j                  d       | j                   j                  dt        t                     z         t               D ]L  }| j                   j                  d|d   z         |d   }t        |d         }t        |d         }|s5| j                   j                  | j                  j                  d             n|t        k(  r:| j                   j                  d	       | j                   j                  d
|z         no| j                   j                  d|j                   d|j                   d       |r7| j                   j                  | j                  j                  d|z               | j                   j                  d|z         O y )Nz==== Plugin report ==== 

z,There are %s plugin types in your database 
z
%s 
r0   r3   r1   r4   z  ERROR      : not installed 
z    model-less plugin 
z    unsaved instance(s) : %s  
z  model      : .z  
z'  ERROR      : %s unsaved instance(s) 
z  instance(s): %s 
)	r   r   lenr;   styleERRORr   r(   r'   )r   r   r   r>   plugin_modelr1   r4   s          r#   r$   zListPluginsCommand.handleT   s[   89ICP]P_L``a#o 	BFKKi&.89!'?LF;/0I #F+>$? @!!$**"2"23T"UV*!!"<=!!"DGX"XY !!OL4K4K3LAlNcNcMddh"ij$KK%%djj&6&67adu7u&vwKK4y@A'	Br%   Nr&   r,   r%   r#   rB   rB   P   s    2KLBr%   rB   c                       e Zd ZdZdZeedZy)ListCommandz$List objects of the following types:r   )r
   r?   N)r'   r(   r)   r*   r+   r	   rB   subcommandsr,   r%   r#   rJ   rJ   m   s    8KL'%Kr%   rJ   N)
cms.modelsr   cms.models.pluginmodelr   cms.plugin_poolr   baser   r	   r;   rB   rJ   r,   r%   r#   <module>rP      s@     , ' $, <'TB+ B:$ r%   