fix test group
[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
ca108b40 15from django.core.urlresolvers import reverse
fc4bf968 16from django.utils.translation import ugettext_lazy as _
ca108b40 17from admin_tools.dashboard import modules, Dashboard, AppIndexDashboard
8e26a99b 18from project.decorators import in_drh_or_admin
edbc9e37 19from project.rh.historique import get_active_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):
edbc9e37 44 revisions = get_active_revisions()[:10]
8e26a99b
OL
45 children = []
46 for rev in revisions:
45c66f19
OL
47 date = rev['short_date_created']
48 user = u"<span style='font-weight: bold;'>%s</span>" % rev['user']
ca108b40
OL
49 if rev['type'] is None or rev['objet'] is None:
50 titre = u"""<span style='color:black;'>[%s] %s</span>
51 commentaire : %s """ % (date, user, rev['comment'])
52 children.append({
53 'title': titre,
54 'url': reverse('rhr_historique_des_modifications'),
55 'external': False,
56 })
57 else:
58 type = u"<span style='font-decoration: underligne;'>%s</span>" % rev['type']
59 titre = u"""<span style='color:black;'>[%s] %s a modifié
60 un(e) %s :</span> %s""" % (date, user, type, rev['objet'], )
61 children.append({
62 'title': titre,
63 'url': rev['history_url'],
64 'external': False,
65 })
8e26a99b
OL
66 self.children.append(modules.LinkList(
67 title='10 dernières modifications',
68 children=children,)
69 )
70
71
72
d69f7f42
DB
73 # append an app list module for "Configuration"
74 self.children.append(modules.AppList(
75 _('Configuration'),
76 models=(
fc4bf968
EMS
77 'project.rh.models.Classement',
78 'project.rh.models.Devise',
79 'project.rh.models.CategorieEmploi',
321fe481 80 'project.rh.models.FamilleProfessionnelle',
fc4bf968
EMS
81 'project.rh.models.OrganismeBstg',
82 'project.rh.models.Responsable',
83 'project.rh.models.Service',
84 'project.rh.models.Statut',
85 'project.rh.models.TauxChange',
86 'project.rh.models.TypeContrat',
87 'project.rh.models.TypePoste',
88 'project.rh.models.TypeRevalorisation',
89 'project.rh.models.TypeRemuneration',
90 'project.rh.models.ValeurPoint',
56fdab08 91 ),
8846b99e
OL
92 exclude=('django.contrib.*',),
93 ))
94
d69f7f42
DB
95 # append an app list module for "Inter-systèmes"
96 self.children.append(modules.AppList(
97 _(u'Inter-systèmes'),
98 models=(
6fb68b2f 99 'project.rh.models.ResponsableImplantationProxy',
d69f7f42
DB
100 ),
101 ))
102
8846b99e
OL
103 # append an app list module for "Administration"
104 self.children.append(modules.AppList(
105 _('Administration'),
d69f7f42 106 models=(
fc4bf968 107 'django.contrib.*',
d69f7f42 108 ),
8846b99e
OL
109 ))
110
7f43054e
PP
111class CustomAppIndexDashboard(AppIndexDashboard):
112 """
113 Custom app index dashboard for project.
114 """
115
116 # we disable title because its redundant with the model list module
117 title = ''
118
119 def __init__(self, *args, **kwargs):
120 AppIndexDashboard.__init__(self, *args, **kwargs)
121
122 def init_with_context(self, context):
123 """
124 Use this method if you need to access the request context.
125 """
126 if self.app_title != 'Rh':
127 # append a model list module and a recent actions module
128 self.children += [
fc4bf968 129 modules.ModelList(self.app_title, self.models),
7f43054e
PP
130 ]
131
132 return
133
134 # append an app list module for "Application"
135 self.children.append(modules.AppList(
136 _('Application'),
137 models=(
fc4bf968
EMS
138 'project.rh.models.AyantDroit',
139 'project.rh.models.Dossier',
140 'project.rh.models.DossierInactif',
141 'project.rh.models.Employe',
142 'project.rh.models.EmployeInactif',
143 'project.rh.models.Poste',
7f43054e
PP
144 ),
145 ))
146
147 # append an app list module for "Configuration"
148 self.children.append(modules.AppList(
149 _('Configuration'),
150 models=(
fc4bf968
EMS
151 'project.rh.models.Classement',
152 'project.rh.models.Devise',
153 'project.rh.models.CategorieEmploi',
321fe481 154 'project.rh.models.FamilleProfessionnelle',
fc4bf968
EMS
155 'project.rh.models.OrganismeBstg',
156 'project.rh.models.Responsable',
157 'project.rh.models.Service',
158 'project.rh.models.Statut',
159 'project.rh.models.TauxChange',
160 'project.rh.models.TypeContrat',
161 'project.rh.models.TypePoste',
162 'project.rh.models.TypeRevalorisation',
163 'project.rh.models.TypeRemuneration',
164 'project.rh.models.ValeurPoint',
7f43054e
PP
165 ),
166 ))
167
168 # append an app list module for "Inter-systèmes"
169 self.children.append(modules.AppList(
170 _(u'Inter-systèmes'),
171 models=(
fc4bf968 172 'project.rh.models.ResponsableImplantation',
7f43054e
PP
173 ),
174 ))