î
#dÝV»  ã               @   s¢   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 Gd d	 „  d	 e j e	 j ƒ ƒ Z Gd
 d „  d e ƒ Z d S)z7
Module where grappelli dashboard classes are defined.
é    )Úsix)Úugettext_lazy)Úreverse)Úforms)Úmodules)Úget_admin_site_namec               @   sX   e  Z d  Z d Z e d  ƒ Z d Z d Z d Z d d „  Z	 d d „  Z
 d	 d
 „  Z d S)Ú	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 = {
                    'all': (
                        'css/mydashboard.css',
                        'css/mystyles.css',
                    ),
                }
                js = (
                    'js/mydashboard.js',
                    'js/myscript.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):
                super(MyDashboard, self).__init__(**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
                ))

    z"grappelli/dashboard/dashboard.htmlé   Nc             K   sP   x7 | D]/ } t  |  j | ƒ r t |  | | | ƒ q q W|  j pF g  |  _ d  S)N)ÚhasattrÚ	__class__ÚsetattrÚchildren)ÚselfÚkwargsÚkey© r   úJ/tmp/pip-build-0jahl3lb/django-grappelli/grappelli/dashboard/dashboards.pyÚ__init___   s    zDashboard.__init__c             C   s   d S)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   Úcontextr   r   r   Úinit_with_contexte   s    zDashboard.init_with_contextc             C   s   d S)zV
        Internal method used to distinguish different dashboards in js code.
        zgrp-dashboardr   )r   r   r   r   Úget_ido   s    zDashboard.get_id)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú_ÚtitleÚtemplateÚcolumnsr   r   r   r   r   r   r   r   r      s   F
r   c               @   s"   e  Z d  Z d Z d d „  Z d S)ÚDefaultIndexDashboardad  
    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 `GRAPPELLI_INDEX_DASHBOARD`` settings variable to
    point to your custom index dashboard class.
    c             C   s’  t  | ƒ } |  j j t j t d ƒ d d d t d ƒ d g t d ƒ t d | ƒ g t d	 ƒ t d
 | ƒ g g ƒƒ |  j j t j t d ƒ d d! ƒƒ |  j j t j t d ƒ d d" ƒƒ |  j j t j t d ƒ d ƒ ƒ |  j j t j	 t d ƒ d d d d ƒƒ |  j j t j t d ƒ d i t d ƒ d 6d d 6d d 6i t d ƒ d 6d d 6d d 6i t d ƒ d 6d  d 6d d 6g ƒƒ d  S)#NzQuick linksZcollapsibleFr   zReturn to siteú/zChange passwordz%s:password_changezLog outz	%s:logoutZApplicationsÚexcludeúdjango.contrib.*ZAdministrationÚmodelszRecent Actionsé   zLatest Django NewsZfeed_urlz(http://www.djangoproject.com/rss/weblog/ÚlimitZSupportzDjango documentationr   zhttp://docs.djangoproject.com/ÚurlTZexternalz"Django "django-users" mailing listz+http://groups.google.com/group/django-userszDjango irc channelzirc://irc.freenode.net/django)r"   )r"   )
r   r   Úappendr   ZLinkListr   r   ZAppListZRecentActionsZFeed)r   r   Z	site_namer   r   r   r   ‚   sB    	#

"
z'DefaultIndexDashboard.init_with_contextN)r   r   r   r   r   r   r   r   r   r   v   s   
r   N)r   Zdjango.utilsr   Zdjango.utils.translationr   r   Zdjango.core.urlresolversr   Zdjangor   Zgrappelli.dashboardr   Zgrappelli.dashboard.utilsr   Úwith_metaclassZMediaDefiningClassr   r   r   r   r   r   Ú<module>   s   "d