Desactivation mots-cles recherche chercheurs
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / chercheurs / views.py
index 616c8f2..ff95ee3 100644 (file)
@@ -1,6 +1,9 @@
 # -*- encoding: utf-8 -*-
+import hashlib
 from django.shortcuts import render_to_response
+from django.http import HttpResponseRedirect
 from django.template import Context, RequestContext
+from django.core.urlresolvers import reverse
 from forms import *
 
 from auf_references_client.models import Discipline, TypeImplantation
@@ -16,7 +19,7 @@ def chercheur_queryset (request):
     if simpleForm.is_valid ():
         pays = simpleForm.cleaned_data["pays"]
         if pays:
-            list = list.filter (pays = pays.pk)
+            list = list.filter (nationalite = pays.pk)
         fonction = simpleForm.cleaned_data["fonction"]
         if fonction:
             list = list.filter (fonction = fonction)
@@ -26,9 +29,9 @@ def chercheur_queryset (request):
         discipline = simpleForm.cleaned_data["discipline"]
         if discipline:
             list = list.filter (discipline=discipline)
-        mots_cles = simpleForm.cleaned_data["mots_cles"]
-        if mots_cles:
-            list = list.filter (personne__nom__icontains=mots_cles)
+        #mots_cles = simpleForm.cleaned_data["mots_cles"]
+        #if mots_cles:
+        #    list = list.filter (personne__nom__icontains=mots_cles)
     return list
     
 def repertoire(request):
@@ -51,7 +54,12 @@ def inscription(request):
         personne_form = PersonneForm (request.POST, prefix="personne")
         chercheur_form = ChercheurForm (request.POST, prefix="chercheur")
         etablissement_form = EtablissementForm (request.POST, prefix="etablissement")
+        etablissement_autre_form = EtablissementAutreForm(request.POST, prefix="etablissement_autre")
         discipline_form = DisciplineForm (request.POST, prefix="discipline")  
+        publication1_form = PublicationForm (request.POST, prefix="publication1")
+        publication2_form = PublicationForm (request.POST, prefix="publication2") 
+        publication3_form = PublicationForm (request.POST, prefix="publication3") 
+        publication4_form = PublicationForm (request.POST, prefix="publication4") 
         
         if personne_form.is_valid():
             if chercheur_form.is_valid():
@@ -60,22 +68,49 @@ def inscription(request):
                 etablissement_form = EtablissementForm (request.POST, prefix="etablissement", instance=c)
                 discipline_form = DisciplineForm (request.POST, prefix="discipline", instance=c)
                 
-                if etablissement_form.is_valid() and discipline_form.is_valid():          
-                    etablissement_form.save(commit=False)         
+                if etablissement_form.is_valid() and discipline_form.is_valid():       
+                    if publication1_form.is_valid() and publication1_form.cleaned_data['titre']:
+                       pub = publication1_form.save()
+                       c.publication1 = pub
+                    if publication2_form.is_valid() and publication2_form.cleaned_data['titre']:
+                       pub = publication2_form.save()
+                       c.publication2 = pub   
+                    if publication3_form.is_valid() and publication3_form.cleaned_data['titre']:
+                       pub = publication3_form.save()
+                       c.publication3 = pub    
+                    if publication4_form.is_valid() and publication4_form.cleaned_data['titre']:
+                       pub = publication4_form.save()
+                       c.publication4 = pub    
+                    etablissement_form.save(commit=False)
+                    etablissement_autre_form.save(commit=False)
                     discipline_form.save(commit=False)
+                    #encodage du mot de passe de l'utilisateur (refactorer car c'est pas clean
+                    #et c'est pas la bonne place pour faire ca - AJ
+                    personne_form.cleaned_data['password'] = hashlib.md5(personne_form.cleaned_data['password']).hexdigest()
                     p = personne_form.save()
                     c.personne = p
                     c.save()
+                    return HttpResponseRedirect(reverse('chercheurs.views.retrieve', args=(p.id,)))
     else:
         personne_form = PersonneForm(prefix="personne")
         chercheur_form = ChercheurForm(prefix="chercheur")
         etablissement_form = EtablissementForm(prefix="etablissement")
+        etablissement_autre_form = EtablissementAutreForm(prefix="etablissement_autre")
         discipline_form = DisciplineForm(prefix="discipline")
+        publication1_form = PublicationForm(prefix="publication1")
+        publication2_form = PublicationForm(prefix="publication2") 
+        publication3_form = PublicationForm(prefix="publication3") 
+        publication4_form = PublicationForm(prefix="publication4") 
     
     variables = { 'personne_form': personne_form,
                   'chercheur_form': chercheur_form,
                   'etablissement_form': etablissement_form,
                   'discipline_form': discipline_form,
+                  'etablissement_autre_form': etablissement_autre_form,
+                  'publication1_form': publication1_form,
+                  'publication2_form': publication2_form,
+                  'publication3_form': publication3_form,
+                  'publication4_form': publication4_form,
                 }
     
     return render_to_response ("chercheurs/inscription.html", \
@@ -88,13 +123,47 @@ def edit(request):
     context_instance = RequestContext(request)
     chercheur = context_instance['user_chercheur']    
     if request.method == 'POST':
-        personne_form = PersonneEditForm(request.POST, prefix="personne", instance=chercheur.personne)  
-        personne_form.save()
+        personne_form = PersonneEditForm(request.POST, prefix="personne", instance=chercheur.personne)
+        chercheur_form = ChercheurForm (request.POST, prefix="chercheur", instance=chercheur)
+        etablissement_form = EtablissementForm(request.POST, prefix="etablissement", instance=chercheur)
+        etablissement_autre_form = EtablissementAutreForm(request.POST, prefix="etablissement_autre", instance=chercheur)
+        discipline_form = DisciplineForm(request.POST, prefix="discipline", instance=chercheur)
+        publication1_form = PublicationForm(request.POST, prefix="publication1", instance=chercheur.publication1)
+        publication2_form = PublicationForm(request.POST, prefix="publication2", instance=chercheur.publication2) 
+        publication3_form = PublicationForm(request.POST, prefix="publication3", instance=chercheur.publication3) 
+        publication4_form = PublicationForm(request.POST, prefix="publication4", instance=chercheur.publication4)
+        
+
+        if( personne_form.is_valid() and discipline_form.is_valid() and publication1_form.is_valid() and publication2_form.is_valid() and publication3_form.is_valid() and publication4_form.is_valid() and chercheur_form.is_valid() ):
+            personne_form.save()
+            chercheur_form.save()
+            discipline_form.save()
+            publication1_form.save()
+            publication2_form.save()
+            publication3_form.save()
+            publication4_form.save()
     else:
-        personne_form = PersonneEditForm(prefix="personne", instance=chercheur.personne)        
+        personne_form = PersonneEditForm(prefix="personne", instance=chercheur.personne) 
+        chercheur_form = ChercheurForm (prefix="chercheur", instance=chercheur)
+        etablissement_form = EtablissementForm(prefix="etablissement", instance=chercheur)
+        etablissement_autre_form = EtablissementAutreForm(prefix="etablissement_autre", instance=chercheur)
+        discipline_form = DisciplineForm(prefix="discipline", instance=chercheur)
+        publication1_form = PublicationForm(prefix="publication1", instance=chercheur.publication1)
+        publication2_form = PublicationForm(prefix="publication2", instance=chercheur.publication2) 
+        publication3_form = PublicationForm(prefix="publication3", instance=chercheur.publication3) 
+        publication4_form = PublicationForm(prefix="publication4", instance=chercheur.publication4)    
+    #import pdb; pdb.set_trace()    
         
     variables = { 'chercheur': chercheur,
                   'personne_form':personne_form,
+                  'chercheur_form': chercheur_form,
+                  'etablissement_form': etablissement_form,
+                  'discipline_form': discipline_form,
+                  'etablissement_autre_form': etablissement_autre_form,
+                  'publication1_form': publication1_form,
+                  'publication2_form': publication2_form,
+                  'publication3_form': publication3_form,
+                  'publication4_form': publication4_form,
                 }
     return render_to_response ("chercheurs/edit.html", \
             Context (variables),