o
    QDi+                     @   s   d dl Z d dlZd dlmZ d dlmZ d dlmZmZm	Z	 d dl
mZ d dlmZmZ d dlmZ d dlmZ d d	lmZmZ d d
lmZ G dd deZdd Zdd Ze	dd Ze	dd Zdd Ze	dd Ze	dd Z e	dd Z!e	dd Z"dS )    N)	AppConfig)settings)ErrorWarningregister)GZipMiddleware)NoReverseMatchreverse)import_string)gettext_lazy)APP_NAMEr   )CONFIG_DEFAULTSc                       s0   e Zd ZdZedZdd Z fddZ  ZS )DebugToolbarConfigdebug_toolbarzDebug Toolbarc                 C   s0   ddl m} | D ]}|  q
t| j d S )Nr   DebugToolbar)debug_toolbar.toolbarr   get_panel_classesready_manage_migrations_visibilityname)selfr   cls r   K/var/www/Datamplify/venv/lib/python3.10/site-packages/debug_toolbar/apps.pyr      s   
zDebugToolbarConfig.readyc                    s(   t  }|d dkrt  S i | _dS )a  
        Override import models to avoid allowing users to dynamically fetch a model
        that doesn't have a table behind it unless they are using the DatabaseStore.
        This also prevents the command `migrate --run-syncdb` from creating tables
        for the models.
        TOOLBAR_STORE_CLASS!debug_toolbar.store.DatabaseStoreN)dt_settings
get_configsuperimport_modelsmodels)r   	dt_config	__class__r   r   r       s   

z DebugToolbarConfig.import_models)	__name__
__module____qualname__r   _verbose_namer   r    __classcell__r   r   r#   r   r      s
    	r   c                 C   s&   t  d dkrtj| d dS dS )z
    Adjust the toolbar's migration visibility by manipulating the
    project's settings.

    This is a hack since it's manipulating settings.
    r   r   N)r   r   r   MIGRATION_MODULES
setdefault)app_namer   r   r   r   +   s
   
r   c                    sT    fdd |  dd}|  di  dd}|rt |}|du p%d|v }|p)|S )	a  
    Checks if a template configuration is valid.

    The toolbar requires either the toolbars to be unspecified or
    ``django.template.loaders.app_directories.Loader`` to be
    included in the loaders.
    If custom loaders are specified, then APP_DIRS must be True.
    c                 3   s>    | D ]}t |tr|d V   |d E dH  q|V  qdS )z
        Recursively flatten the settings list of template loaders.

        Check for (loader, [child_loaders]) tuples.
        Django's default cached loader uses this pattern.
        r      N)
isinstancetuple)loadersloaderflat_loadersr   r   r4   D   s   

z+check_template_config.<locals>.flat_loadersAPP_DIRSFOPTIONSr1   Nz.django.template.loaders.app_directories.Loader)getlist)configapp_dirsr1   has_app_loadersr   r3   r   check_template_config:   s   
r<   c                 K   s  ddl m} g }d }g }tdd tjD r |tdddd td	r1|td
ddd |S ttj	D ]\}}t
t|rB|}q6t
||rL|| q6|s[|tdddd |S t|dkrm|tdddd |S |d ur|d |k r|tdddd |S )Nr   )DebugToolbarMiddlewarec                 s   s    | ]}t | V  qd S N)r<   ).0r9   r   r   r   	<genexpr>f   s    z#check_middleware.<locals>.<genexpr>zAt least one DjangoTemplates TEMPLATES configuration needs to use django.template.loaders.app_directories.Loader or have APP_DIRS set to True.zInclude django.template.loaders.app_directories.Loader in ["OPTIONS"]["loaders"]. Alternatively use APP_DIRS=True for at least one django.template.backends.django.DjangoTemplates backend configuration.zdebug_toolbar.W006hintidMIDDLEWARE_CLASSESz>debug_toolbar is incompatible with MIDDLEWARE_CLASSES setting.z,Use MIDDLEWARE instead of MIDDLEWARE_CLASSESzdebug_toolbar.W004zKdebug_toolbar.middleware.DebugToolbarMiddleware is missing from MIDDLEWARE.zBAdd debug_toolbar.middleware.DebugToolbarMiddleware to MIDDLEWARE.zdebug_toolbar.W001r.   zTdebug_toolbar.middleware.DebugToolbarMiddleware occurs multiple times in MIDDLEWARE.zMLoad debug_toolbar.middleware.DebugToolbarMiddleware only once in MIDDLEWARE.zdebug_toolbar.W002zrdebug_toolbar.middleware.DebugToolbarMiddleware occurs before django.middleware.gzip.GZipMiddleware in MIDDLEWARE.zrMove debug_toolbar.middleware.DebugToolbarMiddleware to after django.middleware.gzip.GZipMiddleware in MIDDLEWARE.zdebug_toolbar.W003)debug_toolbar.middlewarer=   allr   	TEMPLATESappendr   is_overridden	enumerate
MIDDLEWAREis_middleware_classr   len)app_configskwargsr=   errors
gzip_indexdebug_toolbar_indexesi
middlewarer   r   r   check_middleware^   sl   



	rU   c                 K   s:   ddl m} g }| D ]}| D ]}|| qq|S )zOAllow each panel to check the toolbar's integration for their its own purposes.r   r   )r   r   r   
run_checksrH   )rN   rO   r   rP   panel_classcheck_messager   r   r   check_panel_configs   s   rY   c                 C   s6   zt |}W n
 ty   Y d S w t|ot|| S r>   )r
   ImportErrorinspectisclass
issubclass)middleware_classmiddleware_pathmiddleware_clsr   r   r   rL      s   rL   c                 K   s(   g }t  }|s|tdddd |S )Nz&Setting DEBUG_TOOLBAR_PANELS is empty.zASet DEBUG_TOOLBAR_PANELS to a non-empty list in your settings.py.zdebug_toolbar.W005rA   )r   
get_panelsrH   r   )rN   rO   rP   panelsr   r   r   check_panels   s   rc   c                 K   s6   ddh}t td| }|rtddddgS g S )zP
    Check that JavaScript files are resolving to the correct content type.
    zapplication/javascriptztext/javascriptz
toolbar.jsz9JavaScript files are resolving to the wrong content type.a  The Django Debug Toolbar may not load properly while mimetypes are misconfigured. See the Django documentation for an explanation of why this occurs.
https://docs.djangoproject.com/en/stable/ref/contrib/staticfiles/#static-file-development-view

This typically occurs on Windows machines. The suggested solution is to modify HKEY_CLASSES_ROOT in the registry to specify the content type for JavaScript files.

[HKEY_CLASSES_ROOT\.js]
"Content Type"="application/javascript"zdebug_toolbar.W007rA   )set	mimetypes
guess_typeintersectionr   )rN   rO   javascript_typescheck_failedr   r   r   js_mimetype_check   s   
rj   c                 K   sv   t  d td k}ztt d d}W n ty    d}Y nw |o%| }tjs9t  d r9|r9tdddd	gS g S )
zI
    Check that the toolbar is not being used when tests are running
    SHOW_TOOLBAR_CALLBACKz:render_panelTFIS_RUNNING_TESTSz1The Django Debug Toolbar can't be used with testsaR  Django changes the DEBUG setting to False when running tests. By default the Django Debug Toolbar is installed because DEBUG is set to True. For most cases, you need to avoid installing the toolbar when running tests. If you feel this check is in error, you can set `DEBUG_TOOLBAR_CONFIG['IS_RUNNING_TESTS'] = False` to bypass this check.zdebug_toolbar.E001rA   )	r   r   r   r	   r   r   r   DEBUGr   )rN   rO   show_toolbar_changedtoolbar_urls_installedlikely_error_setupr   r   r   0debug_toolbar_installed_when_running_tests_check   s0   


rq   c                 K   s0   g }t tdi }d|v r|tdddd |S )NDEBUG_TOOLBAR_CONFIGOBSERVE_REQUEST_CALLBACKzSThe deprecated OBSERVE_REQUEST_CALLBACK setting is present in DEBUG_TOOLBAR_CONFIG.zFUse the UPDATE_ON_FETCH and/or SHOW_TOOLBAR_CALLBACK settings instead.zdebug_toolbar.W008rA   )getattrr   rH   r   )rN   rO   rP   USER_CONFIGr   r   r   check_settings"  s   rv   )#r[   re   django.appsr   django.confr   django.core.checksr   r   r   django.middleware.gzipr   django.urlsr   r	   django.utils.module_loadingr
   django.utils.translationr   r(   r   r   r   debug_toolbar.settingsr   r   r   r<   rU   rY   rL   rc   rj   rq   rv   r   r   r   r   <module>   s6    $
N




/