recherche avec statut
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / chercheurs / forms.py
CommitLineData
932eef9a
AJ
1# -*- encoding: utf-8 -*-
2from django import forms
3from models import *
0e9597af 4from models import Utilisateur
6bd49ff1
AJ
5from savoirs.forms import SEPDateField
6from models import STATUT_CHOICES
13146d99 7
932eef9a 8class PersonneForm(forms.ModelForm):
c18af6bd
AJ
9 password = forms.CharField(widget=forms.PasswordInput(), label="Mot de passe")
10 genre = forms.ChoiceField(widget=forms.RadioSelect(), choices=GENRE_CHOICES)
932eef9a 11 class Meta:
dab519fa
AJ
12 model = Utilisateur
13 fields = ('nom', 'prenom', 'courriel', 'password', 'genre')
5ecd9e43 14
3eb00212
AJ
15class GroupeForm(forms.ModelForm):
16 class Meta:
17 model = Chercheur
18 fields = ('groupes',)
932eef9a
AJ
19
20class ChercheurForm(forms.ModelForm):
21 class Meta:
22 model = Chercheur
a4e383ac 23 fields = ('statut', 'diplome', )
7c596de2 24
00755d9b
AJ
25class PublicationForm(forms.ModelForm):
26 class Meta:
27 model = Publication
6befc7c9 28 fields = ('titre', 'annee', 'revue', 'editeur', 'lieu_edition', 'nb_pages', 'url')
f810842d
AJ
29
30class TheseForm(PublicationForm):
2a36714f 31 titre = forms.CharField(required=True, label="Titre de la thèse ou du mémoire")
a4e383ac 32 annee = forms.IntegerField(required=True, label="Année de soutenance (réalisée ou prévue)")
2a36714f
AJ
33 editeur = forms.CharField(required=False, label="Directeur de thèse")
34 lieu_edition = forms.CharField(required=False, label="Établissement de soutenance")
e8e9e4fd
AJ
35 class Meta:
36 model = Publication
2a36714f
AJ
37 fields = ('titre', 'annee', 'editeur', 'lieu_edition', 'nb_pages', 'url')
38
5b9abc81 39class ExpertiseForm(forms.ModelForm):
6bd49ff1 40 date = SEPDateField(required=False, label="Date")
5b9abc81
AJ
41 class Meta:
42 model = Expertise
43 fields = ('nom', 'date', 'organisme_demandeur', 'organisme_demandeur_visible')
dab519fa 44
7c596de2
AJ
45class EtablissementForm(forms.ModelForm):
46 class Meta:
47 model = Chercheur
48 fields = ('etablissement',)
a4e383ac 49 def clean(self):
6bd49ff1 50 cleaned_data = self.cleaned_data
a4e383ac
AJ
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")
a4e383ac 54 if statut == "enseignant":
6bd49ff1 55 if not etablissement and not etablissement_autre_nom:
a4e383ac 56 raise forms.ValidationError("")
6bd49ff1 57 return cleaned_data
7c596de2 58
00755d9b
AJ
59class EtablissementAutreForm(forms.ModelForm):
60 class Meta:
61 model = Chercheur
a4e383ac 62 fields = ('etablissement_autre_nom', 'etablissement_autre_pays' )
00755d9b 63
7c596de2
AJ
64class DisciplineForm(forms.ModelForm):
65 class Meta:
66 model = Chercheur
a4e383ac 67 fields = ('discipline', 'theme_recherche', 'mots_cles', 'url_site_web', 'url_blog',)
13146d99 68
b3e1079e
AJ
69class PersonneEditForm(forms.ModelForm):
70 class Meta:
71 model = Personne
72 fields = ('nom', 'prenom', 'genre')
5b9abc81 73
13146d99 74class RepertoireSearchForm (forms.Form):
0e9597af
AJ
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")
6bd49ff1 78 statut = forms.ChoiceField(choices=(('','Tous'),)+STATUT_CHOICES+(('expert','Expert'),), required=False, label="Statut")
0e9597af
AJ
79 pays = forms.ModelChoiceField(queryset=Pays.objects.all().order_by("nom"), required=False, label="Localisation", empty_label="Tous")
80
81class 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.")
e427f068
AJ
91 return email
92
93class 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
0e9597af 104