ergo UI : uniformiastion colonnes des changelists
[auf_rh_dae.git] / project / rh / admin.py
index df95a20..744306e 100644 (file)
@@ -7,6 +7,7 @@ from django.contrib import admin
 from django.conf import settings
 from django.db.models import Q, Count
 from django.template.defaultfilters import date
+from django.utils.formats import date_format
 
 from ajax_select import make_ajax_form
 
@@ -330,12 +331,13 @@ class DossierAdmin(DateRangeMixin, AUFMetadataAdminMixin,
         '_id',
         '_apercu',
         '_nom',
-        '_poste',
         '_employe',
+        '_poste',
+        '_region',
+        '_implantation',
         '_date_debut',
         '_date_fin',
         '_date_modification',
-        'user_modification',
         '_dae',
     )
     list_display_links = ('_nom',)
@@ -396,14 +398,6 @@ class DossierAdmin(DateRangeMixin, AUFMetadataAdminMixin,
     _id.short_description = u"#"
     _id.admin_order_field = "id"
 
-    def _nom(self, obj):
-        return "%d : %s %s" % (
-                        obj.date_debut.year,
-                        obj.employe.nom.upper(),
-                        obj.employe.prenom)
-    _nom.allow_tags = True
-    _nom.short_description = u"Dossier"
-
     def _apercu(self, d):
         apercu_link = u"""<a title="Aperçu du dossier"
                              onclick="return showAddAnotherPopup(this);"
@@ -417,72 +411,88 @@ class DossierAdmin(DateRangeMixin, AUFMetadataAdminMixin,
     _apercu.allow_tags = True
     _apercu.short_description = u""
 
-    def _dae(self, d):
-        apercu_link = ""
-        dossiers_dae = d.dossiers_dae.all()
-        if len(dossiers_dae) > 0:
-            dossier_dae = dossiers_dae[0]
-            apercu_link = u"""<a title="Aperçu du dossier"
-                                 onclick="return showAddAnotherPopup(this);"
-                                 href='%s'>
-                                 <img src="%simg/loupe.png" />
-                                 </a>""" % \
-                    (reverse('embauche_consulter', args=(dossier_dae.id,)),
-                     settings.STATIC_URL,
-                     )
-        return apercu_link
-    _dae.allow_tags = True
-    _dae.short_description = u"DAE"
-
-    def _date_debut(self, obj):
-        return date(obj.date_debut)
-
-    _date_debut.short_description = u'Occupation début'
-    _date_debut.admin_order_field = 'date_debut'
+    def _nom(self, obj):
+        return "Dossier"
+    _nom.allow_tags = True
+    _nom.short_description = u"Dossier"
 
-    def _date_fin(self, obj):
-        return date(obj.date_fin)
-    _date_fin.short_description = u'Occupation fin'
-    _date_fin.admin_order_field = 'date_fin'
+    def _employe(self, obj):
+        employe = obj.employe
+        view_link = reverse('employe_apercu', args=(employe.id,))
+        edit_link = reverse('admin:rh_employe_change', args=(employe.id,))
 
-    def _date_modification(self, obj):
-        return date(obj.date_modification) \
-                if obj.date_modification is not None else "(aucune)"
-    _date_modification.short_description = u'date modification'
-    _date_modification.admin_order_field = 'date_modification'
+        style = ""
+        view = u"""<a href="%s"
+                      title="Aperçu l'employé"
+                      onclick="return showAddAnotherPopup(this);">
+                      <img src="%simg/employe-apercu.png" />
+                    </a>""" % (view_link, settings.STATIC_URL,)
+        return u"""%s<a href='%s' style="%s;">%s</a>""" % \
+        (view, edit_link, style, employe)
+    _employe.allow_tags = True
+    _employe.short_description = u"Employé"
+    _employe.admin_order_field = "employe__nom"
 
     def _poste(self, dossier):
         link = u"""<a title="Aperçu du poste"
                       onclick="return showAddAnotherPopup(this);"
                       href='%s'><img src="%simg/poste-apercu.png" />
                     </a>
-                    <a href="%s" title="Modifier le poste">%s</a>""" % \
+                    <a href="%s" title="Modifier le poste">%s [%d]</a>""" % \
                 (reverse('poste_apercu', args=(dossier.poste.id,)),
                  settings.STATIC_URL,
                  reverse('admin:rh_poste_change', args=(dossier.poste.id,)),
-                 dossier.poste,
+                 dossier.poste.nom,
+                 dossier.poste.id,
                  )
         return link
     _poste.allow_tags = True
     _poste.short_description = u'Poste'
     _poste.admin_order_field = 'poste__nom'
 
-    def _employe(self, obj):
-        employe = obj.employe
-        view_link = reverse('employe_apercu', args=(employe.id,))
-        edit_link = reverse('admin:rh_employe_change', args=(employe.id,))
+    def _region(self, obj):
+        return obj.poste.implantation.region.code
+    _region.short_description = u"Région"
+    _region.admin_order_field = 'poste__implantation__region__code'
 
-        style = ""
-        view = u"""<a href="%s"
-                      title="Aperçu l'employé"
-                      onclick="return showAddAnotherPopup(this);">
-                      <img src="%simg/employe-apercu.png" />
-                    </a>""" % (view_link, settings.STATIC_URL,)
-        return u"""%s<a href='%s' style="%s;">%s</a>""" % \
-        (view, edit_link, style, employe)
-    _employe.allow_tags = True
-    _employe.short_description = u"Employé"
-    _employe.admin_order_field = "employe__nom"
+    def _implantation(self, obj):
+        return obj.poste.implantation.nom
+    _implantation.short_description = u"Implantation"
+    _implantation.admin_order_field = 'poste__implantation__nom'
+
+    def _date_debut(self, obj):
+        return date(obj.date_debut)
+
+    _date_debut.short_description = u'Début'
+    _date_debut.admin_order_field = 'date_debut'
+
+    def _date_fin(self, obj):
+        return date(obj.date_fin)
+    _date_fin.short_description = u'Fin'
+    _date_fin.admin_order_field = 'date_fin'
+
+    def _date_modification(self, obj):
+        return date(obj.date_modification) \
+                if obj.date_modification is not None else "(aucune)"
+    _date_modification.short_description = u'date modification'
+    _date_modification.admin_order_field = 'date_modification'
+
+    def _dae(self, d):
+        apercu_link = ""
+        dossiers_dae = d.dossiers_dae.all()
+        if len(dossiers_dae) > 0:
+            dossier_dae = dossiers_dae[0]
+            apercu_link = u"""<a title="Aperçu du dossier"
+                                 onclick="return showAddAnotherPopup(this);"
+                                 href='%s'>
+                                 <img src="%simg/loupe.png" />
+                                 </a>""" % \
+                    (reverse('embauche_consulter', args=(dossier_dae.id,)),
+                     settings.STATIC_URL,
+                     )
+        return apercu_link
+    _dae.allow_tags = True
+    _dae.short_description = u"DAE"
 
     def save_formset(self, request, form, formset, change):
         instances = formset.save(commit=False)
@@ -510,9 +520,10 @@ class EmployeAdmin(DateRangeMixin, AUFMetadataAdminMixin,
             '_apercu',
             '_nom',
             '_dossiers_postes',
+            '_region',
+            '_implantation',
             'date_entree',
             '_date_modification',
-            'user_modification',
             )
     list_display_links = ('_nom',)
     list_filter = (
@@ -547,6 +558,11 @@ class EmployeAdmin(DateRangeMixin, AUFMetadataAdminMixin,
             ),
         )
 
+    def _id(self, obj):
+        return obj.id
+    _id.short_description = u"#"
+    _id.admin_order_field = "id"
+
     def _apercu(self, obj):
         return u"""<a title="Aperçu de l'employé"
                       onclick="return showAddAnotherPopup(this);"
@@ -565,31 +581,47 @@ class EmployeAdmin(DateRangeMixin, AUFMetadataAdminMixin,
     _nom.short_description = u"Employé"
     _nom.admin_order_field = "nom"
 
-    def _id(self, obj):
-        return obj.id
-    _id.short_description = u"#"
-    _id.admin_order_field = "id"
+    def _region(self, obj):
+        try:
+            d = rh.Dossier.objects.filter(employe=obj.id, principal=True)[0]
+            region = d.poste.implantation.region.code
+        except:
+            region = None
+        return region
+    _region.short_description = u"Région"
 
-    def _date_modification(self, obj):
-        return date(obj.date_modification) \
-                if obj.date_modification is not None else "(aucune)"
-    _date_modification.short_description = u'date modification'
-    _date_modification.admin_order_field = 'date_modification'
+    def _implantation(self, obj):
+        try:
+            d = rh.Dossier.objects.filter(employe=obj.id, principal=True)[0]
+            implantation = d.poste.implantation.nom
+        except:
+            implantation = None
+        return implantation
+    _implantation.short_description = u"Implantation"
 
     def _dossiers_postes(self, obj):
         l = []
         for d in obj.rh_dossiers.all().order_by('-date_debut'):
+            actif = True
+            link_style = u''
+            list_style = u''
+            if d.date_fin is not None and d.date_fin < datetime.date.today():
+                actif = False
+                link_style = u' style="color:#666;"'
+                list_style = u' style="color:grey;"'
+            
             dossier = u"""<a title="Aperçu du dossier"
                              href="%s"
                              onclick="return showAddAnotherPopup(this);"
                              title="Aperçu du dossier">
                              <img src="%simg/dossier-apercu.png" />
                           </a>
-                          <a href="%s">Dossier</a>
+                          <a href="%s"%s>Dossier</a>
                           &nbsp;""" % \
                 (reverse('dossier_apercu', args=(d.id,)),
                  settings.STATIC_URL,
-                 reverse('admin:rh_dossier_change', args=(d.id,)))
+                 reverse('admin:rh_dossier_change', args=(d.id,)),
+                 link_style,)
 
             poste = u"""<a title="Aperçu du poste"
                            href="%s"
@@ -597,31 +629,29 @@ class EmployeAdmin(DateRangeMixin, AUFMetadataAdminMixin,
                            title="Aperçu du poste">
                            <img src="%simg/poste-apercu.png" />
                         </a>
-                        <a href="%s">Poste</a>
+                        <a href="%s"%s>%s [%d]</a>
                         &nbsp;""" % \
                 (reverse('poste_apercu', args=(d.poste.id,)),
                  settings.STATIC_URL,
-                 reverse('admin:rh_poste_change', args=(d.poste.id,)))
-            link = u"""<li>%s %s - %s : [%s] %s</li>""" % \
-                (dossier, poste,
-                 d.date_debut.year,
-                 d.poste.id,
+                 reverse('admin:rh_poste_change', args=(d.poste.id,)),
+                 link_style,
                  d.poste.nom,
-                 )
-
-            # Dossier terminé en gris non cliquable
-            if d.date_fin is not None and d.date_fin < datetime.date.today():
-                link = u"""<li style="color: grey">%s : [%s] %s</li>""" % \
-                    (d.date_debut.year,
-                     d.poste.id,
-                     d.poste.nom,
-                    )
+                 d.poste.id)
+                            
+            link = u"""<li%s>%s %s</li>""" % \
+                (list_style, dossier, poste)
 
             l.append(link)
         return "<ul>%s</ul>" % "\n".join(l)
     _dossiers_postes.allow_tags = True
     _dossiers_postes.short_description = u"Dossiers et postes"
 
+    def _date_modification(self, obj):
+        return date(obj.date_modification) \
+                if obj.date_modification is not None else "(aucune)"
+    _date_modification.short_description = u'date modification'
+    _date_modification.admin_order_field = 'date_modification'
+
     def queryset(self, request):
         qs = super(EmployeAdmin, self).queryset(request)
         return qs.select_related(depth=1).order_by('nom')
@@ -737,13 +767,13 @@ class PosteAdmin(DateRangeMixin, AUFMetadataAdminMixin,
         '_apercu',
         '_nom',
         '_occupe_par',
+        '_region',
         '_implantation',
         '_service',
         '_responsable',
-        'date_debut',
-        'date_fin',
+        '_date_debut',
+        '_date_fin',
         '_date_modification',
-        'user_modification',
         '_dae',
         )
     list_filter = (
@@ -819,6 +849,11 @@ class PosteAdmin(DateRangeMixin, AUFMetadataAdminMixin,
             'service__isnull', 'vacant__exact', 'vacant__isnull',
         ) or super(PosteAdmin, self).lookup_allowed(key, value)
 
+    def _id(self, obj):
+        return "%s" % obj.id
+    _id.short_description = '#'
+    _id.admin_order_field = 'id'
+
     def _apercu(self, poste):
         view_link = u"""<a onclick="return showAddAnotherPopup(this);"
                            title="Aperçu du poste"
@@ -831,25 +866,48 @@ class PosteAdmin(DateRangeMixin, AUFMetadataAdminMixin,
     _apercu.allow_tags = True
     _apercu.short_description = ''
 
-    def _dae(self, poste):
-        apercu_link = ""
-        postes_dae = poste.postes_dae.all()
-        if len(postes_dae) > 0:
-            poste_dae = postes_dae[0]
-            apercu_link = \
-                    u'<a title="Aperçu du dossier" href="%s" ' \
-                    u'onclick="return showAddAnotherPopup(this);">' \
-                    u'<img src="%simg/loupe.png" /></a>' % (reverse(
-                        'poste_consulter', args=("dae-%s" % poste_dae.id,)
-                    ), settings.STATIC_URL)
-        return apercu_link
-    _dae.allow_tags = True
-    _dae.short_description = u"DAE"
+    def _nom(self, poste):
+        return """<a href="%s">%s</a>""" % \
+                (reverse('admin:rh_poste_change', args=(poste.id,)),
+                poste.nom)
+    _nom.allow_tags = True
+    _nom.short_description = u'Poste'
+    _nom.admin_order_field = 'nom'
 
-    def _id(self, obj):
-        return "%s" % obj.id
-    _id.short_description = '#'
-    _id.admin_order_field = 'id'
+    def _occupe_par(self, obj):
+        """Formatte la méthode Poste.occupe_par() pour l'admin"""
+        output = u"Vacant"
+        if obj.date_fin is not None and obj.date_fin < datetime.date.today():
+            return u"s/o"
+        employes = obj.occupe_par()
+        if employes:
+            l = []
+            for e in employes:
+                link = u"""<a href='%s'
+                              title='Aperçu de l\'employé'
+                              onclick='return showAddAnotherPopup(this)'>
+                              <img src='%simg/employe-apercu.png' />
+                            </a>
+                            <a href='%s'>%s</a>""" % \
+                     (reverse('employe_apercu', args=(e.id,)),
+                     settings.STATIC_URL,
+                     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 _region(self, poste):
+        return poste.implantation.region.code
+    _region.short_description = 'Région'
+    _region.admin_order_field = 'implantation__region__code'
+
+    def _implantation(self, poste):
+        return poste.implantation.nom
+    _implantation.short_description = 'Implantation'
+    _implantation.admin_order_field = 'implantation'
 
     def _service(self, obj):
         if obj.service.supprime:
@@ -866,12 +924,13 @@ class PosteAdmin(DateRangeMixin, AUFMetadataAdminMixin,
                                 <img src="%simg/poste-apercu.png"
                                      title="Aperçu du poste" />
                               </a>
-                              <a href="%s">%s</a>
+                              <a href="%s">%s [%d]</a>
                               <br />""" % \
                 (reverse('poste_apercu', args=(obj.responsable.id,)),
                 settings.STATIC_URL,
                 reverse('admin:rh_poste_change', args=(obj.responsable.id,)),
-                obj.responsable.nom)
+                obj.responsable.nom,
+                obj.responsable.id)
         except:
             responsable = ''
 
@@ -896,48 +955,35 @@ class PosteAdmin(DateRangeMixin, AUFMetadataAdminMixin,
     _responsable.short_description = 'Responsable'
     _responsable.allow_tags = True
 
-    def _implantation(self, poste):
-        return poste.implantation.nom
-    _implantation.short_description = 'Implantation'
-    _implantation.admin_order_field = 'implantation'
+    def _date_debut(self, obj):
+        return date_format(obj.date_debut)
+    _date_debut.short_description = u'Début'
+    _date_debut.admin_order_field = 'date_debut'
 
-    def _nom(self, poste):
-        return """<a href="%s">%s</a>""" % \
-                (reverse('admin:rh_poste_change', args=(poste.id,)),
-                poste.nom)
-    _nom.allow_tags = True
-    _nom.short_description = u'Poste'
-    _nom.admin_order_field = 'nom'
+    def _date_fin(self, obj):
+        return date_format(obj.date_fin)
+    _date_fin.short_description = u'Fin'
+    _date_fin.admin_order_field = 'date_fin'
 
     def _date_modification(self, obj):
         return date(obj.date_modification)
     _date_modification.short_description = u'date modification'
     _date_modification.admin_order_field = 'date_modification'
 
-    def _occupe_par(self, obj):
-        """Formatte la méthode Poste.occupe_par() pour l'admin"""
-        output = u"Vacant"
-        if obj.date_fin is not None and obj.date_fin < datetime.date.today():
-            return u"s/o"
-        employes = obj.occupe_par()
-        if employes:
-            l = []
-            for e in employes:
-                link = u"""<a href='%s'
-                              title='Aperçu de l\'employé'
-                              onclick='return showAddAnotherPopup(this)'>
-                              <img src='%simg/employe-apercu.png' />
-                            </a>
-                            <a href='%s'>%s</a>""" % \
-                     (reverse('employe_apercu', args=(e.id,)),
-                     settings.STATIC_URL,
-                     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 _dae(self, poste):
+        apercu_link = ""
+        postes_dae = poste.postes_dae.all()
+        if len(postes_dae) > 0:
+            poste_dae = postes_dae[0]
+            apercu_link = \
+                    u'<a title="Aperçu du dossier" href="%s" ' \
+                    u'onclick="return showAddAnotherPopup(this);">' \
+                    u'<img src="%simg/loupe.png" /></a>' % (reverse(
+                        'poste_consulter', args=("dae-%s" % poste_dae.id,)
+                    ), settings.STATIC_URL)
+        return apercu_link
+    _dae.allow_tags = True
+    _dae.short_description = u"DAE"
 
     def save_formset(self, request, form, formset, change):
         instances = formset.save(commit=False)