CustomAppIndexDashboard   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 26
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 10 1
A init_with_context() 0 5 1
1
# Copyright 2013 Mathias WOLFF
2
# This file is part of pyfreebilling.
3
#
4
# pyfreebilling is free software: you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation, either version 3 of the License, or
7
# (at your option) any later version.
8
#
9
# pyfreebilling is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with pyfreebilling.  If not, see <http://www.gnu.org/licenses/>
16
17
from django.utils.translation import ugettext_lazy as _
18
from django.core.urlresolvers import reverse
19
from admin_tools.dashboard import modules, Dashboard, AppIndexDashboard
20
from admin_tools.utils import get_admin_site_name
21
22
23
class CustomIndexDashboard(Dashboard):
24
    """
25
    Custom index dashboard for pyfreebilling.
26
    """
27
    def init_with_context(self, context):
28
        # request = context['request']
29
30
        # we want a 3 columns layout
31
        self.columns = 3
32
33
        site_name = get_admin_site_name(context)
34
        # append a link list module for "quick links"
35
        self.children.append(modules.LinkList(
36
            _('Quick links'),
37
            layout='inline',
38
            draggable=False,
39
            deletable=False,
40
            collapsible=False,
41
            children=[
42
                [_('Return to site'), '/'],
43
                [_('Change password'),
44
                 reverse('%s:password_change' % site_name)],
45
                [_('Log out'), reverse('%s:logout' % site_name)],
46
            ]
47
        ))
48
49
        # append an app list module for "Applications"
50
        self.children.append(modules.AppList(
51
            _('Applications'),
52
            exclude=('django.contrib.*', 'axes', 'admin_honeypot'),
53
        ))
54
        # append a recent actions module
55
        self.children.append(modules.RecentActions(_('Recent Actions'), 5))
56
57
#        self.children += [SalesChart('Sales', interval='days', days=30)]
58
59
        # append another link list module for "support".
60
        self.children.append(modules.LinkList(
61
            _('PyFreeBilling Support'),
62
            children=[
63
                {
64
                    'title': _('PyFreeBilling documentation'),
65
                    'url': 'https://www.pyfreebilling.com/',
66
                    'external': True,
67
                },
68
            ]
69
        ))
70
71
72
class CustomAppIndexDashboard(AppIndexDashboard):
73
    """
74
    Custom app index dashboard for pyfreebilling.
75
    """
76
77
    # we disable title because its redundant with the model list module
78
    title = ''
79
80
    def __init__(self, *args, **kwargs):
81
        AppIndexDashboard.__init__(self, *args, **kwargs)
82
83
        # append a model list module and a recent actions module
84
        self.children += [
85
            modules.ModelList(self.app_title, self.models),
86
            modules.RecentActions(
87
                _('Recent Actions'),
88
                include_list=self.get_app_content_types(),
89
                limit=5
90
            )
91
        ]
92
93
    def init_with_context(self, context):
94
        """
95
        Use this method if you need to access the request context.
96
        """
97
        return super(CustomAppIndexDashboard, self).init_with_context(context)
98