Completed
Push — master ( da0207...5a5796 )
by Mathias
01:37
created

pyfreebilling.CustomAppIndexDashboard   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %
Metric Value
wmc 2
dl 0
loc 26
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A CustomAppIndexDashboard.init_with_context() 0 5 1
A CustomAppIndexDashboard.__init__() 0 10 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
from django.conf import settings
22
from pyfreebill.modules import SalesChart
23
24
class CustomIndexDashboard(Dashboard):
25
    """
26
    Custom index dashboard for pyfreebilling.
27
    """
28
    def init_with_context(self, context):
29
        request = context['request']
30
31
        # we want a 3 columns layout
32
        self.columns = 3
33
34
        site_name = get_admin_site_name(context)
35
        # append a link list module for "quick links"
36
        self.children.append(modules.LinkList(
37
            _('Quick links'),
38
            layout='inline',
39
            draggable=False,
40
            deletable=False,
41
            collapsible=False,
42
            children=[
43
                [_('Return to site'), '/'],
44
                [_('Change password'),
45
                 reverse('%s:password_change' % site_name)],
46
                [_('Log out'), reverse('%s:logout' % site_name)],
47
            ]
48
        ))
49
50
        # append an app list module for "Applications"
51
        self.children.append(modules.AppList(
52
            _('Applications'),
53
            exclude=('django.contrib.*', 'axes', 'admin_honeypot'),
54
        ))
55
        # append a recent actions module
56
        self.children.append(modules.RecentActions(_('Recent Actions'), 5))
57
58
#        self.children += [SalesChart('Sales', interval='days', days=30)]
59
60
        # append another link list module for "support".
61
        self.children.append(modules.LinkList(
62
            _('PyFreeBilling Support'),
63
            children=[
64
                {
65
                    'title': _('PyFreeBilling documentation'),
66
                    'url': 'http://www.blog-des-telecoms.com/',
67
                    'external': True,
68
                },
69
            ]
70
        ))
71
72
73
class CustomAppIndexDashboard(AppIndexDashboard):
74
    """
75
    Custom app index dashboard for pyfreebilling.
76
    """
77
78
    # we disable title because its redundant with the model list module
79
    title = ''
80
81
    def __init__(self, *args, **kwargs):
82
        AppIndexDashboard.__init__(self, *args, **kwargs)
83
84
        # append a model list module and a recent actions module
85
        self.children += [
86
            modules.ModelList(self.app_title, self.models),
87
            modules.RecentActions(
88
                _('Recent Actions'),
89
                include_list=self.get_app_content_types(),
90
                limit=5
91
            )
92
        ]
93
94
    def init_with_context(self, context):
95
        """
96
        Use this method if you need to access the request context.
97
        """
98
        return super(CustomAppIndexDashboard, self).init_with_context(context)
99
100