o
    h                     @   s6   d dl mZ d dlmZ d dlmZ G dd dZdS )    )render_to_string)settings)get_name_from_objc                   @   s
  e Zd ZdZdd Zedd ZedefddZed	d
 Z	edd Z
edd Zedd Zedd Zedd Zedd Zedd Zedd Zedd Zdd Zdd  Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd/d0 Zed1d2 Zd3S )4Panelz 
    Base class for panels.
    c                 C   s   || _ || _d S N)toolbarget_response)selfr   r    r
   [/var/www/html/ictaz-jobs/venv/lib/python3.10/site-packages/debug_toolbar/panels/__init__.py__init__   s   
zPanel.__init__c                 C   s   | j jS r   )	__class____name__r	   r
   r
   r   panel_id   s   zPanel.panel_idreturnc                 C   sR   | j jjd| j }|d ur|dkS t d }t| }||vo(|dd|vS )NdjdtonDISABLE_PANELSz.panel..)	r   requestCOOKIESgetr   dt_settings
get_configr   replace)r	   cookie_valuedisabled_panels
panel_pathr
   r
   r   enabled   s   zPanel.enabledc                 C      | j S )zI
        Title shown in the side bar. Defaults to :attr:`title`.
        )titler   r
   r
   r   	nav_title+   s   zPanel.nav_titlec                 C      dS )zO
        Subtitle shown in the side bar. Defaults to the empty string.
         r
   r   r
   r
   r   nav_subtitle2      zPanel.nav_subtitlec                 C   r#   )z
        ``True`` if the panel can be displayed in full screen, ``False`` if
        it's only shown in the side bar. Defaults to ``True``.
        Tr
   r   r
   r
   r   has_content9   s   zPanel.has_contentc                 C   r    )zg
        Panel supports rendering historical values.

        Defaults to :attr:`has_content`.
        )r'   r   r
   r
   r   is_historicalA   s   zPanel.is_historicalc                 C      t )z
        Title shown in the panel when it's displayed in full screen.

        Mandatory, unless the panel sets :attr:`has_content` to ``False``.
        NotImplementedErrorr   r
   r
   r   r!   J   s   zPanel.titlec                 C   r)   )z
        Template used to render :attr:`content`.

        Mandatory, unless the panel sets :attr:`has_content` to ``False`` or
        overrides :attr:`content`.
        r*   r   r
   r
   r   templateS   s   zPanel.templatec                 C   s   | j rt| j|  S dS )z
        Content of the panel when it's displayed in full screen.

        By default this renders the template defined by :attr:`template`.
        Statistics stored with :meth:`record_stats` are available in the
        template's context.
        N)r'   r   r,   	get_statsr   r
   r
   r   content]   s   	zPanel.contentc                 C      g S )a  
        Scripts used by the HTML content of the panel when it's displayed.

        When a panel is rendered on the frontend, the ``djdt.panel.render``
        JavaScript event will be dispatched. The scripts can listen for
        this event to support dynamic functionality.
        r
   r   r
   r
   r   scriptsi   s   	zPanel.scriptsc                 C   r#   )a  
        Perform early initialization for the panel.

        This should only include initialization or instrumentation that needs to
        be done unconditionally for the panel regardless of whether it is
        enabled for a particular request.  It should be idempotent.
        Nr
   clsr
   r
   r   readyv       zPanel.readyc                 C   r/   )zE
        Return URLpatterns, if the panel has its own views.
        r
   r1   r
   r
   r   get_urls   r&   zPanel.get_urlsc                 C   r#   )a  
        Enable instrumentation to gather data for this panel.

        This usually means monkey-patching (!) or registering signal
        receivers. Any instrumentation with a non-negligible effect on
        performance should be installed by this method rather than at import
        time.

        Unless the toolbar or this panel is disabled, this method will be
        called early in ``DebugToolbarMiddleware``. It should be idempotent.
        Nr
   r   r
   r
   r   enable_instrumentation   r4   zPanel.enable_instrumentationc                 C   r#   )a  
        Disable instrumentation to gather data for this panel.

        This is the opposite of :meth:`enable_instrumentation`.

        Unless the toolbar or this panel is disabled, this method will be
        called late in the middleware. It should be idempotent.
        Nr
   r   r
   r
   r   disable_instrumentation   r4   zPanel.disable_instrumentationc                 C   s   | j j| ji | dS )
        Store data gathered by the panel. ``stats`` is a :class:`dict`.

        Each call to ``record_stats`` updates the statistics dictionary.
        N)r   stats
setdefaultr   update)r	   r9   r
   r
   r   record_stats   s   zPanel.record_statsc                 C      | j j| ji S zK
        Access data stored by the panel. Returns a :class:`dict`.
        )r   r9   r   r   r   r
   r
   r   r-         zPanel.get_statsc                 C   s*   |||di}| j j| ji | dS )r8   )r!   valueN)r   server_timing_statsr:   r   r;   )r	   keyr!   r@   datar
   r
   r   record_server_timing   s   zPanel.record_server_timingc                 C   r=   r>   )r   rA   r   r   r   r
   r
   r   get_server_timing_stats   r?   zPanel.get_server_timing_statsc                 C   s
   |  |S )z
        Like __call__ in Django's middleware.

        Write panel logic related to the request there. Save data with
        :meth:`record_stats`.

        Return the existing response or overwrite it.
        )r   )r	   r   r
   r
   r   process_request   s   
	zPanel.process_requestc                    s4   i }   }|rd fdd| D |d< |S )a  
        Get headers the panel needs to set.

        Called after :meth:`process_request
        <debug_toolbar.panels.Panel.generate_stats>` and
        :meth:`process_request<debug_toolbar.panels.Panel.generate_stats>`

        Header values will be appended if multiple panels need to set it.

        By default it sets the Server-Timing header.

        Return dict of headers to be appended.
        z, c              	   3   s2    | ]\}}d   j||d|dV  qdS )z{}_{};dur={};desc="{}"r@   r!   N)formatr   r   ).0rB   recordr   r
   r   	<genexpr>   s    
z$Panel.get_headers.<locals>.<genexpr>zServer-Timing)rE   joinitems)r	   r   headersr9   r
   r   r   get_headers   s   zPanel.get_headersc                 C   r#   )a*  
        Write panel logic related to the response there. Post-process data
        gathered while the view executed. Save data with :meth:`record_stats`.

        Called after :meth:`process_request
        <debug_toolbar.panels.Panel.process_request>`.


        Does not return a value.
        Nr
   r	   r   responser
   r
   r   generate_stats   r4   zPanel.generate_statsc                 C   r#   )z
        Similar to :meth:`generate_stats
        <debug_toolbar.panels.Panel.generate_stats>`,

        Generate stats for Server Timing https://w3c.github.io/server-timing/

        Does not return a value.
        Nr
   rO   r
   r
   r   generate_server_timing   r4   zPanel.generate_server_timingc                 C   r/   )a  
        Check that the integration is configured correctly for the panel.

        This will be called as a part of the Django checks system when the
        application is being setup.

        Return a list of :class:`django.core.checks.CheckMessage` instances.
        r
   r1   r
   r
   r   
run_checks   s   
zPanel.run_checksN)r   
__module____qualname____doc__r   propertyr   boolr   r"   r%   r'   r(   r!   r,   r.   r0   classmethodr3   r5   r6   r7   r<   r-   rD   rE   rF   rN   rQ   rR   rS   r
   r
   r
   r   r      sN    






	



	
r   N)django.template.loaderr   debug_toolbarr   r   debug_toolbar.utilsr   r   r
   r
   r
   r   <module>   s    