class PosteAdmin(AUFMetadataAdminMixin, ProtectRegionMixin, admin.ModelAdmin):
alphabet_filter = 'nom'
- search_fields = ('nom', 'implantation__code', 'implantation__nom', 'implantation__region__code', 'implantation__region__nom', )
- list_display = ('nom', 'implantation', 'service', 'type_poste', 'date_debut', 'date_fin', )
+ search_fields = ('nom',
+ 'implantation__code',
+ 'implantation__nom',
+ 'implantation__region__code',
+ 'implantation__region__nom',
+ )
+ list_display = ('nom',
+ '_occupe_par',
+ 'implantation',
+ 'service',
+ 'type_poste',
+ 'date_debut',
+ 'date_fin',
+ 'date_modification',
+ 'user_modification',
+ )
+ list_filter = ('service',
+ 'implantation__region',
+ 'implantation__adresse_physique_pays',
+ 'implantation',
+ )
fieldsets = AUFMetadataAdminMixin.fieldsets + (
(None, {
'fields': (('nom', 'nom_feminin'), 'implantation', 'type_poste',
DossierROInline,
PosteCommentaireInline, )
+ def _occupe_par(self, obj):
+ """Formatte la méthode Poste.occupe_par() pour l'admin"""
+ output = "VACANT"
+ employes = obj.occupe_par()
+ if employes:
+ l = []
+ for e in employes:
+ link = "<a href='%s'>%s</a>" % \
+ (reverse('admin:rh_employe_change', args=(e.id,)),
+ e)
+ l.append(link)
+ output = "\n<br />".join(l)
+ return output
+ _occupe_par.allow_tags = True
+ _occupe_par.short_description = "Occupé par"
+
def save_formset(self, request, form, formset, change):
instances = formset.save(commit=False)
for instance in instances:
representation = u'%s - %s [%s]' % (self.implantation, self.nom,
self.id)
if self.is_vacant():
- representation = representation + u' (vacant)'
+ representation = representation + u' (VACANT)'
return representation
def is_vacant(self):
- # TODO : si existe un dossier actif pour ce poste, return False
- # self.dossier_set.all() fonctionne pas
- return False
+ vacant = True
+ if self.occupe_par():
+ vacant = False
+ return vacant
+
+ def occupe_par(self):
+ """Retourne la liste d'employé occupant ce poste.
+ Généralement, retourne une liste d'un élément.
+ Si poste inoccupé, retourne liste vide.
+ """
+ return [d.employe for d in self.dossiers.filter(actif=True, supprime=False) \
+ .exclude(date_fin__lt=date.today())]
prefix_implantation = "implantation__region"
def get_regions(self):