- return False
-
-class ProxyOffreEmploiAdmin(OffreEmploiAdmin):
- list_display = ('nom', 'date_limite', 'region', 'statut',
- 'est_affiche')
- readonly_fields = ('description', 'bureau', 'duree_affectation',
- 'renumeration', 'debut_affectation', 'lieu_affectation',
- 'nom', 'resume', 'date_limite', 'region', 'poste')
+
+ if obj is not None:
+ employe = groups.get_employe_from_user(request.user)
+ if (groups.DIRECTEUR_DE_BUREAU in user_groupes or \
+ groups.ADMINISTRATEURS in user_groupes) and (
+ employe.implantation.region == obj.lieu_affectation.region):
+ return True
+ else:
+ if groups.DIRECTEUR_DE_BUREAU in user_groupes or \
+ groups.ADMINISTRATEURS in user_groupes:
+ return True
+
+
+ return False
+
+ def formfield_for_foreignkey(self, db_field, request, **kwargs):
+ if db_field.name == 'lieu_affectation':
+ 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)
+
+
+class OffreEmploiAdmin(VersionAdmin, OffreEmploiAdminMixin):
+ pass
+
+
+class ProxyOffreEmploiAdmin(OffreEmploiAdminMixin):
+ list_display = (
+ 'nom', 'date_limite', 'region', 'statut', 'est_affiche'
+ )
+ readonly_fields = (
+ 'description', 'bureau', 'duree_affectation', 'renumeration',
+ 'debut_affectation', 'lieu_affectation', 'nom', 'resume',
+ 'date_limite', 'region', 'poste'
+ )