get_employe_from_user, is_user_dans_services_centraux
from project.dae import models as dae
-from project.dae.workflow import \
- grp_drh, POSTE_ETATS_BOUTONS, POSTE_ETAT_FINALISE
+from project.dae.workflow import grp_drh, POSTE_ETATS_BOUTONS
class BaseInlineFormSetWithInitial(BaseInlineFormSet):
annee = ""
if poste.date_debut:
annee = poste.date_debut.year
+
+ nom = poste.nom
+
label = u"%s %s - %s [%s]" % (
- annee, poste.type_poste, poste.type_poste.categorie_emploi.nom,
- poste.id
+ annee, nom, poste.type_poste.categorie_emploi.nom, poste.id
)
return label
request = kwargs.pop('request')
super(PosteForm, self).__init__(*args, **kwargs)
self.fields['poste'].choices = self._poste_choices(request)
+
self.fields['implantation'].choices = \
_implantation_choices(self, request)
def _poste_choices(self, request):
""" Menu déroulant pour les postes.
-
- Constitué des postes de dae et des postes de rh_v1 qui n'ont pas
- d'équivalent dans dae.
-
+ Constitué des postes de RH
"""
- copies = dae.Poste.objects \
- .ma_region_ou_service(request.user) \
- .exclude(id_rh__isnull=True) \
- .filter(etat=POSTE_ETAT_FINALISE)
- id_copies = [p.id_rh_id for p in copies.all()]
- rhv1 = rh.Poste.objects.ma_region_ou_service(request.user) \
- .exclude(id__in=id_copies)
- # Optimisation de la requête
- rhv1 = rhv1.select_related(depth=1)
+ postes_rh = rh.Poste.objects.ma_region_ou_service(request.user).all()
+ postes_rh = postes_rh.select_related(depth=1)
return [('', 'Nouveau poste')] + \
- sorted([('rh-%s' % p.id, label_poste_display(p)) for p in rhv1],
+ sorted([('rh-%s' % p.id, label_poste_display(p)) for p in
+ postes_rh],
key=lambda t: t[1])
def clean(self):
--- /dev/null
+# -*- encoding: utf-8 -*-
+
+import sys
+import codecs
+from django.core.management.base import BaseCommand
+from project.rh import models as rh
+from project.dae import models as dae
+
+class Command(BaseCommand):
+
+ def handle(self, *args, **options):
+
+ stdout = options.get('stdout', sys.stdout)
+ self.stdout = codecs.getwriter('utf8')(stdout)
+
+ if args[0] == "liste_poste":
+ for poste in dae.Poste.objects.filter(id_rh__isnull=False):
+ self.stdout.write(u"%s: %s %s [%s]\n" % (poste.id, poste.nom,
+ poste.implantation, poste.etat))
+
+ if args[0] == "importer_poste":
+ poste = dae.Poste.objects.get(id=args[1])
+ poste.importer_dans_rh()
+ self.stdout.write(u"DAE:%s => RH:%s\n" % (poste.id, poste.id_rh.id))
params = getattr(request, method, [])
data = []
- # Voir le code de _poste_choices dans forms.py
- copies = dae.Poste.objects.exclude(id_rh__isnull=True) \
- .filter(etat=POSTE_ETAT_FINALISE)
- rh_postes_actifs = rh.Poste.objects.all()
-
if 'implantation_id' in params \
and params.get('implantation_id') is not u"":
implantation_id = params.get('implantation_id')
- copies = copies.filter(implantation__id=implantation_id)
- rh_postes_actifs = rh_postes_actifs.filter(
- implantation__id=implantation_id
- )
+ q = Q(implantation__id=implantation_id)
+ else:
+ q = Q()
- id_copies = [p.id_rh_id for p in copies.all()]
- rhv1 = rh_postes_actifs.exclude(id__in=id_copies)
- rhv1 = rhv1.select_related(depth=1)
+ postes_rh = rh.Poste.objects.ma_region_ou_service(request.user).filter(q)
+ postes_rh = postes_rh.select_related(depth=1)
data = [('', 'Nouveau poste')] + \
- sorted([('rh-%s' % p.id, label_poste_display(p)) for p in rhv1],
- key=lambda t: t[1])
+ sorted([('rh-%s' % p.id, label_poste_display(p)) for p in
+ postes_rh],
+ key=lambda t: t[1])
return HttpResponse(dumps(data))