fix DRH peut mettre toutes les implantations
authorOlivier Larchevêque <olivier.larcheveque@auf.org>
Thu, 1 Nov 2012 20:52:45 +0000 (16:52 -0400)
committerOlivier Larchevêque <olivier.larcheveque@auf.org>
Thu, 1 Nov 2012 20:52:45 +0000 (16:52 -0400)
project/recrutement/admin.py

index f06e047..49978bb 100644 (file)
@@ -244,8 +244,12 @@ class OffreEmploiAdminMixin(BaseAdmin):
 
     def formfield_for_foreignkey(self, db_field, request, **kwargs):
         if db_field.name == 'lieu_affectation':
-            employe = groups.get_employe_from_user(request.user)
-            kwargs["queryset"] = Implantation.objects.filter(region=employe.implantation.region)
+            user_groupes = [g.name for g in request.user.groups.all()]
+            if not (request.user.is_superuser is True or \
+                groups.DRH_NIVEAU_1 in user_groupes or \
+                groups.DRH_NIVEAU_2 in user_groupes):
+                employe = groups.get_employe_from_user(request.user)
+                kwargs["queryset"] = Implantation.objects.filter(region=employe.implantation.region)
             return db_field.formfield(**kwargs)
         return super(OffreEmploiAdminMixin, self).formfield_for_foreignkey(db_field, request, **kwargs)