recherche avec statut
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / chercheurs / forms.py
1 # -*- encoding: utf-8 -*-
2 from django import forms
3 from models import *
4 from models import Utilisateur
5 from savoirs.forms import SEPDateField
6 from models import STATUT_CHOICES
7
8 class PersonneForm(forms.ModelForm):
9 password = forms.CharField(widget=forms.PasswordInput(), label="Mot de passe")
10 genre = forms.ChoiceField(widget=forms.RadioSelect(), choices=GENRE_CHOICES)
11 class Meta:
12 model = Utilisateur
13 fields = ('nom', 'prenom', 'courriel', 'password', 'genre')
14
15 class GroupeForm(forms.ModelForm):
16 class Meta:
17 model = Chercheur
18 fields = ('groupes',)
19
20 class ChercheurForm(forms.ModelForm):
21 class Meta:
22 model = Chercheur
23 fields = ('statut', 'diplome', )
24
25 class PublicationForm(forms.ModelForm):
26 class Meta:
27 model = Publication
28 fields = ('titre', 'annee', 'revue', 'editeur', 'lieu_edition', 'nb_pages', 'url')
29
30 class TheseForm(PublicationForm):
31 titre = forms.CharField(required=True, label="Titre de la thèse ou du mémoire")
32 annee = forms.IntegerField(required=True, label="Année de soutenance (réalisée ou prévue)")
33 editeur = forms.CharField(required=False, label="Directeur de thèse")
34 lieu_edition = forms.CharField(required=False, label="Établissement de soutenance")
35 class Meta:
36 model = Publication
37 fields = ('titre', 'annee', 'editeur', 'lieu_edition', 'nb_pages', 'url')
38
39 class ExpertiseForm(forms.ModelForm):
40 date = SEPDateField(required=False, label="Date")
41 class Meta:
42 model = Expertise
43 fields = ('nom', 'date', 'organisme_demandeur', 'organisme_demandeur_visible')
44
45 class EtablissementForm(forms.ModelForm):
46 class Meta:
47 model = Chercheur
48 fields = ('etablissement',)
49 def clean(self):
50 cleaned_data = self.cleaned_data
51 statut = self.data.get('chercheur-statut')
52 etablissement = self.cleaned_data.get("etablissement")
53 etablissement_autre_nom = self.data.get("etablissement_autre-etablissement_autre_nom")
54 if statut == "enseignant":
55 if not etablissement and not etablissement_autre_nom:
56 raise forms.ValidationError("")
57 return cleaned_data
58
59 class EtablissementAutreForm(forms.ModelForm):
60 class Meta:
61 model = Chercheur
62 fields = ('etablissement_autre_nom', 'etablissement_autre_pays' )
63
64 class DisciplineForm(forms.ModelForm):
65 class Meta:
66 model = Chercheur
67 fields = ('discipline', 'theme_recherche', 'mots_cles', 'url_site_web', 'url_blog',)
68
69 class PersonneEditForm(forms.ModelForm):
70 class Meta:
71 model = Personne
72 fields = ('nom', 'prenom', 'genre')
73
74 class RepertoireSearchForm (forms.Form):
75 mots_cles = forms.CharField (required = False, label="Mots-clés")
76 discipline = forms.ModelChoiceField(queryset=Discipline.objects.all(), required=False, label="Discipline", empty_label="Tous")
77 domaine = forms.ModelChoiceField(queryset=Groupe.objects.all(), required=False, label="Domaine de recherche", empty_label="Tous")
78 statut = forms.ChoiceField(choices=(('','Tous'),)+STATUT_CHOICES+(('expert','Expert'),), required=False, label="Statut")
79 pays = forms.ModelChoiceField(queryset=Pays.objects.all().order_by("nom"), required=False, label="Localisation", empty_label="Tous")
80
81 class SendPasswordForm(forms.Form):
82 email = forms.EmailField(required=True, label="courriel")
83 def clean_email(self):
84 cleaned_data = self.cleaned_data
85 email = cleaned_data.get("email")
86 if email:
87 try:
88 Utilisateur.objects.get(courriel=email)
89 except:
90 raise forms.ValidationError("Ce courriel n'existe pas dans notre base de données.")
91 return email
92
93 class NewPasswordForm(forms.Form):
94 password = forms.CharField(widget=forms.PasswordInput(), required=True, label="Mot de passe")
95 password_repeat = forms.CharField(widget=forms.PasswordInput(), required=True, label="Confirmez mot de passe")
96 def clean_password_repeat(self):
97 cleaned_data = self.cleaned_data
98 password = cleaned_data.get("password")
99 password_repeat = cleaned_data.get("password_repeat")
100 if password and password_repeat:
101 if password != password_repeat:
102 raise forms.ValidationError("Les mots de passe ne concordent pas")
103 return password_repeat
104