ajout PJ au dossier (NON TESTE, ajax fait disparaitre mon form...)
[auf_rh_dae.git] / project / dae / views.py
index 5fb7e5a..1fe65fd 100644 (file)
@@ -8,13 +8,15 @@ from django.shortcuts import redirect, render_to_response, get_object_or_404
 from django.template import RequestContext
 
 from project.dae.forms import (ChoosePosteForm, DossierForm, EmployeForm,
 from django.template import RequestContext
 
 from project.dae.forms import (ChoosePosteForm, DossierForm, EmployeForm,
-                               PosteForm, PosteFinancementForm)
+                               PosteForm, PosteFinancementForm, PostePieceForm,
+                               DossierPieceForm)
 from project.dae import models as dae
 from project.rh_v1 import models as rh
 
 from project.decorators import admin_required
 
 
 from project.dae import models as dae
 from project.rh_v1 import models as rh
 
 from project.decorators import admin_required
 
 
+
 def index(request):
     return render_to_response('dae/index.html', {}, RequestContext(request))
 
 def index(request):
     return render_to_response('dae/index.html', {}, RequestContext(request))
 
@@ -48,15 +50,18 @@ def poste(request, key=None):
     if request.POST:
         data.update(dict(request.POST.items()))
         form = PosteForm(data, instance=poste)
     if request.POST:
         data.update(dict(request.POST.items()))
         form = PosteForm(data, instance=poste)
+        piecesForm = PostePieceForm(request.POST, request.FILES, instance=poste)
         if 'save' in data and form.is_valid():
             poste = form.save()
         if 'save' in data and form.is_valid():
             poste = form.save()
+            piecesForm.save()
             return redirect('poste', key='dae-%s' % poste.id)
     else:
         # 'initial' évite la validation prémature lors d'une copie de poste de
         # rh_v1 vers dae.
         form = PosteForm(initial=data, instance=poste)
             return redirect('poste', key='dae-%s' % poste.id)
     else:
         # 'initial' évite la validation prémature lors d'une copie de poste de
         # rh_v1 vers dae.
         form = PosteForm(initial=data, instance=poste)
+        piecesForm = PostePieceForm(instance=poste)
 
 
-    vars.update(dict(form=form, poste=poste, poste_key=key))
+    vars.update(dict(form=form, poste=poste, poste_key=key, piecesForm=piecesForm))
 
     return render_to_response('dae/poste.html', vars, RequestContext(request))
 
 
     return render_to_response('dae/poste.html', vars, RequestContext(request))
 
@@ -154,12 +159,16 @@ def embauche(request, key=None, dossier=None):
                 else:
                     dossier = get_object_or_404(dae.Dossier, pk=dossier)
                 dossier_form = DossierForm(request.POST, instance=dossier)
                 else:
                     dossier = get_object_or_404(dae.Dossier, pk=dossier)
                 dossier_form = DossierForm(request.POST, instance=dossier)
+                piecesForm = DossierPieceForm(request.POST, request.FILES, instance=dossier)
+
                 if dossier_form.is_valid():
                     dossier = dossier_form.save()
                 if dossier_form.is_valid():
                     dossier = dossier_form.save()
+                    piecesForm.save()
                     return redirect('embauche', key='dae-%s' % poste.id,
                                     dossier=dossier.id)
             else:
                 dossier_form = DossierForm(instance=dossier)
                     return redirect('embauche', key='dae-%s' % poste.id,
                                     dossier=dossier.id)
             else:
                 dossier_form = DossierForm(instance=dossier)
+                piecesForm = DossierPieceForm(instance=dossier)
         else:
             # Initialisation d'un formulaire vide
             dossier_rh = rh.Dossier()
         else:
             # Initialisation d'un formulaire vide
             dossier_rh = rh.Dossier()
@@ -172,10 +181,12 @@ def embauche(request, key=None, dossier=None):
             else:
                 dossier = pre_filled_dossier(dossier_rh, 'new', poste_rh)
                 employe_form = EmployeForm()
             else:
                 dossier = pre_filled_dossier(dossier_rh, 'new', poste_rh)
                 employe_form = EmployeForm()
+
             dossier_form = DossierForm(instance=dossier)
             dossier_form = DossierForm(instance=dossier)
+            piecesForm = DossierPieceForm(instance=dossier)
 
 
-        vars = dict(step='employe', poste=poste, dossier=dossier,
-                    forms=dict(employe=employe_form, dossier=dossier_form))
+        vars = dict(step='employe', poste=poste, dossier=dossier, piecesForm=piecesForm,
+                    forms=dict(employe=employe_form, dossier=dossier_form, ))
 
     return render_to_response('dae/embauche.html', vars,
                               RequestContext(request))
 
     return render_to_response('dae/embauche.html', vars,
                               RequestContext(request))
@@ -239,7 +250,11 @@ def dossier(request, poste_key, employe_key):
     else:
         dossier = pre_filled_dossier(dossier_rh, employe_source, poste_rh)
 
     else:
         dossier = pre_filled_dossier(dossier_rh, employe_source, poste_rh)
 
-    return HttpResponse(DossierForm(initial=data, instance=dossier).as_table())
+    dossier_form = DossierForm(initial=data, instance=dossier)
+    vars = dict(form=dossier_form)
+
+    return render_to_response('dae/embauche-dossier.html', vars,
+                          RequestContext(request))
 
 
 def salaire(request, implantation, devise, classement):
 
 
 def salaire(request, implantation, devise, classement):