[#3165] Remplacé les filtres et protection par région pour des filtres et protections...
authorEric Mc Sween <eric.mcsween@auf.org>
Fri, 21 Sep 2012 14:57:17 +0000 (10:57 -0400)
committerEric Mc Sween <eric.mcsween@auf.org>
Fri, 21 Sep 2012 16:40:18 +0000 (12:40 -0400)
22 files changed:
project/dae/catalogues.py
project/dae/forms.py
project/dae/managers.py
project/dae/templates/dae/embauche-row.html
project/dae/templates/dae/embauches_finalisees.html
project/dae/templates/dae/poste-row.html
project/dae/templatetags/dae.py
project/dae/views.py
project/decorators.py
project/permissions.py
project/rh/admin.py
project/rh/catalogues.py
project/rh/forms.py
project/rh/managers.py
project/rh/models.py
project/rh/ods.py
project/rh/templates/rh/include/dossier.html
project/rh/templates/rh/rapports/contrats.html
project/rh/templates/rh/rapports/employes_sans_contrat.html
project/rh/templates/rh/rapports/masse_salariale.html
project/rh/templatetags/rapports.py
project/rh/views.py

index 3ca3d7e..ba2d0e3 100644 (file)
@@ -72,12 +72,10 @@ class Dossier(object):
             Q(employe__nom__icontains=q) | \
             Q(employe__prenom__icontains=q)
 
-        if groups.is_user_dans_services_centraux(request.user):
-            q_place = Q(**{prefixe_implantation: employe.implantation})
-        else:
-            q_place = Q(**{
-                prefixe_implantation + '__region': employe.implantation.region
-            })
+        q_place = Q(**{
+            prefixe_implantation + '__zone_administrative':
+            employe.implantation.zone_administrative
+        })
 
         user_groupes = [g.name for g in request.user.groups.all()]
         if groups.DRH_NIVEAU_1 in user_groupes:
@@ -119,7 +117,8 @@ class Poste(object):
             q_place = Q(**{prefixe_implantation: employe.implantation})
         else:
             q_place = Q(**{
-                prefixe_implantation + '__region': employe.implantation.region
+                prefixe_implantation + '__zone_administrative':
+                employe.implantation.zone_administrative
             })
 
         user_groupes = [g.name for g in request.user.groups.all()]
index 28de814..e2007a8 100644 (file)
@@ -84,12 +84,7 @@ class BaseInlineFormSetWithInitial(BaseInlineFormSet):
 def _implantation_choices(obj, request):
     # TRAITEMENT NORMAL
     employe = groups.get_employe_from_user(request.user)
-    # SERVICE
-    if groups.is_user_dans_services_centraux(request.user):
-        q = Q(**{'id': employe.implantation_id})
-    # REGION
-    else:
-        q = Q(**{'region': employe.implantation.region})
+    q = Q(**{'zone_administrative': employe.implantation.zone_administrative})
 
     # TRAITEMENT DRH
     user_groupes = [g.name for g in request.user.groups.all()]
@@ -102,18 +97,16 @@ def _implantation_choices(obj, request):
 def _employe_choices(obj, request):
     # TRAITEMENT NORMAL
     employe = groups.get_employe_from_user(request.user)
-    # SERVICE
-    if groups.is_user_dans_services_centraux(request.user):
-        q_dae_region_service = Q(poste__implantation=employe.implantation)
-        q_rh_region_service = Q(poste__implantation=employe.implantation)
-    # REGION
-    else:
-        q_dae_region_service = Q(
-            poste__implantation__region=employe.implantation.region
+    q_dae_region_service = Q(
+        poste__implantation__zone_administrative=(
+            employe.implantation.zone_administrative
         )
-        q_rh_region_service = Q(
-            poste__implantation__region=employe.implantation.region
+    )
+    q_rh_region_service = Q(
+        poste__implantation__zone_administrative=(
+            employe.implantation.zone_administrative
         )
+    )
     # TRAITEMENT DRH
     user_groupes = [g.name for g in request.user.groups.all()]
     if groups.DRH_NIVEAU_1 in user_groupes:
index ca64649..f4bc09e 100644 (file)
@@ -32,7 +32,8 @@ class TodoManagerMixin(object):
                     groups.DRH_NIVEAU_2,
                 ):
                     q2 &= Q(**{
-                        self.prefixe_implantation: employe.implantation.region
+                        self.prefixe_implantation:
+                        employe.implantation.zone_administrative
                     })
                 q |= q2
 
index dc4584b..6027968 100644 (file)
@@ -1,6 +1,6 @@
 {% load dae %}
 <tr>
-    <td>{{ dossier.poste.implantation|region_ou_service }}</td>
+    <td>{{ dossier.poste.implantation.zone_administrative }}</td>
     <td>{{ dossier.poste.implantation }}</td>
     <td><a href="{% url embauche_consulter dossier.id %}">{{ dossier.poste.nom }}</a></td>
     <td>{{ dossier.employe }}</td>
index 90bf4c7..af4ec45 100644 (file)
@@ -31,7 +31,7 @@
     <thead>
       <tr>
         <th></th>
-        {% sort_header "region" "Région" %}
+        {% sort_header "zone_administrative" "Zone administrative" %}
         {% sort_header "implantation" "Implantation" %}
         {% sort_header "poste" "Poste" %}
         {% sort_header "personne" "Personne" %}
@@ -46,7 +46,7 @@
       {% for dossier in embauches.object_list %}
       <tr>
         <td><input type="checkbox" name="ids" value="{{ dossier.id }}"></td>
-        <td>{{ dossier.poste.implantation|region_ou_service }}</td>
+        <td>{{ dossier.poste.implantation.zone_administrative }}</td>
         <td>{{ dossier.poste.implantation }}</td>
         <td><a href="{% url poste_consulter dossier.poste.key %}">{{ dossier.poste.nom }}</a></td>
         <td><a href="{% url embauche_consulter dossier.id %}">{{ dossier.employe }}</a></td>
index 8118def..40a82aa 100644 (file)
@@ -1,6 +1,6 @@
 {% load dae %}
 <tr>
-    <td>{{ poste.implantation|region_ou_service }}</td>
+    <td>{{ poste.implantation.zone_administrative }}</td>
     <td>{{ poste.implantation }}</td>
     <td><a href="{% url poste_consulter poste.key %}">{{ poste.nom }}</a></td>
     <td>{{ poste.date_creation|date:"d-m-Y" }}</td>
index 2b69560..3fbe768 100644 (file)
@@ -46,14 +46,6 @@ def est_editable(obj, user):
         return False
 
 @register.filter
-def region_ou_service(implantation):
-    if implantation.id == 15:
-        return u"Services centraux de Montréal (SCM)"
-    if implantation.id == 19:
-        return u"Services centraux de Paris (SCP)"
-    return implantation.region
-
-@register.filter
 def basename(path):
     return os.path.basename(path)
 
index 33838d4..08adf19 100644 (file)
@@ -538,8 +538,8 @@ def embauches_finalisees(request):
         importees = search_form.cleaned_data.get('importees')
         if q:
             criteria = [
-                Q(poste__implantation__region__nom__icontains=word) |
-                Q(poste__implantation__region__code=word) |
+                Q(poste__implantation__zone_administrative__nom__icontains=word) |
+                Q(poste__implantation__zone_administrative__code=word) |
                 Q(poste__implantation__nom__icontains=word) |
                 Q(poste__nom__icontains=word) |
                 Q(employe__nom__icontains=word) |
@@ -561,7 +561,7 @@ def embauches_finalisees(request):
         dir = ''
     if tri == 'region':
         embauches = embauches.order_by(
-            dir + 'poste__implantation__region__nom'
+            dir + 'poste__implantation__zone_administrative__nom'
         )
     elif tri == 'implantation':
         embauches = embauches.order_by(dir + 'poste__implantation__nom')
index d9d8ce9..c386666 100644 (file)
@@ -69,7 +69,8 @@ def region_protected(model):
                groups.DIRECTEUR_DE_BUREAU in user_groups:
                 employe = groups.get_employe_from_user(request.user)
                 q = Q(**{
-                    model.prefix_implantation: employe.implantation.region
+                    model.prefix_implantation:
+                    employe.implantation.zone_administrative
                 })
                 qs = model.objects.filter(q)
                 if int(id) in [o.id for o in qs]:
@@ -77,7 +78,8 @@ def region_protected(model):
             return redirect_interdiction(request)
         return wrapped
     return wrapper
-    
+
+
 def in_one_of_group(groups):
     """
     Test si le user appartient au moins 1 des ces groupes
index 213b55c..09db52e 100644 (file)
@@ -38,11 +38,11 @@ def obj_in_region_user(user, obj):
     if isinstance(obj, rh.Dossier):
         return True
     if isinstance(obj, rh.Poste):
-        return obj.implantation.region == region_user
+        return obj.implantation.zone_administrative == region_user
     return False
     
 def get_region_user(user):
     # gère actuellement qu'une seule région par user
     employe = get_employe_from_user(user)
-    region_user = employe.implantation.region
+    region_user = employe.implantation.zone_administrative
     return region_user
index 71679a8..64a26d9 100644 (file)
@@ -40,6 +40,7 @@ class BaseAdmin(admin.ModelAdmin):
             'jquery-autocomplete/jquery.autocomplete.min.js',
         )
 
+
 # Admin pour reversion
 
 class ArchivableAdmin(admin.ModelAdmin):
@@ -365,7 +366,7 @@ class DossierAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin,
         '_nom',
         '_employe',
         '_poste',
-        '_region',
+        '_zone_administrative',
         '_implantation',
         '_date_debut',
         '_date_fin',
@@ -374,7 +375,7 @@ class DossierAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin,
     )
     list_display_links = ('_nom',)
     list_filter = (
-        'poste__implantation__region',
+        'poste__implantation__zone_administrative',
         'poste__implantation',
         'poste__type_poste__categorie_emploi',
         'poste__type_poste',
@@ -415,7 +416,7 @@ class DossierAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin,
     def lookup_allowed(self, key, value):
         if key in (
             'employe__nom__istartswith',
-            'poste__implantation__region__id__exact',
+            'poste__implantation__zone_administrative__code__exact',
             'poste__implantation__id__exact',
             'poste__type_poste__id__exact',
             'poste__type_poste__categorie_emploi__id__exact',
@@ -481,10 +482,10 @@ class DossierAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin,
     _poste.short_description = u'Poste'
     _poste.admin_order_field = 'poste__nom'
 
-    def _region(self, obj):
-        return obj.poste.implantation.region.code
-    _region.short_description = u"Région"
-    _region.admin_order_field = 'poste__implantation__region__code'
+    def _zone_administrative(self, obj):
+        return obj.poste.implantation.zone_administrative.code
+    _zone_administrative.short_description = u"Zone administrative"
+    _zone_administrative.admin_order_field = 'poste__implantation__zone_administrative__code'
 
     def _implantation(self, obj):
         return obj.poste.implantation.nom
@@ -548,14 +549,14 @@ class EmployeAdminBase(DateRangeMixin, ProtectRegionMixin,
     form = EmployeAdminForm
     list_display = (
         '_id', '_apercu', '_nom', '_dossiers_postes',
-        #'_region',
+        #'_zone_administrative',
         #'_implantation',
         'date_entree',
         'derniere_modification'
     )
     list_display_links = ('_nom',)
     list_filter = (
-        'rh_dossiers__poste__implantation__region',
+        'rh_dossiers__poste__implantation__zone_administrative',
         'rh_dossiers__poste__implantation', 'nb_postes'
     )
     inlines = (
@@ -608,14 +609,14 @@ class EmployeAdminBase(DateRangeMixin, ProtectRegionMixin,
     _nom.short_description = u"Employé"
     _nom.admin_order_field = "nom"
 
-    def _region(self, obj):
+    def _zone_administrative(self, obj):
         try:
             d = rh.Dossier.objects.filter(employe=obj.id, principal=True)[0]
-            region = d.poste.implantation.region.code
+            zone = d.poste.implantation.zone_administrative.code
         except:
-            region = None
-        return region
-    _region.short_description = u"Région"
+            zone = None
+        return zone
+    _zone_administrative.short_description = u"Zone administrative"
 
     def _implantation(self, obj):
         try:
@@ -793,8 +794,8 @@ class PosteAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin,
         'id',
         'nom',
         'implantation__nom',
-        'implantation__region__code',
-        'implantation__region__nom',
+        'implantation__zone_administrative__code',
+        'implantation__zone_administrative__nom',
         'rh_dossiers__employe__id',
         'rh_dossiers__employe__nom',
         'rh_dossiers__employe__prenom',
@@ -805,7 +806,7 @@ class PosteAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin,
         '_dae'
     )
     list_filter = (
-        'implantation__region',
+        'implantation__zone_administrative',
         'implantation',
         'service',
         'type_poste',
@@ -871,7 +872,7 @@ class PosteAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin,
     def lookup_allowed(self, key, value):
         return key in (
             'date_debut__gte', 'date_debut__isnull', 'date_fin__lte',
-            'date_fin__isnull', 'implantation__region__id__exact',
+            'date_fin__isnull', 'implantation__zone_administrative__code__exact',
             'implantation__id__exact', 'type_poste__id__exact',
             'type_poste__categorie_emploi__id__exact', 'service__id__exact',
             'service__isnull', 'vacant__exact', 'vacant__isnull',
@@ -927,10 +928,10 @@ class PosteAdmin(DateRangeMixin, ProtectRegionMixin, reversion.VersionAdmin,
     _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 _zone_administrative(self, poste):
+        return poste.implantation.zone_administrative.code
+    _zone_administrative.short_description = 'Zone administrative'
+    _zone_administrative.admin_order_field = 'implantation__zone_administrative__code'
 
     def _implantation(self, poste):
         return poste.implantation.nom
@@ -1027,8 +1028,8 @@ class ResponsableImplantationAdmin(BaseAdmin):
     actions = None
     fields = ('nom', )
     inlines = (ResponsableInline, )
-    list_filter = ('region', 'statut', )
-    list_display = ('_region', '_nom', 'statut', '_responsable', )
+    list_filter = ('zone_administrative', 'statut', )
+    list_display = ('_zone_administrative', '_nom', 'statut', '_responsable', )
     list_display_links = ('_nom',)
     list_per_page = 500
     readonly_fields = ('nom', )
@@ -1041,10 +1042,10 @@ class ResponsableImplantationAdmin(BaseAdmin):
     ordering = ('nom',)
     inlines = (ResponsableInline, )
 
-    def _region(self, obj):
-        return obj.region.code
-    _region.short_description = u"Région"
-    _region.admin_order_field = 'region__code'
+    def _zone_administrative(self, obj):
+        return obj.zone_administrative.code
+    _zone_administrative.short_description = u"Zone administrative"
+    _zone_administrative.admin_order_field = 'zone_administrative__code'
 
     def _nom(self, obj):
         return obj.nom
@@ -1207,7 +1208,7 @@ class ValeurPointAdmin(reversion.VersionAdmin, DerniereModificationAdmin,
         '_devise_code', '_devise_nom', 'annee', 'implantation',
         'valeur', 'derniere_modification'
     )
-    list_filter = ('annee', 'devise', 'implantation__region', )
+    list_filter = ('annee', 'devise', 'implantation__zone_administrative', )
     fieldsets = (
         (None, {'fields': ('valeur', 'devise', 'implantation', 'annee')}),
     )
index c039911..96d745e 100644 (file)
@@ -33,12 +33,12 @@ class Implantation(object):
     def get_query(self, q, request):
         implantations = ref.Implantation.objects.filter(
             Q(nom__icontains=q) | Q(nom_court__icontains=q) |
-            Q(nom_long__icontains=q) | Q(region__nom__icontains=q)
+            Q(nom_long__icontains=q) | Q(zone_administrative__nom__icontains=q)
         )
         if user_gere_obj_de_sa_region(request.user):
             employe = get_employe_from_user(request.user)
             implantations = implantations.filter(
-                region=employe.implantation.region
+                zone_administrative=employe.implantation.zone_administrative
             )
         return implantations
 
index 272fecb..6333ffe 100644 (file)
@@ -89,8 +89,9 @@ class ResponsableInlineForm(forms.ModelForm):
 
 
 class MasseSalarialeForm(forms.Form):
-    region = forms.ModelChoiceField(
-        label=u'Région', queryset=ref.Region.objects.all(), required=False
+    zone_administrative = forms.ModelChoiceField(
+        label=u'Région', queryset=ref.ZoneAdministrative.objects.all(),
+        required=False
     )
     implantation = forms.ModelChoiceField(
         label=u'Implantation', queryset=ref.Implantation.objects.all(),
@@ -112,10 +113,13 @@ class MasseSalarialeForm(forms.Form):
         )
         if is_user_dans_region(user):
             employe = get_employe_from_user(user)
-            self.fields['region'].queryset = ref.Region.objects.filter(
-                id=employe.implantation.region.id
-            )
+            self.fields['zone_administrative'].queryset = \
+                    ref.ZoneAdministrative.objects.filter(
+                        code=employe.implantation.zone_administrative.code
+                    )
             self.fields['implantation'].queryset = \
                     ref.Implantation.objects.filter(
-                        region=employe.implantation.region
+                        zone_administrative=(
+                            employe.implantation.zone_administrative
+                        )
                     )
index a4bc601..bee3f71 100644 (file)
@@ -27,7 +27,10 @@ class SecurityManager(models.Manager):
         # TRAITEMENT NORMAL
         ############################################
         # REGION
-        q = Q(**{self.prefixe_implantation: employe.implantation.region})
+        q = Q(**{
+            self.prefixe_implantation:
+            employe.implantation.zone_administrative
+        })
 
         # SERVICE
         if self.prefixe_service \
@@ -98,7 +101,7 @@ class PosteQuerySet(ActifsQuerySet):
 
 class PosteManager(SecurityManager):
     prefixe_service = "service"
-    prefixe_implantation = "implantation__region"
+    prefixe_implantation = "implantation__zone_administrative"
 
     def get_query_set(self):
         return PosteQuerySet(self.model).select_related('type_poste')
@@ -116,7 +119,7 @@ class DossierQuerySet(ActifsQuerySet):
 
 class DossierManager(SecurityManager):
     prefixe_service = "poste__service"
-    prefixe_implantation = "poste__implantation__region"
+    prefixe_implantation = "poste__implantation__zone_administrative"
 
     def get_query_set(self):
         return DossierQuerySet(self.model) \
@@ -176,12 +179,12 @@ class EmployeManager(models.Manager):
 
 class PosteComparaisonManager(SecurityManager):
     use_for_related_fields = True
-    prefixe_implantation = "implantation__region"
+    prefixe_implantation = "implantation__zone_administrative"
 
 
 class DossierComparaisonManager(SecurityManager):
     use_for_related_fields = True
-    prefixe_implantation = "implantation__region"
+    prefixe_implantation = "implantation__zone_administrative"
 
 
 class DeviseManager(models.Manager):
index daa714f..ada39b5 100644 (file)
@@ -337,10 +337,10 @@ class Poste_( DateActiviteMixin, models.Model,):
         )
         return representation
 
-    prefix_implantation = "implantation__region"
+    prefix_implantation = "implantation__zone_administrative"
 
-    def get_regions(self):
-        return [self.implantation.region]
+    def get_zones_administratives(self):
+        return [self.implantation.zone_administrative]
 
     def get_devise(self):
         vp = ValeurPoint.objects.filter(
@@ -625,13 +625,14 @@ class Employe(models.Model):
             pass
         return poste
 
-    prefix_implantation = "rh_dossiers__poste__implantation__region"
+    prefix_implantation = \
+            "rh_dossiers__poste__implantation__zone_administrative"
 
-    def get_regions(self):
-        regions = []
-        for d in self.dossiers.all():
-            regions.append(d.poste.implantation.region)
-        return regions
+    def get_zones_administratives(self):
+        return [
+            d.poste.implantation.zone_administrative
+            for d in self.dossiers.all()
+        ]
 
 reversion.register(Employe, format='xml', follow=[
     'pieces', 'commentaires', 'ayantdroits'
@@ -722,13 +723,14 @@ class AyantDroit(models.Model):
     def __unicode__(self):
         return u'%s %s' % (self.nom.upper(), self.prenom, )
 
-    prefix_implantation = "employe__dossiers__poste__implantation__region"
+    prefix_implantation = \
+            "employe__dossiers__poste__implantation__zone_administrative"
 
-    def get_regions(self):
-        regions = []
-        for d in self.employe.dossiers.all():
-            regions.append(d.poste.implantation.region)
-        return regions
+    def get_zones_administratives(self):
+        return [
+            d.poste.implantation.zone_administrative
+            for d in self.employe.dossiers.all()
+        ]
 
 reversion.register(AyantDroit, format='xml', follow=['commentaires'])
 
@@ -840,10 +842,10 @@ class Dossier_(DateActiviteMixin, models.Model, DevisableMixin,):
             poste = self.poste.nom_feminin
         return u'%s - %s' % (self.employe, poste)
 
-    prefix_implantation = "poste__implantation__region"
+    prefix_implantation = "poste__implantation__zone_administrative"
 
-    def get_regions(self):
-        return [self.poste.implantation.region]
+    def get_zones_administratives(self):
+        return [self.poste.implantation.zone_administrative]
 
     def remunerations(self):
         key = "%s_remunerations" % self._meta.app_label
@@ -1431,11 +1433,6 @@ class OrganismeBstg(models.Model):
     def __unicode__(self):
         return u'%s (%s)' % (self.nom, self.get_type_display())
 
-    prefix_implantation = "pays__region"
-
-    def get_regions(self):
-        return [self.pays.region]
-
 reversion.register(OrganismeBstg, format='xml')
 
 
index ca731a9..af83eed 100644 (file)
@@ -90,7 +90,7 @@ def masse_salariale(lignes, annee, titres_traitements, titres_indemnites,
         # GESTION de l'affichage des VACANTS
         if 'dossier' not in ligne.keys():
             row.add_cells([
-                ligne['poste'].implantation.region.code,
+                ligne['poste'].implantation.zone_administrative.code,
                 ligne['poste'].implantation.adresse_physique_pays.nom,
                 ligne['poste'].implantation.nom_court
             ])
@@ -158,7 +158,7 @@ def masse_salariale(lignes, annee, titres_traitements, titres_indemnites,
             continue
 
         row.add_cells([
-            ligne['poste'].implantation.region.code,
+            ligne['poste'].implantation.zone_administrative.code,
             ligne['poste'].implantation.adresse_physique_pays.nom,
             ligne['poste'].implantation.nom_court
         ])
index de978f5..206e1d6 100644 (file)
@@ -1,6 +1,6 @@
 <fieldset class="module aligned">
     <h2>Localisation</h2>
-    {% include "rh/form-row.html" with label="Région" value=dossier.poste.implantation.region %}
+    {% include "rh/form-row.html" with label="Zone administrative" value=dossier.poste.implantation.zone_administrative %}
     {% include "rh/form-row.html" with label="Implantation" value=dossier.poste.implantation %}
 </fieldset>
 
index 27afccf..19d5f5b 100644 (file)
@@ -25,7 +25,7 @@
 <div id="changelist-filter">
   <h2>{% trans 'Filter' %}</h2>
   
-  {% filter_region_contrat %}
+  {% filter_zone_administrative_contrat %}
   {% filter_implantation_contrat %}
   {% filter_type_contrat %}
   {% filter_echeance_contrat %}
@@ -57,7 +57,7 @@
     <td>{{ contrat.date_debut }}</td>
     <td>{{ contrat.date_fin|default:'' }}</td>
     <td>{{ contrat.dossier.get_statut_residence_display }}</td>
-    <td>{{ contrat.dossier.poste.implantation.region.nom }}</td>
+    <td>{{ contrat.dossier.poste.implantation.zone_administrative.nom }}</td>
     <td>{{ contrat.dossier.poste.implantation.nom }}</td>
   </tr>
   {% endfor %}
index 56af714..ae74f3c 100644 (file)
@@ -17,7 +17,7 @@
 {% block contentrapport %}
 <div id="changelist-filter">
   <h2>{% trans 'Filter' %}</h2>
-  {% filter_region_dossier %}
+  {% filter_zone_administrative_dossier %}
   {% filter_implantation_dossier %}
 </div>
 
@@ -40,7 +40,7 @@
       <td>{{ d.dernier_contrat.date_debut|default_if_none:"" }}</td>
       <td>{{ d.dernier_contrat.date_fin|default_if_none:"" }}</td>
       <td>{{ d.get_statut_residence_display }}</td>
-      <td>{{ d.poste.implantation.region.code }}</td>
+      <td>{{ d.poste.implantation.zone_administrative.code }}</td>
       <td>{{ d.poste.implantation.nom }}</td>
     </tr>
     {% endfor %}
index 73c90fa..60a3f33 100644 (file)
@@ -109,7 +109,7 @@ $(document).ready(function() {
   <tbody>
     {% for ligne in lignes %}
     <tr class="{% cycle 'row1' 'row2' %}">
-      <td>{{ ligne.poste.implantation.region.code }}</td>
+      <td>{{ ligne.poste.implantation.zone_administrative.code }}</td>
       <td>{{ ligne.poste.implantation.adresse_physique_pays.nom }}</td>
       <td>{{ ligne.poste.implantation.nom_court }}</td>
       <td class="numeric">
index 7faf777..484326c 100644 (file)
@@ -6,7 +6,8 @@ from django.utils.encoding import smart_unicode
 from django.template import Library
 from django.utils.http import urlencode
 
-from auf.django.references.models import Implantation, Region
+from auf.django.references.models import \
+        Implantation, Region, ZoneAdministrative
 
 from project import groups
 
@@ -39,6 +40,18 @@ def filter_region(context, prefix=None):
 
 
 @register.inclusion_tag('admin/filter.html', takes_context=True)
+def filter_zone_administrative(context, prefix=None):
+    label = "".join([prefix or "", "implantation__zone_administrative"])
+    return {
+        'title': u"zone administrative",
+        'choices': prepare_choices(
+            ZoneAdministrative.objects.values_list('code', 'nom'), label, context,
+            remove=['pays', 'nord_sud']
+        )
+    }
+
+
+@register.inclusion_tag('admin/filter.html', takes_context=True)
 def filter_implantation(context, prefix=None):
     label = "".join([prefix or "", "implantation"])
     return {
@@ -50,27 +63,35 @@ def filter_implantation(context, prefix=None):
 
 
 @register.inclusion_tag('admin/filter.html', takes_context=True)
-def filter_region_contrat(context):
+def filter_zone_administrative_contrat(context):
     request = context['request']
     user_groups = [g.name for g in request.user.groups.all()]
     if groups.CORRESPONDANT_RH in user_groups or\
          groups.ADMINISTRATEURS in user_groups or\
          groups.DIRECTEUR_DE_BUREAU in user_groups:
         employe = groups.get_employe_from_user(request.user)
-        regions = Region.objects.filter(id=employe.implantation.region.id)
+        zones = ZoneAdministrative.objects.filter(
+            code=employe.implantation.zone_administrative.code
+        )
     else:
-       regions = Region.objects.all()
-    return {'title': u"région",
-            'choices': prepare_choices(regions.values_list('id', 'nom'), 'dossier__poste__implantation__region', context, remove=['pays', 'nord_sud'])}
+       zones = ZoneAdministrative.objects.all()
+    return {
+        'title': u"région",
+        'choices': prepare_choices(
+            zones.values_list('code', 'nom'),
+            'dossier__poste__implantation__zone_administrative',
+            context, remove=['pays', 'nord_sud']
+        )
+    }
 
 
 @register.inclusion_tag('admin/filter.html', takes_context=True)
-def filter_region_dossier(context):
+def filter_zone_administrative_dossier(context):
     return {
         'title': u"région",
         'choices': prepare_choices(
-            Region.objects.values_list('id', 'nom'),
-            'poste__implantation__region', context,
+            ZoneAdministrative.objects.values_list('code', 'nom'),
+            'poste__implantation__zone_administrative', context,
             remove=['pays', 'nord_sud']
         )
     }
@@ -95,7 +116,9 @@ def filter_implantation_contrat(context):
          groups.ADMINISTRATEURS in user_groups or\
          groups.DIRECTEUR_DE_BUREAU in user_groups:
         employe = groups.get_employe_from_user(request.user)
-        implantations = Implantation.objects.filter(region=employe.implantation.region)
+        implantations = Implantation.objects.filter(
+            zone_administrative=employe.implantation.zone_administrative
+        )
     else:
        implantations = Implantation.objects.all()
     return {'title': u"implantation",
@@ -193,12 +216,12 @@ def filter_a_venir(context):
 
 
 @register.inclusion_tag('admin/filter_select.html', takes_context=True)
-def filter_region_remun(context):
+def filter_zone_administrative_remun(context):
     return {
         'title': u"région",
         'choices': prepare_choices(
-            Region.objects.values_list('id', 'nom'),
-            'dossiers__poste__implantation__region', context,
+            ZoneAdministrative.objects.values_list('code', 'nom'),
+            'dossiers__poste__implantation__zone_administrative', context,
             remove=['pays', 'nord_sud']
         )
     }
index 59b7e4b..5010814 100644 (file)
@@ -110,7 +110,11 @@ def rapports_contrat(request):
        groups.ADMINISTRATEURS in user_groups or\
        groups.DIRECTEUR_DE_BUREAU in user_groups:
         employe = get_employe_from_user(request.user)
-        q = q & Q(dossier__poste__implantation__region=employe.implantation.region)
+        q = q & Q(
+            dossier__poste__implantation__zone_administrative=(
+                employe.implantation.zone_administrative
+            )
+        )
 
     contrats = contrats.filter(q)
 
@@ -130,7 +134,7 @@ def rapports_contrat(request):
         ("date_debut", u"Début contrat"),
         ("date_fin", u"Fin contrat"),
         ("dossier__statut_residence", u"Statut"),
-        ("dossier__poste__implantation__region", u"Région"),
+        ("dossier__poste__implantation__zone_administrative", u"Zone administrative"),
         ("dossier__poste__implantation", u"Implantation"),
     ]
     h = SortHeaders(
@@ -168,7 +172,8 @@ def rapports_employes_sans_contrat(request):
        groups.ADMINISTRATEURS in user_groups or\
        groups.DIRECTEUR_DE_BUREAU in user_groups:
         employe = get_employe_from_user(request.user)
-        lookup_params['poste__implantation__region'] = employe.implantation.region
+        lookup_params['poste__implantation__zone_administrative'] = \
+                employe.implantation.zone_administrative
 
     
     dossiers = rh.Dossier.objects.sans_contrats_ou_echus(**lookup_params)
@@ -190,7 +195,7 @@ def rapports_employes_sans_contrat(request):
         ("rh_contrats__date_debut", u"Début contrat"),
         ("rh_contrats__date_fin", u"Fin contrat"),
         ("statut_residence", u"Statut"),
-        ("poste__implantation__region__code", u"Région"),
+        ("poste__implantation__zone_administrative__code", u"Zone administrative"),
         ("poste__implantation__nom", u"Implantation"),
     ]
     h = SortHeaders(
@@ -217,7 +222,7 @@ def rapports_employes_sans_contrat(request):
 def rapports_masse_salariale(request):
     form = MasseSalarialeForm(request.user, request.GET)
     if 'annee' in request.GET and form.is_valid():
-        region = form.cleaned_data['region']
+        zone_administrative = form.cleaned_data['zone_administrative']
         implantation = form.cleaned_data['implantation']
         annee = form.cleaned_data['annee']
         debut_annee = date(annee, 1, 1)
@@ -230,7 +235,7 @@ def rapports_masse_salariale(request):
                 .actifs(annee=annee) \
                 .select_related(
                     'poste', 'poste__implantation',
-                    'poste__implantation__region',
+                    'poste__implantation__zone_administrative',
                     'poste__implantation__adresse_physique_pays',
                     'employe', 'poste__type_poste', 'classement',
                     'statut', 'organisme_bstg'
@@ -251,8 +256,8 @@ def rapports_masse_salariale(request):
                         )
                     }
                 )
-        if region:
-            dossiers = dossiers.filter(poste__implantation__region=region)
+        if zone_administrative:
+            dossiers = dossiers.filter(poste__implantation__zone_administrative=zone_administrative)
         if implantation:
             dossiers = dossiers.filter(poste__implantation=implantation)
 
@@ -271,8 +276,8 @@ def rapports_masse_salariale(request):
                         'taux_change': 'rh_tauxchange.taux'
                     }
                 )
-        if region:
-            remuns = remuns.filter(dossier__poste__implantation__region=region)
+        if zone_administrative:
+            remuns = remuns.filter(dossier__poste__implantation__zone_administrative=zone_administrative)
         if implantation:
             remuns = remuns.filter(dossier__poste__implantation=implantation)
         remuns_par_dossier = defaultdict(list)
@@ -419,8 +424,8 @@ def rapports_masse_salariale(request):
                         'taux_change': 'rh_tauxchange.taux'
                     }
                 )
-        if region:
-            postes = postes.filter(implantation__region=region)
+        if zone_administrative:
+            postes = postes.filter(implantation__zone_administrative=zone_administrative)
         if implantation:
             postes = postes.filter(implantation=implantation)
         postes = list(postes)
@@ -666,8 +671,12 @@ def employe_apercu(request, employe_id):
        groups.ADMINISTRATEURS in user_groups or\
        groups.DIRECTEUR_DE_BUREAU in user_groups:
         employe_connecte = get_employe_from_user(request.user)
-        q = Q(employe=employe) & Q(poste__implantation__region=employe_connecte.implantation.region)
-    
+        q = Q(employe=employe) & Q(
+            poste__implantation__zone_administrative=(
+                employe_connecte.implantation.zone_administrative
+            )
+        )
+
     dossiers = rh.Dossier.objects.filter(q).order_by('-date_debut')
 
     c = {