Fix for odette
[auf_rh_dae.git] / project / menu.py
1 # -*- coding: utf-8 -*-
2
3 """
4 This file was generated with the custommenu management command, it contains
5 the classes for the admin menu, you can customize this class as you want.
6
7 To activate your custom menu add the following to your settings.py::
8 ADMIN_TOOLS_MENU = 'project.menu.CustomMenu'
9 """
10
11 from django.core.urlresolvers import reverse
12 from django.utils.translation import ugettext_lazy as _
13
14 from admin_tools.menu import items, Menu
15
16 from project.decorators import in_drh_or_admin
17 from project import groups
18
19
20
21 class CustomMenu(Menu):
22 """
23 Custom Menu for project admin site.
24 """
25
26 def __init__(self, **kwargs):
27 Menu.__init__(self, **kwargs)
28 self.children += [
29 items.MenuItem(_('Dashboard'), reverse('admin:index')),
30 #items.Bookmarks(),
31 #items.AppList(
32 # _('Applications'),
33 # exclude=('django.contrib.*', 'project.rh.models.EmployeProxy')
34 #),
35 items.AppList(
36 _('Administration'),
37 models=('django.contrib.*',))]
38
39 def init_with_context(self, context):
40 """
41 Use this method if you need to access the request context.
42 """
43 request = context['request']
44
45 if request.user.is_superuser:
46 self.children += [
47 items.MenuItem('DAE', reverse('admin:app_list',
48 kwargs={'app_label': 'dae'})),
49 ]
50
51 user_groups = [g.name for g in request.user.groups.all()]
52 if in_drh_or_admin(request.user) or\
53 groups.CORRESPONDANT_RH in user_groups or\
54 groups.ADMINISTRATEURS in user_groups or\
55 groups.DIRECTEUR_DE_BUREAU in user_groups:
56 rapports = [
57 items.MenuItem('Rapport des contrats',
58 reverse('rhr_contrats')),
59 items.MenuItem(u'Rapport des employés sans contrat',
60 reverse('rhr_employe_sans_contrat')),
61 items.MenuItem('Rapport de masse salariale',
62 reverse('rhr_masse_salariale')),
63 ]
64 if in_drh_or_admin(request.user):
65 rapports.append(
66 items.MenuItem('Rapport des modifications',
67 reverse('rhr_historique_des_modifications')),
68 )
69
70 items_organigrammes = items.MenuItem('Organigrammes',
71 children=[
72 items.MenuItem('Organigramme par employé',
73 reverse('admin:rh_employeproxy_changelist')),
74 items.MenuItem('Organigramme par service',
75 reverse('admin:rh_serviceproxy_changelist')),
76 items.MenuItem('Organigramme par implantation',
77 reverse('admin:rh_implantationproxy_changelist')),
78 items.MenuItem('Organigramme par bureau',
79 reverse('admin:rh_regionproxy_changelist')),
80 ])
81
82 items_rapports = items.MenuItem('Rapports', children=rapports)
83
84 items_requetes = items.MenuItem('Requêtes',
85 children=[
86 items.MenuItem('Requêtes sauvegardées',
87 reverse('admin:django_qbe_savedquery_changelist')),
88 items.MenuItem('Constructeur de requêtes',
89 reverse('qbe_form')),
90 ])
91
92 children = [items_rapports, items_organigrammes, ]
93 if in_drh_or_admin(request.user):
94 children.append(items_requetes)
95
96 self.children += children
97
98 super(CustomMenu, self).init_with_context(context)