initilisation
[auf_rh_dae.git] / project / dashboard.py
CommitLineData
8846b99e
OL
1# -*- encoding: utf-8 -*
2
3"""
4This file was generated with the customdashboard management command, it
5contains the two classes for the main dashboard and app index dashboard.
6You can customize these classes as you want.
7
8To activate your index dashboard add the following to your settings.py::
9 ADMIN_TOOLS_INDEX_DASHBOARD = 'SIGMA.dashboard.CustomIndexDashboard'
10
11And to activate the app index dashboard::
12 ADMIN_TOOLS_APP_INDEX_DASHBOARD = 'SIGMA.dashboard.CustomAppIndexDashboard'
13"""
14
8846b99e 15from admin_tools.dashboard import modules, Dashboard, AppIndexDashboard
fc4bf968 16from django.utils.translation import ugettext_lazy as _
8e26a99b
OL
17from reversion.models import Revision
18from project.decorators import in_drh_or_admin
19from project.rh.historique import format_revisions
8846b99e 20
8846b99e
OL
21class CustomIndexDashboard(Dashboard):
22 """
23 Custom index dashboard for SIGMA.
24 """
25 def init_with_context(self, context):
8e26a99b 26 request = context['request']
8846b99e
OL
27
28 # append an app list module for "Applications"
29 self.children.append(modules.AppList(
30 _('Applications'),
d69f7f42 31 models=(
fc4bf968
EMS
32 'project.dae.models.*',
33 'project.recrutement.models.*',
34 'project.rh.models.AyantDroit',
35 'project.rh.models.Dossier',
36 'project.rh.models.DossierInactif',
37 'project.rh.models.Employe',
38 'project.rh.models.EmployeInactif',
39 'project.rh.models.Poste',
d69f7f42
DB
40 ),
41 ))
42
8e26a99b 43 if in_drh_or_admin(request.user):
45c66f19
OL
44 revisions = format_revisions(
45 Revision.objects.exclude(user__isnull=True).order_by('-date_created')[:10])
8e26a99b
OL
46 children = []
47 for rev in revisions:
45c66f19
OL
48 date = rev['short_date_created']
49 user = u"<span style='font-weight: bold;'>%s</span>" % rev['user']
50 type = u"<span style='font-decoration: underligne;'>%s</span>" % rev['type']
51 titre = u"""<span style='color:black;'>[%s] %s a modifié
52 un(e) %s :</span> %s""" % (date, user, type, rev['objet'], )
8e26a99b 53 children.append({
3d6759a8
OL
54 'title': titre,
55 'url': rev['history_url'],
8e26a99b
OL
56 'external': False,
57 })
58 self.children.append(modules.LinkList(
59 title='10 dernières modifications',
60 children=children,)
61 )
62
63
64
d69f7f42
DB
65 # append an app list module for "Configuration"
66 self.children.append(modules.AppList(
67 _('Configuration'),
68 models=(
fc4bf968
EMS
69 'project.rh.models.Classement',
70 'project.rh.models.Devise',
71 'project.rh.models.CategorieEmploi',
321fe481 72 'project.rh.models.FamilleProfessionnelle',
fc4bf968
EMS
73 'project.rh.models.OrganismeBstg',
74 'project.rh.models.Responsable',
75 'project.rh.models.Service',
76 'project.rh.models.Statut',
77 'project.rh.models.TauxChange',
78 'project.rh.models.TypeContrat',
79 'project.rh.models.TypePoste',
80 'project.rh.models.TypeRevalorisation',
81 'project.rh.models.TypeRemuneration',
82 'project.rh.models.ValeurPoint',
56fdab08 83 ),
8846b99e
OL
84 exclude=('django.contrib.*',),
85 ))
86
d69f7f42
DB
87 # append an app list module for "Inter-systèmes"
88 self.children.append(modules.AppList(
89 _(u'Inter-systèmes'),
90 models=(
6fb68b2f 91 'project.rh.models.ResponsableImplantationProxy',
d69f7f42
DB
92 ),
93 ))
94
8846b99e
OL
95 # append an app list module for "Administration"
96 self.children.append(modules.AppList(
97 _('Administration'),
d69f7f42 98 models=(
fc4bf968 99 'django.contrib.*',
d69f7f42 100 ),
8846b99e
OL
101 ))
102
7f43054e
PP
103class CustomAppIndexDashboard(AppIndexDashboard):
104 """
105 Custom app index dashboard for project.
106 """
107
108 # we disable title because its redundant with the model list module
109 title = ''
110
111 def __init__(self, *args, **kwargs):
112 AppIndexDashboard.__init__(self, *args, **kwargs)
113
114 def init_with_context(self, context):
115 """
116 Use this method if you need to access the request context.
117 """
118 if self.app_title != 'Rh':
119 # append a model list module and a recent actions module
120 self.children += [
fc4bf968 121 modules.ModelList(self.app_title, self.models),
7f43054e
PP
122 ]
123
124 return
125
126 # append an app list module for "Application"
127 self.children.append(modules.AppList(
128 _('Application'),
129 models=(
fc4bf968
EMS
130 'project.rh.models.AyantDroit',
131 'project.rh.models.Dossier',
132 'project.rh.models.DossierInactif',
133 'project.rh.models.Employe',
134 'project.rh.models.EmployeInactif',
135 'project.rh.models.Poste',
7f43054e
PP
136 ),
137 ))
138
139 # append an app list module for "Configuration"
140 self.children.append(modules.AppList(
141 _('Configuration'),
142 models=(
fc4bf968
EMS
143 'project.rh.models.Classement',
144 'project.rh.models.Devise',
145 'project.rh.models.CategorieEmploi',
321fe481 146 'project.rh.models.FamilleProfessionnelle',
fc4bf968
EMS
147 'project.rh.models.OrganismeBstg',
148 'project.rh.models.Responsable',
149 'project.rh.models.Service',
150 'project.rh.models.Statut',
151 'project.rh.models.TauxChange',
152 'project.rh.models.TypeContrat',
153 'project.rh.models.TypePoste',
154 'project.rh.models.TypeRevalorisation',
155 'project.rh.models.TypeRemuneration',
156 'project.rh.models.ValeurPoint',
7f43054e
PP
157 ),
158 ))
159
160 # append an app list module for "Inter-systèmes"
161 self.children.append(modules.AppList(
162 _(u'Inter-systèmes'),
163 models=(
fc4bf968 164 'project.rh.models.ResponsableImplantation',
7f43054e
PP
165 ),
166 ))