
    &g+                         d 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mZ  G d de      Z G d de      Z G d de      Z G d de      Zy# e$ r ddlmZ ddlmZ	 ddl
mZ Y Tw xY w)z9
Module where admin tools dashboard classes are defined.
    )slugify)import_module)reverse)gettext_lazy)	force_str)ugettext_lazy)
force_text)modules)get_admin_site_nameuniquifyc                   X    e Zd ZdZ ed       ZdZdZdZ G d d      Z	d Z
d Zd	 Zd
 Zy)	Dashboarda  
    Base class for dashboards.
    The Dashboard class is a simple python list that has three additional
    properties:

    ``title``
        The dashboard title, by default, it is displayed above the dashboard
        in a ``h2`` tag. Default value: 'Dashboard'.

    ``template``
        The template to use to render the dashboard.
        Default value: 'admin_tools/dashboard/dashboard.html'

    ``columns``
        An integer that represents the number of columns for the dashboard.
        Default value: 2.

    If you want to customize the look of your dashboard and it's modules, you
    can declare css stylesheets and/or javascript files to include when
    rendering the dashboard (these files should be placed in your
    media path), for example::

        from admin_tools.dashboard import Dashboard

        class MyDashboard(Dashboard):
            class Media:
                css = {
                    'screen, projection': ('css/mydashboard.css',),
                }
                js = ('js/mydashboard.js',)

    Here's an example of a custom dashboard::

        from django.core.urlresolvers import reverse
        from django.utils.translation import ugettext_lazy as _
        from admin_tools.dashboard import modules, Dashboard

        class MyDashboard(Dashboard):

            # we want a 3 columns layout
            columns = 3

            def __init__(self, **kwargs):

                # append an app list module for "Applications"
                self.children.append(modules.AppList(
                    title=_('Applications'),
                    exclude=('django.contrib.*',),
                ))

                # append an app list module for "Administration"
                self.children.append(modules.AppList(
                    title=_('Administration'),
                    models=('django.contrib.*',),
                ))

                # append a recent actions module
                self.children.append(modules.RecentActions(
                    title=_('Recent Actions'),
                    limit=5
                ))

    Below is a screenshot of the resulting dashboard:

    .. image:: images/dashboard_example.png
    z$admin_tools/dashboard/dashboard.html   Nc                       e Zd ZdZdZy)Dashboard.Media N)__name__
__module____qualname__cssjsr       Y/var/www/html/djangosite/lib/python3.12/site-packages/admin_tools/dashboard/dashboards.pyMediar   _   s    r   r   c                     |D ])  }t        | j                  |      st        | |||          + | j                  xs g | _        y )N)hasattr	__class__setattrchildren)selfkwargskeys      r   __init__zDashboard.__init__c   sA     	0Ct~~s+c6#;/	0 +r   c                      y)a  
        Sometimes you may need to access context or request variables to build
        your dashboard, this is what the ``init_with_context()`` method is for.
        This method is called just before the display with a
        ``django.template.RequestContext`` as unique argument, so you can
        access to all context variables and to the ``django.http.HttpRequest``.
        Nr   )r    contexts     r   init_with_contextzDashboard.init_with_contexti   s     	r   c                      y)V
        Internal method used to distinguish different dashboards in js code.
        	dashboardr   r    s    r   get_idzDashboard.get_ids   s     r   c                     t               }t        | j                        D ]@  \  }}t        |j                  xs t        |dz         |      |_        |j                          B y)z) Enumerates children without explicit id    N)set	enumerater   r   idstr_prepare_children)r    seenr0   modules       r   r2   zDashboard._prepare_childreny   sP    u#DMM2 	'JB !7c"Q$i>FI$$&	'r   )r   r   r   __doc___titletemplatecolumnsr   r   r#   r&   r+   r2   r   r   r   r   r      sA    AF kNE5HGH ,'r   r   c                   <     e Zd ZdZdZdZ fdZd Zd Zd Z	 xZ
S )AppIndexDashboarda  
    Class that represents an app index dashboard, app index dashboards are
    displayed in the applications index page.
    :class:`~admin_tools.dashboard.AppIndexDashboard` is very similar to the
    :class:`~admin_tools.dashboard.Dashboard` class except
    that its constructor receives two extra arguments:

    ``app_title``
        The title of the application

    ``models``
        A list of strings representing the available models for the current
        application, example::

            ['yourproject.app.Model1', 'yourproject.app.Model2']

    It also provides two helper methods:

    ``get_app_model_classes()``
        Method that returns the list of model classes for the current app.

    ``get_app_content_types()``
        Method that returns the list of content types for the current app.

    If you want to provide custom app index dashboard, be sure to inherit from
    this class instead of the :class:`~admin_tools.dashboard.Dashboard` class.

    Here's an example of a custom app index dashboard::

        from django.urls import reverse
        from django.utils.translation import gettext_lazy as _
        from admin_tools.dashboard import modules, AppIndexDashboard

        class MyAppIndexDashboard(AppIndexDashboard):

            # we don't want a title, it's redundant
            title = ''

            def __init__(self, app_title, models, **kwargs):
                AppIndexDashboard.__init__(self, app_title, models, **kwargs)

                # append a model list module that lists all models
                # for the app and a recent actions module for the current app
                self.children += [
                    modules.ModelList(self.app_title, self.models),
                    modules.RecentActions(
                        include_list=self.models,
                        limit=5
                    )
                ]

    Below is a screenshot of the resulting dashboard:

    .. image:: images/dashboard_app_index_example.png
    Nc                 T    |j                  ||d       t        t        |   di | y )N)	app_titlemodelsr   )updatesuperr;   r#   )r    r=   r>   r!   r   s       r   r#   zAppIndexDashboard.__init__   s'    I@A/9&9r   c                     g }| j                   D ]=  }|j                  dd      \  }}t        |      }|j                  t	        ||             ? |S )zY
        Helper method that returns a list of model classes for the current app.
        .r-   )r>   rsplitr   appendgetattr)r    r>   mmodclss        r   get_app_model_classesz'AppIndexDashboard.get_app_model_classes   sT      	-AxxQ'HC$CMM'#s+,	- r   c                     ddl m} g }| j                         D ]-  }	 |j                  |j                  j                  |             / |S # t        $ r Y =w xY w)zB
        Return a list of all content_types for this app.
        r   )ContentType)"django.contrib.contenttypes.modelsrK   rI   rD   objectsget_for_modelAttributeError)r    rK   resultrH   s       r   get_app_content_typesz'AppIndexDashboard.get_app_content_types   sd    
 	C--/ 	Ck11??DE	  "  	s   *A	AAc                 D    dt        t        | j                              z  S )r(   z%s-dashboard)r   r   r=   r*   s    r   r+   zAppIndexDashboard.get_id   s     	$..(A BBBr   )r   r   r   r5   r>   r=   r#   rI   rQ   r+   __classcell__)r   s   @r   r;   r;      s*    6p FI:	$Cr   r;   c                       e Zd ZdZd Zy)DefaultIndexDashboardag  
    The default dashboard displayed on the admin index page.
    To change the default dashboard you'll have to type the following from the
    commandline in your project root directory::

        python manage.py customdashboard

    And then set the ``ADMIN_TOOLS_INDEX_DASHBOARD`` settings variable to
    point to your custom index dashboard class.
    c                    t        |      }| j                  j                  t        j                  t        d      ddddt        d      dgt        d      t        d|z        gt        d      t        d	|z        gg
             | j                  j                  t        j                  t        d      d             | j                  j                  t        j                  t        d      d             | j                  j                  t        j                  t        d      d             | j                  j                  t        j                  t        d      dd             | j                  j                  t        j                  t        d      t        d      dddt        d      dddt        d      dddg             y )NzQuick linksinlineFzReturn to site/zChange passwordz%s:password_changezLog outz	%s:logout)layout	draggable	deletablecollapsibler   Applications)zdjango.contrib.*)excludeAdministration)r>   Recent Actions   zLatest Django Newsz(http://www.djangoproject.com/rss/weblog/)feed_urllimitSupportzDjango documentationzhttp://docs.djangoproject.com/T)r7   urlexternalz"Django "django-users" mailing listz+http://groups.google.com/group/django-userszDjango irc channelzirc://irc.freenode.net/django)r   )
r   r   rD   r
   LinkListr6   r   AppListRecentActionsFeed)r    r%   	site_names      r   r&   z'DefaultIndexDashboard.init_with_context   s   '0	W--m#$c*$%-	9:<9w{Y'>?@	
 	 	W__n)
 	 	W__(
 	 	W2215E3FJK 	W\\"#?
 	 	W--iL 56; $ CDH $ 34: $
 	r   N)r   r   r   r5   r&   r   r   r   rU   rU      s    	;r   rU   c                       e Zd ZdZdZd Zy)DefaultAppIndexDashboardav  
    The default dashboard displayed on the applications index page.
    To change the default dashboard you'll have to type the following from the
    commandline in your project root directory::

        python manage.py customdashboard

    And then set the ``ADMIN_TOOLS_APP_INDEX_DASHBOARD`` settings variable to
    point to your custom app index dashboard class.
     c                    t        j                  | g|i | | xj                  t        j                  | j
                  | j                        t        j                  t        d      | j                         d      gz  c_        y )Nr`   ra   )include_listrc   )
r;   r#   r   r
   	ModelListr=   r>   ri   r6   rQ   )r    argsr!   s      r   r#   z!DefaultAppIndexDashboard.__init__=  sm    ""49$9&9 	dnndkk:!!"#!779
 	
r   N)r   r   r   r5   r7   r#   r   r   r   rm   rm   .  s    	 E
r   rm   N)r5   django.template.defaultfiltersr   	importlibr   django.urlsr   django.utils.translationr   r6   django.utils.encodingr   ImportErrordjango.core.urlresolversr   r	   admin_tools.dashboardr
   admin_tools.utilsr   r   objectr   r;   rU   rm   r   r   r   <module>r}      s    3 #	> $:/ * ;h' h'VaC	 aCHFI FR
0 
C	  >0;=>s   A A76A7