
    &g'                     D   d Z 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dlmZmZ dd	lmZ dd
lmZ ddlmZmZ  ej0                  d      Z G d dej4                        Z G d dej8                        Z G d de      Z G d dej>                        Z y)z
Custom modules for the admin dashboard.

This package adds the following classes:

* :class:`AppIconList`
* :class:`CmsAppIconList`
* :class:`PersonalModule`
* :class:`CacheStatusGroup`
    N)modules)get_admin_site_name)apps)settings)ImproperlyConfigured)NoReverseMatchreverse)gettext_lazy)appsettings)
is_cms_appsort_cms_modelszfluent_dashboard.modulesc                   `     e Zd ZdZdZdZdZ ed      Ze	j                  ZdZ fdZd Z xZS )PersonalModuleap  
    A simple module to display a welcome message.

    .. image:: /images/personalmodule.png
       :width: 471px
       :height: 77px
       :alt: PersonalModule for django-fluent-dashboard

    It renders the template ``fluent_dashboard/modules/personal.html``,
    unless the ``template`` variable is overwritten.
    The module overrides :class:`~admin_tools.dashboard.modules.LinkList`,
    allowing links to be added to the element.
    The :ref:`FLUENT_DASHBOARD_CMS_PAGE_MODEL` setting is used to display a link to the pages module.
    If this setting is not defined, a general text will be displayed instead.
    FWelcome,z&fluent_dashboard/modules/personal.htmlc                    t         |   |       |d   j                  }|j                         xs |j	                         }t        |      }t        d      dz   |z   | _        d| _        d| _	        t        | d      | _        t        | d      | _        | j                  r	 | j                  \  }}t        j                  ||      }|j                   j"                  j%                         }t        dj'                  ||j%                         |j%                                     }	d	|j                   j(                  j%                          }
|j+                  |j                   j,                   d
|
       r|| _	        |	| _        yyy# t.        $ r% t1        dj'                  | j                              t2        $ r Y yw xY w)z,
        Initializes the link list.
        requestr    Nz:password_changez:logoutz{site}:{app}_{model}_changelist)siteappmodelchange_.zwThe value {} of FLUENT_DASHBOARD_CMS_PAGE_MODEL setting (or cms_page_model value) does not reffer to an existing model.)superinit_with_contextuserget_short_nameget_usernamer   _title
pages_linkpages_titler	   password_linklogout_linkcms_page_modelr   	get_model_metaverbose_name_plurallowerformat
model_namehas_perm	app_labelAttributeErrorr   r   )selfcontextcurrent_usercurrent_username	site_namer,   r*   r   r!   r    permission_name	__class__s              Q/var/www/html/djangosite/lib/python3.12/site-packages/fluent_dashboard/modules.pyr   z PersonalModule.init_with_context;   s    	!'*y)..'668WL<U<U<W'0	 z]S(,<=
 $	{2B%CD"i[#891(,(;(;%	:y*=#kk==CCE$5<<&IOO,=ZEUEUEW = 
  %,EKK,B,B,H,H,J+K"L((EKK,A,A+B!OCT)UV'2D$&0DO W/  " * N  U  U++ 
 " s   $BF 5G ?G c                      y)NF )r.   s    r5   is_emptyzPersonalModule.is_emptyh   s        )__name__
__module____qualname____doc__	draggable	deletablecollapsibler   r   r   FLUENT_DASHBOARD_CMS_PAGE_MODELr$   templater   r8   __classcell__r4   s   @r5   r   r      sC    " IIK jME !@@N 8H+1Zr9   r   c                        e Zd ZdZdZej                  Zdj                  ee	j                        Z fdZd Zd Zd	dZd Z xZS )
AppIconLista  
    The list of applications, icon style.

    .. image:: /images/appiconlist.png
       :width: 471px
       :height: 124px
       :alt: AppIconList module for django-fluent-dashboard

    It uses the ``FLUENT_DASHBOARD_APP_ICONS`` setting to find application icons.
    z+fluent_dashboard/modules/app_icon_list.htmlz{}fluent_dashboard/{}/c                    t         |   |       | j                  }|D ]|  }| j                  |      }||d<   |d   D ]\  }	 | j	                  |      }||d<   | j                  ||      xs t        j                  |d<   | j                  |d         |d<   ||d<   ^ ~ y# t        $ r t        j                  |d<   Y ?w xY w),
        Initializes the icon list.
        namemodelsiconapp_nameN)
r   r   children_get_app_name_get_model_nameget_icon_for_modelr   FLUENT_DASHBOARD_DEFAULT_ICON
ValueErrorget_icon_url)r.   r/   r   r   rL   r   r*   r4   s          r5   r   zAppIconList.init_with_context   s     	!'*}}  	-C))#.H"CKX -N!%!5!5e!<J$.E&M//*E E&DD &M !% 1 1%- @f$,j!-		- " N$/$M$ME&MNs   =BB>=B>c                 N    |d   j                  d      j                  d      d   S )z_
        Extract the app name from the ``appdata`` that *django-admin-tools* provides.
        url/)stripsplit)r.   appdatas     r5   rN   zAppIconList._get_app_name   s)     u~##C(..s3B77r9   c                     d|v r&|d   j                  d      j                  d      d   S d|v r&|d   j                  d      j                  d      d   S t        d      )zc
        Extract the model name from the ``modeldata`` that *django-admin-tools* provides.
        
change_urlrV   rW   add_urlz7Missing attributes in modeldata to find the model name!)rX   rY   rR   )r.   	modeldatas     r5   rO   zAppIconList._get_model_name   st     9$,'--c288=bA )#)$**3/55c:2> VWWr9   c                 P    | d| }t         j                  j                  ||      S )zv
        Return the icon for the given model.
        It reads the :ref:`FLUENT_DASHBOARD_APP_ICONS` setting.
        rV   )r   FLUENT_DASHBOARD_APP_ICONSget)r.   rL   r*   defaultkeys        r5   rP   zAppIconList.get_icon_for_model   s-    
 
!J<(5599#wGGr9   c                     |j                  d      sD|j                  d      s3|j                  d      s"d|v r| j                  |z   S | j                  |z   S |S )a  
        Replaces the "icon name" with a full usable URL.

        * When the icon is an absolute URL, it is used as-is.
        * When the icon contains a slash, it is relative from the ``STATIC_URL``.
        * Otherwise, it's relative to the theme url folder.
        rV   zhttp://zhttps://)
startswithicon_static_rooticon_theme_root)r.   rK   s     r5   rS   zAppIconList.get_icon_url   sV     $OOI.OOJ/d{,,t33++d22Kr9   )N)r:   r;   r<   r=   rB   r   
STATIC_URLrg   r)   r   FLUENT_DASHBOARD_ICON_THEMErh   r   rN   rO   rP   rS   rC   rD   s   @r5   rF   rF   m   sS    	 =H  **.55+AAO-88XHr9   rF   c                   "     e Zd ZdZ fdZ xZS )CmsAppIconLista  
    A variation of the :class:`AppIconList` class
    with a strong bias towards sorting CMS apps on top.

    .. image:: /images/cmsappiconlist.png
       :width: 471px
       :height: 124px
       :alt: CmsAppIconList module for django-fluent-dashboard
    c                    t         	|   |       | j                  }|D cg c]  }t        |d         s| }}|D cg c]	  }||vs| }}|r/g }|D ]
  }||d   z  } t	        |       ddd|d}|g|z   | _        yyc c}w c c}w )rH   rI   rJ   Modules )rI   r   rU   rJ   N)r   r   rM   r   r   )
r.   r/   r   acms_appsnon_cms_apps
cms_modelsr   single_cms_appr4   s
            r5   r   z CmsAppIconList.init_with_context   s     	!'*}}#=!z!F)'<A==#'=a1H+<==J ,c(m+
, J'!"$	N ,,|;DM  >=s   BB	B	B)r:   r;   r<   r=   r   rC   rD   s   @r5   rl   rl      s    < <r9   rl   c                   :     e Zd ZdZ ed      ZdZdZ fdZ xZ	S )CacheStatusGroupa  
    Display status modules for Varnish en Memcache, in a :class:`~admin_tools.modules.Group` module.

    This module is only displayed when the :ref:`dashboardmods` package
    is installed, added to the ``INSTALLED_APPS``, and the caches are configured and reachable.
    For more information, see the :ref:`optional dependencies <cachestatus>` page.

    .. image:: /images/cachestatusgroup.png
       :width: 471px
       :height: 198px
       :alt: CacheStatusGroup module for django-fluent-dashboard
    zSystem statusstackedFc                 >   t         |   |       dt        j                  v r0ddl}|j                         }	 |j                         }||z   | _        yy# t        t        f$ r-}t        j                  dt        |              g }Y d}~Cd}~wt        $ r g }Y Sw xY w)z.
        Initializes the status list.
        dashboardmodsr   Nz!Unable to request Varnish stats: )r   r   r   INSTALLED_APPSry   get_memcache_dash_modulesget_varnish_dash_modulesOSErrorKeyErrorlogger	exceptionstrImportErrorrM   )r.   r/   ry   memcache_modsvarnish_modser4   s         r5   r   z"CacheStatusGroup.init_with_context  s     	!'*h555 )CCEM",EEG *L8DM 6 X& "   #DSVH!MN! "!"s   A B##BBB)
r:   r;   r<   r=   r   r   displayenabledr   rC   rD   s   @r5   rv   rv      s(     oEGG9 9r9   rv   )!r=   loggingsocketadmin_tools.dashboardr   admin_tools.utilsr   django.appsr   django.confr   django.core.exceptionsr   django.urlsr   r	   django.utils.translationr
   r   fluent_dashboardr   fluent_dashboard.appgroupsr   r   	getLoggerr   LinkListr   AppListrF   rl   Grouprv   r7   r9   r5   <module>r      s   	   ) 1    7 / 6 ( B			5	6NW%% Nba'// aH$<[ $<N*9w}} *9r9   