fix url
[auf_rh_dae.git] / project / dashboard.py
1 # -*- encoding: utf-8 -*
2
3 """
4 This file was generated with the customdashboard management command, it
5 contains the two classes for the main dashboard and app index dashboard.
6 You can customize these classes as you want.
7
8 To activate your index dashboard add the following to your settings.py::
9 ADMIN_TOOLS_INDEX_DASHBOARD = 'SIGMA.dashboard.CustomIndexDashboard'
10
11 And to activate the app index dashboard::
12 ADMIN_TOOLS_APP_INDEX_DASHBOARD = 'SIGMA.dashboard.CustomAppIndexDashboard'
13 """
14
15 from django.core.urlresolvers import reverse
16 from django.utils.translation import ugettext_lazy as _
17 from admin_tools.dashboard import modules, Dashboard, AppIndexDashboard
18 from project.decorators import in_drh_or_admin
19 from project.rh.historique import get_active_revisions
20
21 class CustomIndexDashboard(Dashboard):
22 """
23 Custom index dashboard for SIGMA.
24 """
25 def init_with_context(self, context):
26 request = context['request']
27
28 # append an app list module for "Applications"
29 self.children.append(modules.AppList(
30 _('Applications'),
31 models=(
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',
40 ),
41 ))
42
43 if in_drh_or_admin(request.user):
44 revisions = get_active_revisions()[:10]
45 children = []
46 for rev in revisions:
47 date = rev['short_date_created']
48 user = u"<span style='font-weight: bold;'>%s</span>" % rev['user']
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 })
66 self.children.append(modules.LinkList(
67 title='10 dernières modifications',
68 children=children,)
69 )
70
71
72
73 # append an app list module for "Configuration"
74 self.children.append(modules.AppList(
75 _('Configuration'),
76 models=(
77 'project.rh.models.Classement',
78 'project.rh.models.Devise',
79 'project.rh.models.CategorieEmploi',
80 'project.rh.models.FamilleProfessionnelle',
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',
91 ),
92 exclude=('django.contrib.*',),
93 ))
94
95 # append an app list module for "Inter-systèmes"
96 self.children.append(modules.AppList(
97 _(u'Inter-systèmes'),
98 models=(
99 'project.rh.models.ResponsableImplantationProxy',
100 ),
101 ))
102
103 # append an app list module for "Administration"
104 self.children.append(modules.AppList(
105 _('Administration'),
106 models=(
107 'django.contrib.*',
108 ),
109 ))
110
111 class 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 += [
129 modules.ModelList(self.app_title, self.models),
130 ]
131
132 return
133
134 # append an app list module for "Application"
135 self.children.append(modules.AppList(
136 _('Application'),
137 models=(
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',
144 ),
145 ))
146
147 # append an app list module for "Configuration"
148 self.children.append(modules.AppList(
149 _('Configuration'),
150 models=(
151 'project.rh.models.Classement',
152 'project.rh.models.Devise',
153 'project.rh.models.CategorieEmploi',
154 'project.rh.models.FamilleProfessionnelle',
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',
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=(
172 'project.rh.models.ResponsableImplantation',
173 ),
174 ))