Multiples zones par user implémenté
[auf_rh_dae.git] / project / rh / admin.py
index f70f405..04ca2ef 100644 (file)
@@ -5,6 +5,8 @@ import datetime
 import reversion
 from ajax_select import make_ajax_form
 from auf.django.references import models as ref
+from django.contrib.auth.admin import UserAdmin
+from django.contrib.auth.models import User
 from django import forms
 from django.core.urlresolvers import reverse
 from django.contrib import admin
@@ -21,8 +23,7 @@ from project.permissions import user_gere_obj_de_sa_region, \
         user_can_list_obj, \
         user_can_add_obj, \
         user_can_change_obj, \
-        user_can_delete_obj, \
-        get_region_user
+        user_can_delete_obj
 
 from project.rh.forms import ContratForm, AyantDroitForm, EmployeAdminForm, \
         AjaxSelect, DossierForm, ResponsableInlineForm
@@ -149,10 +150,9 @@ class ProtectRegionMixin(object):
         if listing_par_defaut(self.model, request):
             if user_gere_obj_de_sa_region(request.user):
                 params = request.GET.copy()
-                employe = groups.get_employe_from_user(request.user)
-                za = employe.implantation.zone_administrative.code
-                prefix_za = "%s__code__exact" % self.model.prefix_implantation
-                params.update({prefix_za: za})
+                zones = groups.get_zones_from_user(request.user)
+                prefix_za = "%s__in" % self.model.prefix_implantation
+                params.update({prefix_za: zones})
                 request.GET = params
         return super(ProtectRegionMixin, self) \
                 .changelist_view(request, extra_context)
@@ -164,9 +164,9 @@ class ProtectRegionMixin(object):
             return qs
 
         if user_gere_obj_de_sa_region(request.user):
-            region_user = get_region_user(request.user)
-            q = Q(**{self.model.prefix_implantation: \
-                    region_user})
+            zones = groups.get_zones_from_user(request.user)
+            qkey = '%s__in' % self.model.prefix_implantation
+            q = Q(**{qkey: zones})
             qs = qs.filter(q).distinct()
             return qs
         return qs.none()
@@ -454,6 +454,7 @@ class DossierAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin,
         if key in (
             'employe__nom__istartswith',
             'poste__implantation__zone_administrative__code__exact',
+            'poste__implantation__zone_administrative__in',
             'poste__implantation__id__exact',
             'poste__type_poste__id__exact',
             'poste__type_poste__categorie_emploi__id__exact',
@@ -1338,6 +1339,17 @@ class RegionProxyAdmin(BaseAdmin):
     _organigramme.short_description = "Organigramme"
 
 
+class ProfileInline(admin.StackedInline):
+    model = rh.UserProfile
+    
+
+class RHUserAdmin(UserAdmin):
+    inlines = list(UserAdmin.inlines) + [ProfileInline]
+    
+
+admin.site.unregister(User)
+admin.site.register(User, RHUserAdmin)
+
 admin.site.register(rh.Classement, ClassementAdmin)
 admin.site.register(rh.Devise, DeviseAdmin)
 admin.site.register(rh.Dossier, DossierAdmin)