Commit | Line | Data |
---|---|---|
df59fcab | 1 | # -*- encoding: utf-8 -*- |
2 | ||
6067184b | 3 | from django.core.urlresolvers import reverse |
4 | from django.http import HttpResponseRedirect | |
df59fcab | 5 | from django.contrib import admin |
38df74bb | 6 | from django.shortcuts import get_object_or_404 |
7 | ||
6067184b | 8 | from reversion.admin import VersionAdmin |
38df74bb | 9 | from datamaster_modeles.models import Employe, Implantation, Region |
6067184b | 10 | |
df59fcab | 11 | from recrutement.models import * |
12 | ||
38df74bb | 13 | |
d2b30f5f | 14 | class OffreEmploiAdmin(VersionAdmin): |
7f9e891e | 15 | date_hierarchy = 'date_creation' |
2f78949d | 16 | list_display = ('nom', 'resume', 'date_limite', '_candidatsList', ) |
7f9e891e | 17 | list_filter = ('region',) |
38df74bb | 18 | |
596fe324 | 19 | def _candidatsList(self, obj): |
8ea41642 | 20 | return "<a href='%s?offre_emploi__id__exact=%s'>Voir les candidats \ |
21 | </a>" % (reverse('admin:recrutement_candidat_changelist'), obj.id) | |
2f78949d | 22 | _candidatsList.allow_tags = True |
23 | _candidatsList.short_description = "Liste des candidats" | |
362a3534 | 24 | |
2f78949d | 25 | def queryset(self, request): |
26 | """ | |
8ea41642 | 27 | Spécifie un queryset limité, autrement Django exécute un |
28 | select_related() sans paramètre, ce qui a pour effet de charger tous | |
29 | les objets FK, sans limite de profondeur. Dès qu'on arrive, dans les | |
30 | modèles de Region, il existe plusieurs boucles, ce qui conduit à la | |
31 | génération d'une requête infinie. | |
2f78949d | 32 | """ |
38df74bb | 33 | user_email = request.user.email |
34 | user = get_object_or_404(Employe, courriel=user_email) | |
35 | user_implantation = user.implantation | |
8ea41642 | 36 | implantation_region = get_object_or_404(Implantation, |
37 | id=user_implantation.id) | |
38 | user_region = get_object_or_404(Region, | |
39 | id=implantation_region.region.id) | |
2f78949d | 40 | qs = self.model._default_manager.get_query_set() |
38df74bb | 41 | return qs.select_related('offre_emploi').filter(region=user_region.id) |
362a3534 | 42 | |
170c9aa2 | 43 | class CandidatPieceInline(admin.TabularInline): |
44 | model = CandidatPiece | |
45 | extra = 1 | |
46 | ||
eb579d40 | 47 | class EvaluateurInline(admin.TabularInline): |
48 | model = Evaluateur.candidats.through | |
49 | extra = 1 | |
50 | ||
d2b30f5f | 51 | class CandidatAdmin(VersionAdmin): |
7f9e891e | 52 | date_hierarchy = 'date_creation' |
8ea41642 | 53 | list_display = ('nom', 'prenom', 'offre_emploi','statut', '_actions', |
54 | 'evaluer_candidat', ) | |
55 | list_filter = ('offre_emploi', ) | |
7f9e891e | 56 | fieldsets = ( |
57 | ('Informations personnelles', { | |
58 | 'fields': ('prenom','nom','genre', 'nationalite', 'date_naissance', | |
59 | 'situation_famille', 'nombre_dependant',) | |
60 | }), | |
61 | ('Adresse', { | |
62 | 'fields': ('adresse', 'ville', 'etat_province', 'pays', ) | |
63 | }), | |
64 | ('Informations professionnelles', { | |
8ea41642 | 65 | 'fields': ('offre_emploi','niveau_diplome','employeur_actuel', |
66 | 'poste_actuel', 'domaine_professionnel',) | |
7f9e891e | 67 | }), |
68 | ('Options avancées', { | |
69 | 'classes': ('collapse',), | |
70 | 'fields': ('actif', 'statut', ) | |
71 | }), | |
72 | ) | |
170c9aa2 | 73 | inlines = [ |
74 | CandidatPieceInline, | |
eb579d40 | 75 | EvaluateurInline, |
170c9aa2 | 76 | ] |
f9983b5a | 77 | |
362a3534 | 78 | # Affecter un évaluateurs à des candidats |
79 | actions = ['affecter_candidats_evaluateur'] | |
596fe324 | 80 | def affecter_candidats_evaluateur(modeladmin, obj): |
81 | selected = obj.POST.getlist(admin.ACTION_CHECKBOX_NAME) | |
8ea41642 | 82 | return HttpResponseRedirect(reverse('affecter_evaluateurs_candidats')+ |
83 | "?ids=%s" % (",".join(selected))) | |
362a3534 | 84 | affecter_candidats_evaluateur.short_description = "Affecter evaluateur" |
85 | ||
596fe324 | 86 | def evaluer_candidat(self, obj): |
8ea41642 | 87 | return "<a href='%s?id=%s'>Évaluer le candidat \ |
88 | </a>" % (reverse('evaluer_candidat'), obj.id) | |
596fe324 | 89 | evaluer_candidat.allow_tags = True |
90 | evaluer_candidat.short_description = "Évaluer" | |
91 | ||
92 | def queryset(self, obj): | |
f9983b5a | 93 | """ |
8ea41642 | 94 | Spécifie un queryset limité, autrement Django exécute un |
95 | select_related() sans paramètre, ce qui a pour effet de charger tous | |
96 | les objets FK, sans limite de profondeur. Dès qu'on arrive, dans les | |
97 | modèles de Region, il existe plusieurs boucles, ce qui conduit à la | |
98 | génération d'une requête infinie. | |
f9983b5a OL |
99 | """ |
100 | qs = self.model._default_manager.get_query_set() | |
101 | return qs.select_related('offre_emploi') | |
df59fcab | 102 | |
596fe324 | 103 | def _actions(self, obj): |
8ea41642 | 104 | return "<a href='%s?id=%s'>Voir l'offre d'emploi</a> \ |
105 | " % (reverse('admin:recrutement_offreemploi_changelist'), | |
106 | obj.offre_emploi.id) | |
6067184b | 107 | _actions.allow_tags = True |
2f78949d | 108 | _actions.short_description = "Offre d'emploi" |
6067184b | 109 | |
2e9ee615 | 110 | class CandidatPieceAdmin(admin.ModelAdmin): |
170c9aa2 | 111 | list_display = ('nom', 'candidat', ) |
112 | ||
113 | def queryset(self, request): | |
114 | """ | |
115 | Spécifie un queryset limité, autrement Django exécute un | |
116 | select_related() sans paramètre, ce qui a pour effet de charger tous | |
117 | les objets FK, sans limite de profondeur. Dès qu'on arrive, dans les | |
118 | modèles de Region, il existe plusieurs boucles, ce qui conduit à la | |
119 | génération d'une requête infinie. | |
120 | """ | |
121 | qs = self.model._default_manager.get_query_set() | |
122 | return qs.select_related('candidat') | |
2e9ee615 | 123 | |
d2b30f5f | 124 | class EvaluateurAdmin(VersionAdmin): |
eb579d40 | 125 | fieldsets = ( |
126 | (None, {'fields': ('nom', 'prenom')}), | |
127 | (None, {'fields': ('candidats',)}), | |
128 | ) | |
4418c732 | 129 | |
d2b30f5f | 130 | class CandidatEvaluationAdmin(VersionAdmin): |
596fe324 | 131 | list_display = ('candidat', 'evaluateur', 'note', 'commentaire', 'date', ) |
132 | ||
133 | def queryset(self, obj): | |
134 | """ | |
8ea41642 | 135 | Spécifie un queryset limité, autrement Django exécute un |
136 | select_related() sans paramètre, ce qui a pour effet de charger tous | |
137 | les objets FK, sans limite de profondeur. Dès qu'on arrive, dans les | |
138 | modèles de Region, il existe plusieurs boucles, ce qui conduit à la | |
139 | génération d'une requête infinie. | |
596fe324 | 140 | """ |
141 | qs = self.model._default_manager.get_query_set() | |
142 | return qs.select_related('offre_emploi') | |
4418c732 | 143 | |
df59fcab | 144 | admin.site.register(OffreEmploi, OffreEmploiAdmin) |
145 | admin.site.register(Candidat, CandidatAdmin) | |
4418c732 | 146 | admin.site.register(CandidatPiece, CandidatPieceAdmin) |
147 | admin.site.register(Evaluateur, EvaluateurAdmin) | |
148 | admin.site.register(CandidatEvaluation, CandidatEvaluationAdmin) |