PEP8
authorEric Mc Sween <eric.mcsween@auf.org>
Fri, 18 May 2012 20:57:49 +0000 (16:57 -0400)
committerEric Mc Sween <eric.mcsween@auf.org>
Fri, 18 May 2012 21:03:41 +0000 (17:03 -0400)
project/dashboard.py
project/rh/admin.py

index bad4122..70f8d45 100644 (file)
@@ -12,10 +12,8 @@ And to activate the app index dashboard::
     ADMIN_TOOLS_APP_INDEX_DASHBOARD = 'SIGMA.dashboard.CustomAppIndexDashboard'
 """
 
-from django.utils.translation import ugettext_lazy as _
-
 from admin_tools.dashboard import modules, Dashboard, AppIndexDashboard
-from admin_tools.utils import get_admin_site_name
+from django.utils.translation import ugettext_lazy as _
 
 
 class CustomIndexDashboard(Dashboard):
@@ -28,14 +26,14 @@ class CustomIndexDashboard(Dashboard):
         self.children.append(modules.AppList(
             _('Applications'),
             models=(
-            'project.dae.models.*',
-            'project.recrutement.models.*',
-            'project.rh.models.AyantDroit',
-            'project.rh.models.Dossier',
-            'project.rh.models.DossierInactif',
-            'project.rh.models.Employe',
-            'project.rh.models.EmployeInactif',
-            'project.rh.models.Poste',
+                'project.dae.models.*',
+                'project.recrutement.models.*',
+                'project.rh.models.AyantDroit',
+                'project.rh.models.Dossier',
+                'project.rh.models.DossierInactif',
+                'project.rh.models.Employe',
+                'project.rh.models.EmployeInactif',
+                'project.rh.models.Poste',
             ),
         ))
 
@@ -43,19 +41,19 @@ class CustomIndexDashboard(Dashboard):
         self.children.append(modules.AppList(
             _('Configuration'),
             models=(
-            'project.rh.models.Classement',
-            'project.rh.models.Devise',
-            'project.rh.models.CategorieEmploi',
-            'project.rh.models.OrganismeBstg',
-            'project.rh.models.Responsable',
-            'project.rh.models.Service',
-            'project.rh.models.Statut',
-            'project.rh.models.TauxChange',
-            'project.rh.models.TypeContrat',
-            'project.rh.models.TypePoste',
-            'project.rh.models.TypeRevalorisation',
-            'project.rh.models.TypeRemuneration',
-            'project.rh.models.ValeurPoint',
+                'project.rh.models.Classement',
+                'project.rh.models.Devise',
+                'project.rh.models.CategorieEmploi',
+                'project.rh.models.OrganismeBstg',
+                'project.rh.models.Responsable',
+                'project.rh.models.Service',
+                'project.rh.models.Statut',
+                'project.rh.models.TauxChange',
+                'project.rh.models.TypeContrat',
+                'project.rh.models.TypePoste',
+                'project.rh.models.TypeRevalorisation',
+                'project.rh.models.TypeRemuneration',
+                'project.rh.models.ValeurPoint',
             ),
             exclude=('django.contrib.*',),
         ))
@@ -64,7 +62,7 @@ class CustomIndexDashboard(Dashboard):
         self.children.append(modules.AppList(
             _(u'Inter-systèmes'),
             models=(
-            'project.rh.models.ResponsableImplantation',
+                'project.rh.models.ResponsableImplantation',
             ),
         ))
 
@@ -72,13 +70,10 @@ class CustomIndexDashboard(Dashboard):
         self.children.append(modules.AppList(
             _('Administration'),
             models=(
-            'django.contrib.*',
+                'django.contrib.*',
             ),
         ))
 
-        # append a recent actions module
-        #self.children.append(modules.RecentActions(_('Recent Actions'), 5))
-
 
 class CustomAppIndexDashboard(AppIndexDashboard):
     """
@@ -98,12 +93,7 @@ class CustomAppIndexDashboard(AppIndexDashboard):
         if self.app_title != 'Rh':
             # append a model list module and a recent actions module
             self.children += [
-                modules.ModelList(self.app_title,self.models),
-                #modules.RecentActions(
-                #    _('Recent Actions'),
-                #    include_list=self.get_app_content_types(),
-                #    limit=5
-                #)
+                modules.ModelList(self.app_title, self.models),
             ]
 
             return
@@ -112,12 +102,12 @@ class CustomAppIndexDashboard(AppIndexDashboard):
         self.children.append(modules.AppList(
             _('Application'),
             models=(
-            'project.rh.models.AyantDroit',
-            'project.rh.models.Dossier',
-            'project.rh.models.DossierInactif',
-            'project.rh.models.Employe',
-            'project.rh.models.EmployeInactif',
-            'project.rh.models.Poste',
+                'project.rh.models.AyantDroit',
+                'project.rh.models.Dossier',
+                'project.rh.models.DossierInactif',
+                'project.rh.models.Employe',
+                'project.rh.models.EmployeInactif',
+                'project.rh.models.Poste',
             ),
         ))
 
@@ -125,19 +115,19 @@ class CustomAppIndexDashboard(AppIndexDashboard):
         self.children.append(modules.AppList(
             _('Configuration'),
             models=(
-            'project.rh.models.Classement',
-            'project.rh.models.Devise',
-            'project.rh.models.CategorieEmploi',
-            'project.rh.models.OrganismeBstg',
-            'project.rh.models.Responsable',
-            'project.rh.models.Service',
-            'project.rh.models.Statut',
-            'project.rh.models.TauxChange',
-            'project.rh.models.TypeContrat',
-            'project.rh.models.TypePoste',
-            'project.rh.models.TypeRevalorisation',
-            'project.rh.models.TypeRemuneration',
-            'project.rh.models.ValeurPoint',
+                'project.rh.models.Classement',
+                'project.rh.models.Devise',
+                'project.rh.models.CategorieEmploi',
+                'project.rh.models.OrganismeBstg',
+                'project.rh.models.Responsable',
+                'project.rh.models.Service',
+                'project.rh.models.Statut',
+                'project.rh.models.TauxChange',
+                'project.rh.models.TypeContrat',
+                'project.rh.models.TypePoste',
+                'project.rh.models.TypeRevalorisation',
+                'project.rh.models.TypeRemuneration',
+                'project.rh.models.ValeurPoint',
             ),
         ))
 
@@ -145,13 +135,6 @@ class CustomAppIndexDashboard(AppIndexDashboard):
         self.children.append(modules.AppList(
             _(u'Inter-systèmes'),
             models=(
-            'project.rh.models.ResponsableImplantation',
+                'project.rh.models.ResponsableImplantation',
             ),
         ))
-
-        # append a recent actions module
-        #self.children.append(modules.RecentActions(
-        #    _('Recent Actions'),
-        #    include_list=self.get_app_content_types(),
-        #    limit=5
-        #))
index 301325e..78d1689 100644 (file)
@@ -2,24 +2,25 @@
 
 import datetime
 
+from ajax_select import make_ajax_form
+from auf.django.metadata.admin import \
+        AUFMetadataAdminMixin, AUFMetadataInlineAdminMixin, \
+        AUF_METADATA_READONLY_FIELDS
 from django.core.urlresolvers import reverse
 from django.contrib import admin
 from django.conf import settings
 from django.db.models import Q
 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
-from forms import ContratForm, AyantDroitForm, EmployeAdminForm, AjaxSelect, \
-DossierForm
-from dae import models as dae
+
+import auf.django.references.models as ref
+import models as rh
+from forms import \
+        ContratForm, AyantDroitForm, EmployeAdminForm, AjaxSelect, DossierForm
 from dae.utils import get_employe_from_user
 from change_list import ChangeList
 from groups import grp_correspondants_rh
 from decorators import in_drh_or_admin
-import models as rh
-import auf.django.references.models as ref
+
 
 class ArchiveMixin(object):
     """
@@ -38,6 +39,7 @@ class ArchiveMixin(object):
     _archive.short_description = u'Archivé'
     _archive.admin_order_field = 'archive'
 
+
 class RegionProxy(ref.Region):
     """ Proxy utilisé pour les organigrammes par région """
     class Meta:
@@ -629,15 +631,28 @@ class EmployeProxyAdmin(EmployeAdmin):
 
     def _organigramme(self, obj):
         l = []
-        for d in rh.Dossier.objects.filter((Q(date_fin__gt=datetime.date.today()) | Q(date_fin=None)) & (Q(date_debut__lt=datetime.date.today()) | Q(date_debut=None)) ).filter(employe=obj.id).all():
-            organigramme = u"""Organigramme, niveau: <input type="text" id="level_%s" style="width:30px;height:15px;" /> <input type="button" value="Générer" onclick="window.location='%s'+document.getElementById('level_%s').value" />""" % \
-                    (d.poste.id, 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,
-                 d.poste.nom,
-                 organigramme
-                 )
+        for d in rh.Dossier.objects.filter(
+            Q(date_fin__gt=datetime.date.today()) | Q(date_fin=None),
+            Q(date_debut__lt=datetime.date.today()) | Q(date_debut=None),
+            employe=obj.id
+        ):
+            organigramme = \
+                    u'Organigramme, niveau: ' \
+                    u'<input type="text" id="level_%s" ' \
+                    u'style="width:30px;height:15px;" /> ' \
+                    u'<input type="button" value="Générer" ' \
+                    u"""onclick="window.location='%s' + """ \
+                    u"""document.getElementById('level_%s').value" />""" % (
+                        d.poste.id,
+                        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,
+                    d.poste.nom,
+                    organigramme
+            )
             l.append(link)
         return "<ul>%s</ul>" % "\n".join(l)
 
@@ -858,8 +873,9 @@ class PosteAdmin(DateRangeMixin, AUFMetadataAdminMixin, \
             responsable = ''
 
         try:
+            employe = obj.responsable.rh_dossiers.all()[0]
             employe_id = obj.responsable.rh_dossiers.all()[0].id
-            employe = u"""<br />
+            employe_html = u"""<br />
                     <a href="%s"
                        onclick="return showAddAnotherPopup(this)">
                        <img src="%simg/loupe.png"
@@ -871,9 +887,9 @@ class PosteAdmin(DateRangeMixin, AUFMetadataAdminMixin, \
                      reverse('admin:rh_employe_change', args=(employe_id,)),
                      employe)
         except:
-            employe = ""
+            employe_html = ""
 
-        return "%s %s" % (responsable, employe)
+        return "%s %s" % (responsable, employe_html)
     _responsable.short_description = 'Responsable'
     _responsable.allow_tags = True
 
@@ -944,7 +960,8 @@ class RemunerationAdmin(admin.ModelAdmin):
 class ResponsableInline(admin.TabularInline):
     model = rh.ResponsableImplantation
     extra = 0
-    fk_name  = "implantation"
+    fk_name = "implantation"
+
 
 class ResponsableImplantationAdmin(admin.ModelAdmin):
     actions = None
@@ -963,8 +980,8 @@ class ResponsableImplantationAdmin(admin.ModelAdmin):
                     employe, u"sans dossier actif")
             else:
                 return employe
-        except Exception, e:
-            if obj.statut in (1, 2): # ouverte, ouverture imminente
+        except Exception:
+            if obj.statut in (1, 2):  # ouverte, ouverture imminente
                 css = "style='color: red;'"
             else:
                 css = ""
@@ -981,6 +998,7 @@ class ResponsableImplantationAdmin(admin.ModelAdmin):
     def has_delete_permission(self, request, obj=None):
         return False
 
+
 class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin, ArchiveMixin):
     list_display = (
             'nom',
@@ -1001,6 +1019,7 @@ class ServiceAdmin(AUFMetadataAdminMixin, admin.ModelAdmin, ArchiveMixin):
     _date_modification.short_description = u'date modification'
     _date_modification.admin_order_field = 'date_modification'
 
+
 class ServiceProxyAdmin(ServiceAdmin):
     list_display = ('nom', '_organigramme', '_archive', )
     actions = None
@@ -1106,7 +1125,8 @@ class TypePosteAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
     _date_modification.admin_order_field = 'date_modification'
 
 
-class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin, ArchiveMixin):
+class TypeRemunerationAdmin(AUFMetadataAdminMixin, admin.ModelAdmin,
+                            ArchiveMixin):
     list_display = (
             'nom',
             'type_paiement',
@@ -1169,6 +1189,7 @@ class ValeurPointAdmin(AUFMetadataAdminMixin, admin.ModelAdmin):
         return obj.devise.nom
     _devise_nom.short_description = "Nom de la devise"
 
+
 class ImplantationProxyAdmin(admin.ModelAdmin):
     list_display = ('nom', '_organigramme')
     actions = None
@@ -1184,10 +1205,13 @@ class ImplantationProxyAdmin(admin.ModelAdmin):
         return in_drh_or_admin(request.user)
 
     def _organigramme(self, obj):
-        return """<a href="%s"><strong>Organigramme</strong></a>""" % (reverse('rho_implantation', args=(obj.id,)))
+        return '<a href="%s"><strong>Organigramme</strong></a>' % (
+            reverse('rho_implantation', args=(obj.id,))
+        )
     _organigramme.allow_tags = True
     _organigramme.short_description = "Organigramme"
 
+
 class RegionProxyAdmin(admin.ModelAdmin):
     list_display = ('nom', '_organigramme')
     actions = None
@@ -1203,13 +1227,13 @@ class RegionProxyAdmin(admin.ModelAdmin):
         return in_drh_or_admin(request.user)
 
     def _organigramme(self, obj):
-        return """<a href="%s"><strong>Organigramme</strong></a>""" % (reverse('rho_region', args=(obj.id,)))
+        return """<a href="%s"><strong>Organigramme</strong></a>""" % (
+            reverse('rho_region', args=(obj.id,))
+        )
     _organigramme.allow_tags = True
     _organigramme.short_description = "Organigramme"
 
 
-
-
 admin.site.register(rh.Classement, ClassementAdmin)
 admin.site.register(rh.Devise, DeviseAdmin)
 admin.site.register(rh.Dossier, DossierAdmin)
@@ -1219,7 +1243,9 @@ admin.site.register(rh.Employe, EmployeAdmin)
 admin.site.register(rh.CategorieEmploi, CategorieEmploiAdmin)
 admin.site.register(rh.OrganismeBstg, OrganismeBstgAdmin)
 admin.site.register(rh.Poste, PosteAdmin)
-admin.site.register(rh.ResponsableImplantationProxy, ResponsableImplantationAdmin)
+admin.site.register(
+    rh.ResponsableImplantationProxy, ResponsableImplantationAdmin
+)
 admin.site.register(rh.Service, ServiceAdmin)
 admin.site.register(rh.Statut, StatutAdmin)
 admin.site.register(rh.TauxChange, TauxChangeAdmin)