fix for 500 error
[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 """
e1a81904 23 Custom index dashboard for SGRH.
8846b99e
OL
24 """
25 def init_with_context(self, context):
8e26a99b 26 request = context['request']
8846b99e
OL
27
28 # append an app list module for "Applications"
e1a81904 29 self.children.append(modules.Group(
8846b99e 30 _('Applications'),
e1a81904
PP
31 display='stacked',
32 children=[
33 modules.ModelList(
34 title='Demande d\'autorisation d\'engagement',
35 models=(
36 'project.dae.models.*',
37 )
38 ),
39 modules.ModelList(
e4d2c0d2 40 title='Recrutement',
e1a81904
PP
41 models=(
42 'auf.django.emploi.models.OffreEmploi',
43 'project.recrutement.models.ProxyOffreEmploi',
44 'auf.django.emploi.models.Candidat',
45 'project.recrutement.models.ProxyCandidat',
46 'project.recrutement.models.CandidatEvaluation',
47 'project.recrutement.models.MesCandidatEvaluation',
48 'project.recrutement.models.Evaluateur',
9fc5dedb 49 'project.recrutement.models.OffreEmploiEvaluateur',
e1a81904
PP
50 'project.recrutement.models.CourrielTemplate',
51 )
52 ),
53 modules.ModelList(
54 title='Gestion des personnels',
55 models=(
56 'project.rh.models.AyantDroit',
57 'project.rh.models.Dossier',
58 'project.rh.models.DossierInactif',
59 'project.rh.models.Employe',
60 'project.rh.models.EmployeInactif',
61 'project.rh.models.Poste',
62 )
63 ),
343cfd9c
BS
64 modules.ModelList(
65 title='Log',
66 models=(
67 'project.rh.models.ChangementPersonnel',
68 )
69 ),
e1a81904 70 ]
d69f7f42
DB
71 ))
72
62201d27 73
8e26a99b 74 if in_drh_or_admin(request.user):
edbc9e37 75 revisions = get_active_revisions()[:10]
8e26a99b
OL
76 children = []
77 for rev in revisions:
45c66f19
OL
78 date = rev['short_date_created']
79 user = u"<span style='font-weight: bold;'>%s</span>" % rev['user']
ca108b40
OL
80 if rev['type'] is None or rev['objet'] is None:
81 titre = u"""<span style='color:black;'>[%s] %s</span>
82 commentaire : %s """ % (date, user, rev['comment'])
83 children.append({
84 'title': titre,
85 'url': reverse('rhr_historique_des_modifications'),
86 'external': False,
87 })
88 else:
89 type = u"<span style='font-decoration: underligne;'>%s</span>" % rev['type']
90 titre = u"""<span style='color:black;'>[%s] %s a modifié
91 un(e) %s :</span> %s""" % (date, user, type, rev['objet'], )
92 children.append({
93 'title': titre,
94 'url': rev['history_url'],
95 'external': False,
96 })
8e26a99b
OL
97 self.children.append(modules.LinkList(
98 title='10 dernières modifications',
99 children=children,)
100 )
101
102
103
d69f7f42
DB
104 # append an app list module for "Configuration"
105 self.children.append(modules.AppList(
106 _('Configuration'),
107 models=(
fc4bf968
EMS
108 'project.rh.models.Classement',
109 'project.rh.models.Devise',
110 'project.rh.models.CategorieEmploi',
321fe481 111 'project.rh.models.FamilleProfessionnelle',
fc4bf968
EMS
112 'project.rh.models.OrganismeBstg',
113 'project.rh.models.Responsable',
114 'project.rh.models.Service',
115 'project.rh.models.Statut',
116 'project.rh.models.TauxChange',
117 'project.rh.models.TypeContrat',
118 'project.rh.models.TypePoste',
119 'project.rh.models.TypeRevalorisation',
120 'project.rh.models.TypeRemuneration',
121 'project.rh.models.ValeurPoint',
343cfd9c 122 'project.rh.models.ChangementPersonnelNotifications',
56fdab08 123 ),
8846b99e
OL
124 exclude=('django.contrib.*',),
125 ))
126
d69f7f42
DB
127 # append an app list module for "Inter-systèmes"
128 self.children.append(modules.AppList(
129 _(u'Inter-systèmes'),
130 models=(
6fb68b2f 131 'project.rh.models.ResponsableImplantationProxy',
d69f7f42
DB
132 ),
133 ))
134
8846b99e
OL
135 # append an app list module for "Administration"
136 self.children.append(modules.AppList(
137 _('Administration'),
d69f7f42 138 models=(
fc4bf968 139 'django.contrib.*',
d69f7f42 140 ),
8846b99e
OL
141 ))
142
7f43054e
PP
143class CustomAppIndexDashboard(AppIndexDashboard):
144 """
145 Custom app index dashboard for project.
146 """
147
148 # we disable title because its redundant with the model list module
149 title = ''
150
151 def __init__(self, *args, **kwargs):
152 AppIndexDashboard.__init__(self, *args, **kwargs)
153
154 def init_with_context(self, context):
155 """
156 Use this method if you need to access the request context.
157 """
158 if self.app_title != 'Rh':
159 # append a model list module and a recent actions module
160 self.children += [
fc4bf968 161 modules.ModelList(self.app_title, self.models),
7f43054e
PP
162 ]
163
164 return
165
166 # append an app list module for "Application"
167 self.children.append(modules.AppList(
168 _('Application'),
169 models=(
fc4bf968
EMS
170 'project.rh.models.AyantDroit',
171 'project.rh.models.Dossier',
172 'project.rh.models.DossierInactif',
173 'project.rh.models.Employe',
174 'project.rh.models.EmployeInactif',
175 'project.rh.models.Poste',
7f43054e
PP
176 ),
177 ))
178
179 # append an app list module for "Configuration"
180 self.children.append(modules.AppList(
181 _('Configuration'),
182 models=(
fc4bf968
EMS
183 'project.rh.models.Classement',
184 'project.rh.models.Devise',
185 'project.rh.models.CategorieEmploi',
321fe481 186 'project.rh.models.FamilleProfessionnelle',
fc4bf968
EMS
187 'project.rh.models.OrganismeBstg',
188 'project.rh.models.Responsable',
189 'project.rh.models.Service',
190 'project.rh.models.Statut',
191 'project.rh.models.TauxChange',
192 'project.rh.models.TypeContrat',
193 'project.rh.models.TypePoste',
194 'project.rh.models.TypeRevalorisation',
195 'project.rh.models.TypeRemuneration',
196 'project.rh.models.ValeurPoint',
7f43054e
PP
197 ),
198 ))
199
200 # append an app list module for "Inter-systèmes"
201 self.children.append(modules.AppList(
202 _(u'Inter-systèmes'),
203 models=(
fc4bf968 204 'project.rh.models.ResponsableImplantation',
7f43054e
PP
205 ),
206 ))