Merge branch 'dev'
authorEric Mc Sween <eric.mcsween@auf.org>
Thu, 21 Jun 2012 17:58:54 +0000 (13:58 -0400)
committerEric Mc Sween <eric.mcsween@auf.org>
Thu, 21 Jun 2012 17:58:54 +0000 (13:58 -0400)
Conflicts:
project/rh/admin.py

1  2 
project/rh/admin.py

diff --combined project/rh/admin.py
@@@ -7,6 -7,7 +7,7 @@@ from django.contrib import admi
  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
  
@@@ -18,13 -19,11 +19,11 @@@ import auf.django.references.models as 
  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 import models as rh
++from project.rh.change_list import ChangeList
  from project.rh.forms import ContratForm, AyantDroitForm, EmployeAdminForm, \
            AjaxSelect, DossierForm, ResponsableInlineForm
 -from project.rh.change_list import ChangeList
  
- from project.rh.change_list import ChangeList
  
  class BaseAdmin(admin.ModelAdmin):
  
@@@ -330,12 -329,13 +329,13 @@@ class DossierAdmin(DateRangeMixin, AUFM
          '_id',
          '_apercu',
          '_nom',
-         '_poste',
          '_employe',
+         '_poste',
+         '_region',
+         '_implantation',
          '_date_debut',
          '_date_fin',
          '_date_modification',
-         'user_modification',
          '_dae',
      )
      list_display_links = ('_nom',)
      _id.short_description = u"#"
      _id.admin_order_field = "id"
  
-     def _nom(self, obj):
-         return "%d : %s&nbsp;%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);"
      _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 -518,10 +518,10 @@@ class EmployeAdmin(DateRangeMixin, AUFM
              '_apercu',
              '_nom',
              '_dossiers_postes',
+             '_region',
+             '_implantation',
              'date_entree',
              '_date_modification',
-             'user_modification',
              )
      list_display_links = ('_nom',)
      list_filter = (
              ),
          )
  
+     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);"
      _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'):
+             link_style = u''
+             list_style = u''
+             if d.date_fin is not None and d.date_fin < datetime.date.today():
+                 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"
                             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,
-                  )
+                  d.poste.id)
  
-             # 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,
-                     )
+             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')
  
  class EmployeProxyAdmin(EmployeAdmin):
      list_display = ('_id', '_apercu', '_nom', '_organigramme')
+     list_per_page = 500
      actions = None
  
      def __init__(self, *args, **kwargs):
                          reverse('rho_employe_sans_niveau', args=(d.poste.id,)),
                          d.poste.id
                      )
-             link = u"""<li>%s - [%s] %s : %s</li>""" % (
-                     d.date_debut.year,
-                     d.poste.id,
+             link = u"""<li>%s [%s]:<br />%s</li>""" % (
                      d.poste.nom,
+                     d.poste.id,
                      organigramme
              )
              l.append(link)
@@@ -737,13 -763,13 +763,13 @@@ class PosteAdmin(DateRangeMixin, AUFMet
          '_apercu',
          '_nom',
          '_occupe_par',
+         '_region',
          '_implantation',
          '_service',
          '_responsable',
-         'date_debut',
-         'date_fin',
+         '_date_debut',
+         '_date_fin',
          '_date_modification',
-         'user_modification',
          '_dae',
          )
      list_filter = (
              '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"
      _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:
                                  <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 = ''
  
      _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)
@@@ -964,6 -1006,7 +1006,7 @@@ class ResponsableImplantationAdmin(Base
      list_filter = ('region', 'statut', )
      list_display = ('_region', '_nom', 'statut', '_responsable', )
      list_display_links = ('_nom',)
+     list_per_page = 500
      readonly_fields = ('nom', )
      search_fields = (
              'nom',