ajout PJ au dossier (NON TESTE, ajax fait disparaitre mon form...)
[auf_rh_dae.git] / project / dae / views.py
index 2701dcd..1fe65fd 100644 (file)
@@ -8,7 +8,8 @@ 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,
-                               PosteForm, PosteFinancementForm, PostePieceForm)
+                               PosteForm, PosteFinancementForm, PostePieceForm,
+                               DossierPieceForm)
 from project.dae import models as dae
 from project.rh_v1 import models as rh
 
@@ -158,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)
+                piecesForm = DossierPieceForm(request.POST, request.FILES, instance=dossier)
+
                 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)
+                piecesForm = DossierPieceForm(instance=dossier)
         else:
             # Initialisation d'un formulaire vide
             dossier_rh = rh.Dossier()
@@ -176,10 +181,12 @@ def embauche(request, key=None, dossier=None):
             else:
                 dossier = pre_filled_dossier(dossier_rh, 'new', poste_rh)
                 employe_form = EmployeForm()
+
             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))
@@ -243,7 +250,11 @@ def dossier(request, poste_key, employe_key):
     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):