[#2658] Intégré django-reversion à l'app rh
[auf_rh_dae.git] / project / rh / admin.py
index df95a20..8e10643 100644 (file)
@@ -2,27 +2,24 @@
 
 import datetime
 
+import reversion
+from ajax_select import make_ajax_form
+from auf.django.metadata.admin import \
+        AUFMetadataAdminMixin, AUFMetadataInlineAdminMixin, \
+        AUF_METADATA_READONLY_FIELDS
+from auf.django.references import models as ref
 from django.core.urlresolvers import reverse
 from django.contrib import admin
 from django.conf import settings
 from django.db.models import Q, Count
 from django.template.defaultfilters import date
 
-from ajax_select import make_ajax_form
-
-from auf.django.metadata.admin import \
-        AUFMetadataAdminMixin, AUFMetadataInlineAdminMixin, \
-        AUF_METADATA_READONLY_FIELDS
-import auf.django.references.models as ref
-
 from project.decorators import in_drh_or_admin
 from project.groups import grp_correspondants_rh
 from project.groups import get_employe_from_user
-
-import project.rh.models as rh
 from project.rh.forms import ContratForm, AyantDroitForm, EmployeAdminForm, \
           AjaxSelect, DossierForm, ResponsableInlineForm
-        
+from project.rh import models as rh
 from project.rh.change_list import ChangeList
 
 
@@ -273,7 +270,8 @@ class PosteComparaisonInline(AUFMetadataInlineAdminMixin, admin.TabularInline):
     model = rh.PosteComparaison
 
 
-class ClassementAdmin(AUFMetadataAdminMixin, BaseAdmin):
+class ClassementAdmin(AUFMetadataAdminMixin, BaseAdmin,
+                      reversion.VersionAdmin):
     list_display = ('_classement', '_date_modification', 'user_modification', )
     fieldsets = AUFMetadataAdminMixin.fieldsets + (
         (None, {
@@ -291,7 +289,12 @@ class ClassementAdmin(AUFMetadataAdminMixin, BaseAdmin):
     _date_modification.admin_order_field = 'date_modification'
 
 
-class DeviseAdmin(AUFMetadataAdminMixin, BaseAdmin, ArchiveMixin):
+class CommentaireAdmin(reversion.VersionAdmin, BaseAdmin):
+    pass
+
+
+class DeviseAdmin(AUFMetadataAdminMixin, reversion.VersionAdmin,
+                  ArchiveMixin, BaseAdmin):
     list_display = (
             'code',
             'nom',
@@ -314,7 +317,8 @@ class DeviseAdmin(AUFMetadataAdminMixin, BaseAdmin, ArchiveMixin):
 
 
 class DossierAdmin(DateRangeMixin, AUFMetadataAdminMixin,
-                   ProtectRegionMixin, BaseAdmin, AjaxSelect):
+                   ProtectRegionMixin, BaseAdmin, AjaxSelect,
+                   reversion.VersionAdmin):
     alphabet_filter = 'employe__nom'
     search_fields = (
         'id',
@@ -493,8 +497,8 @@ class DossierAdmin(DateRangeMixin, AUFMetadataAdminMixin,
             instance.save()
 
 
-class EmployeAdmin(DateRangeMixin, AUFMetadataAdminMixin,
-                   ProtectRegionMixin, BaseAdmin):
+class EmployeAdminMixin(DateRangeMixin, AUFMetadataAdminMixin,
+                        ProtectRegionMixin, BaseAdmin):
     prefixe_recherche_temporelle = "rh_dossiers__"
     alphabet_filter = 'nom'
     DEFAULT_ALPHABET = u'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
@@ -635,7 +639,11 @@ class EmployeAdmin(DateRangeMixin, AUFMetadataAdminMixin,
             instance.save()
 
 
-class EmployeProxyAdmin(EmployeAdmin):
+class EmployeAdmin(reversion.VersionAdmin, EmployeAdminMixin):
+    pass
+
+
+class EmployeProxyAdmin(admin.ModelAdmin, EmployeAdminMixin):
     list_display = ('_id', '_apercu', '_nom', '_organigramme')
     actions = None
 
@@ -677,7 +685,8 @@ class EmployeProxyAdmin(EmployeAdmin):
     _organigramme.short_description = "Organigramme"
 
 
-class CategorieEmploiAdmin(AUFMetadataAdminMixin, BaseAdmin):
+class CategorieEmploiAdmin(AUFMetadataAdminMixin, reversion.VersionAdmin,
+                           BaseAdmin):
     list_display = ('nom', '_date_modification', 'user_modification', )
     inlines = (TypePosteInline,)
     fieldsets = AUFMetadataAdminMixin.fieldsets + (
@@ -690,7 +699,8 @@ class CategorieEmploiAdmin(AUFMetadataAdminMixin, BaseAdmin):
     _date_modification.admin_order_field = 'date_modification'
 
 
-class OrganismeBstgAdmin(AUFMetadataAdminMixin, BaseAdmin):
+class OrganismeBstgAdmin(AUFMetadataAdminMixin, reversion.VersionAdmin,
+                         BaseAdmin):
     search_fields = ('nom',)
     list_display = (
             'nom',
@@ -712,8 +722,8 @@ class OrganismeBstgAdmin(AUFMetadataAdminMixin, BaseAdmin):
     _date_modification.admin_order_field = 'date_modification'
 
 
-class PosteAdmin(DateRangeMixin, AUFMetadataAdminMixin,
-                 ProtectRegionMixin, BaseAdmin, AjaxSelect):
+class PosteAdmin(DateRangeMixin, AUFMetadataAdminMixin, ProtectRegionMixin,
+                 reversion.VersionAdmin, AjaxSelect, BaseAdmin):
     form = make_ajax_form(rh.Poste, {
         'implantation': 'implantations',
         'type_poste': 'typepostes',
@@ -876,7 +886,8 @@ class PosteAdmin(DateRangeMixin, AUFMetadataAdminMixin,
             responsable = ''
 
         try:
-            dossier = obj.responsable.rh_dossiers.all().order_by('-date_debut')[0]
+            dossier = obj.responsable.rh_dossiers.all() \
+                    .order_by('-date_debut')[0]
             employe_id = dossier.employe.id
             employe_html = u"""<br />
                     <a href="%s"
@@ -971,17 +982,17 @@ class ResponsableImplantationAdmin(BaseAdmin):
             'responsable__employe__prenom',
             )
     ordering = ('nom',)
-    
+
     def _region(self, obj):
         return obj.region.code
     _region.short_description = u"Région"
     _region.admin_order_field = 'region__code'
-    
+
     def _nom(self, obj):
         return obj.nom
     _nom.short_description = u"Implantation"
     _nom.admin_order_field = 'nom'
-    
+
     def _responsable(self, obj):
         try:
             employe = obj.responsable.employe
@@ -1011,7 +1022,7 @@ class ResponsableImplantationAdmin(BaseAdmin):
         return False
 
 
-class ServiceAdmin(AUFMetadataAdminMixin, BaseAdmin, ArchiveMixin):
+class ServiceAdminMixin(AUFMetadataAdminMixin, ArchiveMixin, BaseAdmin):
     list_display = (
             'nom',
             '_archive',
@@ -1032,7 +1043,11 @@ class ServiceAdmin(AUFMetadataAdminMixin, BaseAdmin, ArchiveMixin):
     _date_modification.admin_order_field = 'date_modification'
 
 
-class ServiceProxyAdmin(ServiceAdmin):
+class ServiceAdmin(reversion.VersionAdmin, ServiceAdminMixin):
+    pass
+
+
+class ServiceProxyAdmin(admin.ModelAdmin, ServiceAdminMixin):
     list_display = ('nom', '_organigramme', '_archive', )
     actions = None
 
@@ -1058,7 +1073,7 @@ class ServiceProxyAdmin(ServiceAdmin):
     _organigramme.short_description = "Organigramme"
 
 
-class StatutAdmin(AUFMetadataAdminMixin, BaseAdmin):
+class StatutAdmin(AUFMetadataAdminMixin, reversion.VersionAdmin, BaseAdmin):
     list_display = ('code', 'nom', '_date_modification', 'user_modification', )
     fieldsets = AUFMetadataAdminMixin.fieldsets + (
         (None, {
@@ -1073,7 +1088,7 @@ class StatutAdmin(AUFMetadataAdminMixin, BaseAdmin):
     _date_modification.admin_order_field = 'date_modification'
 
 
-class TauxChangeAdmin(BaseAdmin):
+class TauxChangeAdmin(reversion.VersionAdmin, BaseAdmin):
     list_display = (
             'taux',
             'devise',
@@ -1095,7 +1110,7 @@ class TauxChangeAdmin(BaseAdmin):
     _date_modification.admin_order_field = 'date_modification'
 
 
-class TypeContratAdmin(BaseAdmin):
+class TypeContratAdmin(reversion.VersionAdmin, BaseAdmin):
     list_display = (
             'nom',
             'nom_long',
@@ -1115,7 +1130,8 @@ class TypeContratAdmin(BaseAdmin):
     _date_modification.admin_order_field = 'date_modification'
 
 
-class TypePosteAdmin(AUFMetadataAdminMixin, BaseAdmin):
+class TypePosteAdmin(AUFMetadataAdminMixin, reversion.VersionAdmin,
+                     BaseAdmin):
     search_fields = ('nom', 'nom_feminin', )
     list_display = (
             'nom',
@@ -1143,8 +1159,8 @@ class TypePosteAdmin(AUFMetadataAdminMixin, BaseAdmin):
     _date_modification.admin_order_field = 'date_modification'
 
 
-class TypeRemunerationAdmin(AUFMetadataAdminMixin, BaseAdmin,
-                            ArchiveMixin):
+class TypeRemunerationAdmin(AUFMetadataAdminMixin, reversion.VersionAdmin,
+                            ArchiveMixin, BaseAdmin):
     list_display = (
             'nom',
             'type_paiement',
@@ -1165,7 +1181,8 @@ class TypeRemunerationAdmin(AUFMetadataAdminMixin, BaseAdmin,
     _date_modification.admin_order_field = 'date_modification'
 
 
-class TypeRevalorisationAdmin(AUFMetadataAdminMixin, BaseAdmin):
+class TypeRevalorisationAdmin(AUFMetadataAdminMixin, reversion.VersionAdmin,
+                              BaseAdmin):
     list_display = ('nom', '_date_modification', 'user_modification', )
     fieldsets = AUFMetadataAdminMixin.fieldsets + (
         (None, {'fields': ('nom', )}),
@@ -1178,7 +1195,8 @@ class TypeRevalorisationAdmin(AUFMetadataAdminMixin, BaseAdmin):
     _date_modification.admin_order_field = 'date_modification'
 
 
-class ValeurPointAdmin(AUFMetadataAdminMixin, BaseAdmin):
+class ValeurPointAdmin(AUFMetadataAdminMixin, reversion.VersionAdmin,
+                       BaseAdmin):
     list_display = (
             '_devise_code',
             '_devise_nom',