
    Bh5O                     ^   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 d
lmZ d dlmZ dZdZdZdZg Z G d d      Z G d de      Zd Zed        Zed        Zed        Zed        Z ed        Z!ed        Z"ed        Z#ed        Z$ed        Z%d Z&y)    N)contextmanager)chain)settings)method_decoratorcolorize)validate_template)	constants)AliasPluginModel)is_installed)get_cms_setting            c                   ~    e Zd ZdZd ZddZddZd ZddZd Z	d Z
d	 Zd
 Zd Z ee      d        Zed        Zy)FileOutputWrappera2  
    Wraps two file-like objects (that support at the very least the 'write'
    method) into an API to be used by the check function further down in
    this module.

    The following properties are public (and required) by alternative implementations:

        errors: integer count of errors encountered
        successes: integer count of successes encountered
        warnings: integer count of warnings encountered
        skips: integer count of skips encountered
        successful: Whether the checks were successful (no errors)

    They must also provide these methods:

        write_line(message=''): writes a message to stdout
        write_stderr_line(message=''): writes a message to stderr
        success(message): reports and registers a successful check
        error(message): reports and registers an error
        warn(message); reports and registers a warning
        skip(message): reports and registers a skipped check
        section(title): A context manager that starts a new section. For the
            Section API see FileSectionWrapper
    c                 n    || _         || _        t        | _        d| _        d| _        d| _        d| _        y )Nr   )stdoutstderrFileSectionWrappersection_wrappererrors	successeswarningsskips)selfr   r   s      ?/home/dcms/DCMS/lib/python3.12/site-packages/cms/utils/check.py__init__zFileOutputWrapper.__init__1   s4    1
    c                     t        |fd|i|S )Noptsr   )r   msgr"   kwargss       r   r   zFileOutputWrapper.colorize:   s    1$1&11r    c                 ,    | j                  d|z         y Nz%s
writer   messages     r   
write_linezFileOutputWrapper.write_line=   s    

6G#$r    c                 :    | j                   j                  |       y N)r   r(   r)   s     r   r(   zFileOutputWrapper.write@       '"r    c                 ,    | j                  d|z         y r&   write_stderrr)   s     r   write_stderr_linez#FileOutputWrapper.write_stderr_lineC   s    &7*+r    c                 :    | j                   j                  |       y r-   )r   r(   r)   s     r   r1   zFileOutputWrapper.write_stderrF   r.   r    c           
          | xj                   dz  c_         | j                  dj                  || j                  dddg                   y )Nr   {} {}z[OK]greenboldfgr"   )r   r+   formatr   r)   s     r   successzFileOutputWrapper.successI   s:    !wfX^W_0`abr    c           
          | xj                   dz  c_         | j                  dj                  || j                  dddg                   y )Nr   r5   z[ERROR]redr7   r8   )r   r2   r:   r   r)   s     r   errorzFileOutputWrapper.errorM   s=    qw~~gt}}YSX`f_g}7hijr    c           
          | xj                   dz  c_         | j                  dj                  || j                  dddg                   y )Nr   r5   z	[WARNING]yellowr7   r8   )r   r2   r:   r   r)   s     r   warnzFileOutputWrapper.warnQ   s=    w~~gt}}[U]ekdl}7mnor    c           
          | xj                   dz  c_         | j                  dj                  || j                  dddg                   y )Nr   r5   z[SKIP]bluer7   r8   )r   r+   r:   r   r)   s     r   skipzFileOutputWrapper.skipU   s9    

a
wh6Y_X`0abcr    c              #   D  K   | j                  | j                  |dg             | j                  | j                  dt        |      z  dg             | j                          | j                  |       }	 | | xj
                  |j
                  z  c_        | xj                  |j                  z  c_        | xj                  |j                  z  c_        | xj                  |j                  z  c_        | j                  d       y #  | j	                  d        xY ww)Nr7   r"   =zChecker failed, see traceback )	r+   r   lenr   r>   r   r   r   r   )r   titlewrappers      r   sectionzFileOutputWrapper.sectionY   s     e6(;<cCJ&6fXFG&&t,	M 	w~~%'+++)))

gmm#
	JJ67s   A4D 7D	 ;BD 	DD c                     | j                    S r-   )r   )r   s    r   
successfulzFileOutputWrapper.successfulj   s    ;;r    N) rH   )__name__
__module____qualname____doc__r   r   r+   r(   r2   r1   r;   r>   rA   rD   r   r   rL   propertyrN   rO   r    r   r   r      sj    22%#,#ckpd n% &   r    r   c                   J     e Zd ZdZ fdZd	dZd	dZd Zd Zd Z	d Z
 xZS )
r   a@  
    Used from FileOutputWrapper to report checks in a section.

    If you want to provide your own output class, you may want to subclass
    this class for the section reporting too. If you want to use your own,
    you must defined at least the same API as FileOutputWrapper, as well
    as these four additional methods:

        finish_success(message): End the section (successfully)
        finish_error(message): End the section with errors
        finish_warning(message): End this section with a warning
        finish_skip(message): End this (skipped) section
    c                 \    t         |   |j                  |j                         || _        y r-   )superr   r   r   rK   )r   rK   	__class__s     r   r   zFileSectionWrapper.__init__~   s!    8r    c                 ,    | j                  d|z         y Nz  - %s
r'   r)   s     r   r+   zFileSectionWrapper.write_line   s    

:'(r    c                 ,    | j                  d|z         y r[   r0   r)   s     r   r2   z$FileSectionWrapper.write_stderr_line   s    *w./r    c                 n    | j                   j                          | j                   j                  |       y r-   )rK   r+   r;   r)   s     r   finish_successz!FileSectionWrapper.finish_success   $    !W%r    c                 n    | j                   j                          | j                   j                  |       y r-   )rK   r+   r>   r)   s     r   finish_errorzFileSectionWrapper.finish_error   s$    !7#r    c                 n    | j                   j                          | j                   j                  |       y r-   )rK   r+   warningr)   s     r   finish_warningz!FileSectionWrapper.finish_warning   r_   r    c                 n    | j                   j                          | j                   j                  |       y r-   )rK   	write_linrD   r)   s     r   finish_skipzFileSectionWrapper.finish_skip   s$     '"r    rP   )rQ   rR   rS   rT   r   r+   r2   r^   ra   rd   rg   __classcell__)rY   s   @r   r   r   o   s+    )0&$&#r    r   c                 0    t         j                  |        | S )z8
    Helper decorator to register a check function.
    )CHECKERSappend)funcs    r   define_checkrm      s     OODKr    c                    | j                  d      5 }t        d      }|r|j                  d       n|j                  d       t	        t        t        j                  D cg c]  }|d   j                  dg        c}       }d|v r|j                  d       n|j                  d	       |s
	 d d d        y t        d
      D ]P  \  }}|t        j                  k(  rt        |ddg      r|j                  d|z         =|j                  d|z         R |j                  r|j                  d       n|j                  d       d d d        y c c}w # 1 sw Y   y xY w)NSekizaisekizaizSekizai is installedzDSekizai is not installed, could not find 'sekizai' in INSTALLED_APPSOPTIONScontext_processorsz"sekizai.context_processors.sekizaiz/Sekizai template context processor is installedzSekizai template context processor is not installed, could not find 'sekizai.context_processors.sekizai' in TEMPLATES option context_processors	TEMPLATESjscssz-Sekizai namespaces 'js' and 'css' found in %rz1Sekizai namespaces 'js' and 'css' not found in %rzSekizai configuration okayz Sekizai configuration has errors)rL   r   r;   r>   listr   r   rs   getr   r
   TEMPLATE_INHERITANCE_MAGICr	   rN   r^   ra   )outputrL   sekizai_installedtemplate
processors_s         r   check_sekizair~      s^   			" "Eg(3OO23MM`aV^VhVhi(HY'++,@"Eij

 0:=OOMNMM^
 ! -"E "E0 +;7 	^KHa9??? D%=9 ORZ Z[QT\\]	^ ""#?@  !CDE"E "E j"E "Es%   AEE;2E6BEEEc           	      T   | j                  d      5 }t        t        t        di       t              r|j                  d       n|j                  d       t        t        dd      j                  d      dkD  r#|j                  d	t        t        dd      z         t        t        d
d      D ]1  }|d   j                  d      dkD  s|j                  d|d   z         3 t        j                  t        t        j                        k(  rit        d
      j                         D ]L  \  }}t        |t              s|D ]1  }|d   j                  d      dkD  s|j                  d|d   z         3 N n"|j                  dt        j                  z         d d d        y # 1 sw Y   y xY w)NInternationalizationCMS_LANGUAGESzNew style CMS_LANGUAGESzXOld style (tuple based) CMS_LANGUAGES, please switch to the new (dictionary based) styleLANGUAGE_CODErH   r}   zpLANGUAGE_CODE must contain a valid language code, not a locale (e.g.: 'en-us' instead of 'en_US'): '%s' provided	LANGUAGESrO   r   zjLANGUAGES must contain valid language codes, not locales (e.g.: 'en-us' instead of 'en_US'): '%s' providedcodezvCMS_LANGUAGES entries must contain valid language codes, not locales (e.g.: 'en-us' instead of 'en_US'): '%s' providedz"SITE_ID must be an integer, not %r)rL   
isinstancegetattrr   dictr;   rA   findSITE_IDhashr   itemsintr>   )ry   rL   langsiter   s        r   
check_i18nr      s   	.	/ S7gh<dCOO56LLst8_b166s;b@LL*,3Hor,RS Hk26 	DAw||C 2%.04Q8	 tH$4$455.{;AAC edC( % <,,S1B6#LL!MOSTZ|!\ MM>AQAQQR5S S Ss   B4FA2F:F>FF'c                     | j                  d      5 }d}t        t        dg       }|D ]  }||vs|j                  d|z          	 d d d        y # 1 sw Y   y xY w)NMiddlewares)
z4django.contrib.sessions.middleware.SessionMiddlewarez)django.middleware.csrf.CsrfViewMiddlewarez7django.contrib.auth.middleware.AuthenticationMiddlewarez4django.contrib.messages.middleware.MessageMiddlewarez)django.middleware.locale.LocaleMiddlewarez)django.middleware.common.CommonMiddlewarez)cms.middleware.user.CurrentUserMiddlewarez)cms.middleware.page.CurrentPageMiddlewarez(cms.middleware.toolbar.ToolbarMiddlewarez0cms.middleware.language.LanguageCookieMiddleware
MIDDLEWAREz#%s middleware must be in MIDDLEWARE)rL   r   r   r>   )ry   rL   required_middlewaresmiddlewares
middlewares        r   check_middlewaresr      sl    		& R' 
 hb9. 	RJ,CjPQ	RR R Rs   AAAc                     | j                  d      5 }t        t        t        j                  D cg c]  }|d   j                  dg        c}       }d}|D ]  }||vs|j                  d|z          	 d d d        y c c}w # 1 sw Y   y xY w)NzContext processorsrq   rr   )z#cms.context_processors.cms_settingsz'django.template.context_processors.i18nzC%s context processor must be in TEMPLATES option context_processors)rL   rv   r   r   rs   rw   r>   )ry   rL   r{   r|   required_processors	processors         r   check_context_processorsr      s    	,	- qV^VhVhi(HY'++,@"Eij

 q, 	qI
*cfoop	qq qiq qs"   BA?BB?BBc                    ddl m} | j                  d      5 } |       }|j                  dt	        |      z         |D ]T  }|d   s|j                  d|d   z         |d   s%|j                  d	j                  |d   t	        |d                      V |j                  r|j                  d
       n|j                  d       d d d        y # 1 sw Y   y xY w)Nr   )plugin_reportzPlugin instancesz2Plugin instances of %s types found in the databasemodelz+%s has instances but is no longer installedtypeunsaved_instancesz{} has {} unsaved instancesz.The plugins in your database are in good ordera"  There are potentially serious problems with the plugins in your database. 
Even if your site works, you should run the 'manage.py cms list plugins' 
command and then the 'manage.py cms delete-orphaned-plugins' command. 
This will alter your database; read the documentation before using it.)
(cms.management.commands.subcommands.listr   rL   r;   rI   r>   r:   rN   r^   ra   )ry   r   rL   reportplugin_types        r   check_plugin_instancesr   	  s    F	*	+ wLsSY{Z[! 	Kw'KkZ`Naab./188V9LcR]^qRrNst	 ""#ST  D%  s   AC$A!CCc           
         ddl m} ddlm} ddlm} ddlm} d }d }| j                  d      5 }|j                          |j                  j                         D ]  }|j                  }	 |d	|	      |us|	|u r|	j                  j                  D ]/  }
|j                   ||	       d
 ||
j                         d       1 |	j!                         D ]t  }
|
j                  |k7  st#        |
j                  |j                        r4|
j                  t$        k7  sH|j                   ||	       d ||
j                         d       v  t'        |j(                  |j*                        D ]  } |d	|      |ur|j                  j                  D ]9  }
|j                   ||      d
 ||
j,                  j                        d       ; |j!                         D ]?  }
|
j                  |k7  s|j                   ||       d ||
j                         d       A  |j.                  s|j1                  d       n|j1                  d       d d d        y # 1 sw Y   y xY w)Nr   )extension_pool)BaseExtension)	CMSPluginplugin_poolc                 8    | j                    d| j                   S )N.)rR   rQ   )klasss    r   c_to_sz$check_copy_relations.<locals>.c_to_s.  s    ""#1U^^$455r    c                 \    t        j                  |      D ]  }| |j                  v s|c S  y r-   )inspectgetmro__dict__)method_namer   clss      r   	get_classz'check_copy_relations.<locals>.get_class1  s0    >>%( 	Ccll*
	 r    zPresence of "copy_relations"copy_relationsz  has a many-to-many relation to z-,
    but no "copy_relations" method defined.z has a foreign key from zTAll plugins and page/page content extensions have "copy_relations" method if needed.aq  Some plugins or page/page content extensions do not define a "copy_relations" method.
This might lead to data loss when publishing or copying plugins/extensions.
See https://django-cms.readthedocs.io/en/latest/extending_cms/custom_plugins.html#handling-relations or https://django-cms.readthedocs.io/en/latest/extending_cms/extending_page_title.html#handling-relations.)cms.extensionsr   cms.extensions.modelsr   cms.models.pluginmodelr   cms.plugin_poolr   rL   discover_pluginspluginsvaluesr   _metamany_to_manyrA   _get_related_objects
issubclassr   r   page_extensionspage_content_extensionsremote_fieldr   r^   )ry   r   r   r   r   r   r   rL   pluginplugin_classrel	extensions               r   check_copy_relationsr   '  sm   -30+6 
6	7 47$$&!))002 	F!<<L)<8	I\]fMf #))66 l+,,LVTWT]T]M^L_  `N  O $88: II*&syy&,,?		%55LL!,/00HPSPYPYIZH[  \J  K	( ~==~?e?ef 	I)95]J  33  y)s//556	 !557 99	)LL!),--EfSYYFWEX  YG  H	( ""f ""z_4 4 4s&   B4I% IICI/A II!c                    | j                  d      5 }t        d      rt        t        d      t        t        f      rt        d      D ]  }t        |t        t        f      s|j                  d       +t        |      dk7  r|j                  d       Kt        |d   t              s|j                  d       p|j                  d        n|j                  d	       t        t        d
      r|j                  d       nt        d      rt        t        d      t        t        f      rut        d      D ]f  }t        |t        t        f      s|j                  d       +t        |d   t              s|j                  d|d           V|j                  d       h n#|j                  d       n|j                  d       d d d        y # 1 sw Y   y xY w)NzTemplate configurationrs   z5CMS_TEMPLATES setting contains a non-list/tuple entryr   z=CMS_TEMPLATES setting contains a list/tuple with != 2 entriesr   z)CMS_TEMPLATES contains a non-string entryz1CMS_TEMPLATES_DIR or CMS_TEMPLATES setting  foundz,CMS_TEMPLATES setting is not a list or tupleCMS_PLACEHOLDERSz=CMS_PLACEHOLDERS setting is also present but will be ignored.PLACEHOLDERSz8CMS_PLACEHOLDERS setting contains a non-list/tuple entryzACMS_PLACEHOLDERS contains an entry with a non-string identifier: zDCMS_PLACEHOLDERS setting entry found - CMS will run in headless modez/CMS_PLACEHOLDERS setting is not a list or tuplez}Both CMS_TEMPLATES and CMS_PLACEHOLDERS settings are missing. Will run in headless mode with one placeholder called "content")rL   r   r   rv   tupler>   rI   strr;   hasattrr   rA   )ry   rL   r{   placeholders       r   check_template_confr   n  s   	0	1 !W;'/+6uF / < ]H%hu>&]^X!+&ef'S9&QR([\] LMx!34\]^,/.9D%=I#2>#B pK%kD%=A&`a'A<_`klm`n_op  (nop OPLLR=! ! !s   F/G

Gc                 &   ddl m} | j                  d      5 }|j                         D ]5  \  }}|j	                  |      j
                  "|j                  d|z         7 |j                  r|j                  d       d d d        y # 1 sw Y   y xY w)Nr   )apphook_poolApphooksz4CMSApps should define a name. %s doesn't have a namezCMSApps configuration is okay)	cms.apphook_poolr   rL   get_apphooksget_apphooknamerA   rN   r^   )ry   r   rL   hookr   s        r   check_cmsapps_namesr     s    -	
	# Dw&335 	\JD$''-22:SVZZ[	\ ""#BCD D Ds   2B3BBc           
         ddl m} | j                  d      5 }|j                          |j                  j                         D ]  }t        |d      rS|j                  rG|j                  D ]8  }|dvs||j                  vs|j                  d| d|j                   d       : t        |d	      so|j                  s||j                  D ]3  }||j                  vs|j                  d
| d|j                   d       5  |j                  r|j                  d       n|j                  d       d d d        y # 1 sw Y   y xY w)Nr   r   zPlugin parent/child relationsparent_classes)0rH   zParent plugin class 'z' not found for plugin ''child_classeszChild plugin class 'z'Plugin parent/child relations are validzySome plugins have invalid parent/child class configurations.
This might cause unexpected behavior in the admin interface.)r   r   rL   r   r   r   r   r   rA   rQ   r   rN   r^   rd   )ry   r   rL   r   parent_classchild_classs         r   #check_plugin_parent_child_relationsr     sG   +	7	8 G$$&!))002 	uFv/0V5J5J$*$9$9 wL#94[M`M`9`'<\NJbcicrcrbsst%uvw
 v/F4H4H#)#7#7 uK"+*=*==';K=H`agapap`qqr%stu	u ""#LM""O%  s+   AD;2D;0D;2D;?D;AD;;Ec                    ddl }d|j                   d}dt        |      z  }| j                  | j	                  |dg             | j                  | j	                  |dg             | j                  | j	                  |dg             | j                          t
        D ]
  } ||         | j                          | j                  d      5  | j                  r1| j                  | j	                  d	| j                  z  dgd
             | j                  r1| j                  | j	                  d| j                  z  dgd             | j                  r1| j                  | j	                  d| j                  z  dgd             | j                  | j	                  d| j                  z  dgd             | j                          | j                  r%| j                  | j	                  ddgd
             nU| j                  r%| j                  | j	                  ddgd             n$| j                  | j	                  ddgd             ddd       | j                  S # 1 sw Y   | j                  S xY w)z
    Checks the configuration/environment of this django CMS installation.

    'output' should be an object that provides the same API as FileOutputWrapper.

    Returns whether the configuration/environment are okay (has no errors)
    r   NzChecking django CMS z installation*r7   rF   zOVERALL RESULTSz
%s errors!r=   )r"   r9   z%s warnings!r@   z%s checks skipped!rC   z%s checks successful!r6   zPlease check the errors abovez2Installation okay, but please check warnings abovezInstallation okay)cms__version__rI   r+   r   rj   rL   r   r2   r   r   r   rN   )ry   r   rJ   bordercheckers        r   checkr     s4    "3??"3=AE3u:F
foofF8o<=
fooe6(o;<
foofF8o<=
 
	)	* _==$$V__\FMM5QY_X`ej_%kl??$$V__^foo5U]c\diq_%rs<<foo.BV\\.QY_X`ekolm&//*AFDTDT*T\b[cho/pq==$$V__5T\b[chm_%no__$$ T\b[chpq foo.AU\o]^!_" #_" s   E?I##I7)'r   
contextlibr   	itertoolsr   django.confr   django.utils.decoratorsr   django.utils.termcolorsr   sekizai.helpersr	   r   r
   
cms.modelsr   cms.utils.compat.djr   cms.utils.confr   SUCCESSWARNINGERRORSKIPPEDrj   r   r   rm   r~   r   r   r   r   r   r   r   r   r   rO   r    r   <module>r      s'    %    4 , -  ' , *

	
U Up'#* '#T #E #EL S S< R R* q q  : C CL " "J D D  6$r    