fixes
authorOlivier Larchevêque <olivier.larcheveque@auf.org>
Fri, 21 Sep 2012 15:30:52 +0000 (11:30 -0400)
committerOlivier Larchevêque <olivier.larcheveque@auf.org>
Fri, 21 Sep 2012 15:30:52 +0000 (11:30 -0400)
project/recrutement/admin.py

index 5110568..e12092c 100644 (file)
@@ -115,47 +115,50 @@ class OffreEmploiAdminMixin(BaseAdmin):
         user_groupes = [g.name for g in request.user.groups.all()]
 
         # Region
-        if 'region' in form.declared_fields:
+        region_field = None
+        if 'region' in form.declared_fields.keys():
             region_field = form.declared_fields['region']
-        else:
+        if 'region' in form.base_fields.keys():
             region_field = form.base_fields['region']
-
-        if groups.DRH_NIVEAU_1 in user_groupes or \
-           groups.DRH_NIVEAU_2 in user_groupes or \
-           groups.HAUTE_DIRECTION in user_groupes:
-            region_field.queryset = Region.objects.all()
-        else:
-            region_field.queryset = Region.objects.\
-                                    filter(id=employe.implantation.region.id)
+        if region_field:
+            if groups.DRH_NIVEAU_1 in user_groupes or \
+               groups.DRH_NIVEAU_2 in user_groupes or \
+               groups.HAUTE_DIRECTION in user_groupes:
+                region_field.queryset = Region.objects.all()
+            else:
+                region_field.queryset = Region.objects.\
+                                        filter(id=employe.implantation.region.id)
 
         # Poste
-        if 'poste' in form.declared_fields:
+        poste_field = None
+        if 'poste' in form.declared_fields.keys():
             poste_field = form.declared_fields['poste']
-        else:
+        if 'poste' in form.base_fields.keys():
             poste_field = form.base_fields['poste']
-
-        if groups.DRH_NIVEAU_1 in user_groupes or \
-           groups.DRH_NIVEAU_2 in user_groupes or \
-           groups.HAUTE_DIRECTION in user_groupes:
-            poste_field.queryset = rh.Poste.objects.all()
-        else:
-            poste_field.queryset = rh.Poste.objects.\
-                    filter(implantation__region=employe.implantation.region).\
-                    exclude(implantation__in=IMPLANTATIONS_CENTRALES)
+        if poste_field:
+            if groups.DRH_NIVEAU_1 in user_groupes or \
+               groups.DRH_NIVEAU_2 in user_groupes or \
+               groups.HAUTE_DIRECTION in user_groupes:
+                poste_field.queryset = rh.Poste.objects.all()
+            else:
+                poste_field.queryset = rh.Poste.objects.\
+                        filter(implantation__region=employe.implantation.region).\
+                        exclude(implantation__in=IMPLANTATIONS_CENTRALES)
 
         # Bureau
-        if 'bureau' in form.declared_fields:
+        bureau_field = None
+        if 'bureau' in form.declared_fields.keys():
             bureau_field = form.declared_fields['bureau']
-        else:
+        if 'bureau' in form.base_fields.keys():
             bureau_field = form.base_fields['bureau']
-
-        if groups.DRH_NIVEAU_1 in user_groupes or \
-            groups.DRH_NIVEAU_2 in user_groupes or \
-            groups.HAUTE_DIRECTION in user_groupes:
-            bureau_field.queryset = Bureau.objects.all()
-        else:
-            bureau_field.queryset = \
-                    Bureau.objects.filter(region=employe.implantation.region)
+        if bureau_field:
+            if groups.DRH_NIVEAU_1 in user_groupes or \
+                groups.DRH_NIVEAU_2 in user_groupes or \
+                groups.HAUTE_DIRECTION in user_groupes:
+                bureau_field.queryset = Bureau.objects.all()
+            else:
+                bureau_field.queryset = \
+                        Bureau.objects.filter(region=employe.implantation.region)
 
         return form
 
@@ -265,11 +268,6 @@ class ProxyOffreEmploiAdmin(OffreEmploiAdminMixin):
     def response_change(self, request, obj):
         return redirect('admin:recrutement_proxyoffreemploi_changelist')
 
-    ### Formulaire
-    def get_form(self, request, obj=None, **kwargs):
-        form = super(OffreEmploiAdmin, self).get_form(request, obj, **kwargs)
-        return form
-
     ### Permissions add, delete, change
     def has_add_permission(self, request):
         return False
@@ -604,12 +602,16 @@ class ProxyCandidatAdmin(CandidatAdminMixin):
 
     def has_change_permission(self, request, obj=None):
         if obj is not None:
-            evaluateur = Evaluateur.objects.get(user=request.user)
-            for e in obj.evaluations.all():
-                if e.evaluateur == evaluateur:
-                    return True
-
-        return not super(ProxyCandidatAdmin, self).has_change_permission(request, obj)
+            return obj in self.queryset(request)
+            #try:
+            #    evaluateur = Evaluateur.objects.get(user=request.user)
+            #    for e in obj.evaluations.all():
+            #        if e.evaluateur == evaluateur:
+            #            return True
+            #    return False
+            #except:
+            #    pass
+        return super(ProxyCandidatAdmin, self).has_change_permission(request, obj)
 
     def get_actions(self, request):
         return None