expertis e dans chercheurs
[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
6 class PersonneForm(forms.ModelForm):
7 password = forms.CharField(widget=forms.PasswordInput(), label="Mot de passe")
8 genre = forms.ChoiceField(widget=forms.RadioSelect(), choices=GENRE_CHOICES)
9 class Meta:
10 model = Utilisateur
11 fields = ('nom', 'prenom', 'courriel', 'password', 'genre')
12
13 class GroupeForm(forms.ModelForm):
14 class Meta:
15 model = Chercheur
16 fields = ('groupes',)
17
18 class ChercheurForm(forms.ModelForm):
19 class Meta:
20 model = Chercheur
21 fields = ('fonction', 'diplome',)
22
23 class PublicationForm(forms.ModelForm):
24 class Meta:
25 model = Publication
26 fields = ('titre', 'annee', 'revue', 'editeur', 'lieu_edition', 'nb_pages', 'url')
27
28 class TheseForm(PublicationForm):
29 titre = forms.CharField(required=True, label="Titre de la thèse ou du mémoire")
30 annee = forms.IntegerField(required=False, label="Année de soutenance")
31 editeur = forms.CharField(required=False, label="Directeur de thèse")
32 lieu_edition = forms.CharField(required=False, label="Établissement de soutenance")
33 class Meta:
34 model = Publication
35 fields = ('titre', 'annee', 'editeur', 'lieu_edition', 'nb_pages', 'url')
36
37
38
39 class EtablissementForm(forms.ModelForm):
40 class Meta:
41 model = Chercheur
42 fields = ('etablissement',)
43
44 class EtablissementAutreForm(forms.ModelForm):
45 class Meta:
46 model = Chercheur
47 fields = ('etablissement_autre_nom', 'etablissement_autre_pays', )
48
49 class DisciplineForm(forms.ModelForm):
50 class Meta:
51 model = Chercheur
52 fields = ('discipline', 'expertise', 'mots_cles', 'url_site_web', 'url_blog', 'url_facebook', 'url_linkedin')
53
54 class PersonneEditForm(forms.ModelForm):
55 class Meta:
56 model = Personne
57 fields = ('nom', 'prenom', 'genre')
58
59
60 class RepertoireSearchForm (forms.Form):
61 mots_cles = forms.CharField (required = False, label="Mots-clés")
62 discipline = forms.ModelChoiceField(queryset=Discipline.objects.all(), required=False, label="Discipline", empty_label="Tous")
63 domaine = forms.ModelChoiceField(queryset=Groupe.objects.all(), required=False, label="Domaine de recherche", empty_label="Tous")
64 fonction = forms.ChoiceField(choices=(('','Tous'),)+FONCTION_CHOICES, required=False, label="Fonction")
65 pays = forms.ModelChoiceField(queryset=Pays.objects.all().order_by("nom"), required=False, label="Localisation", empty_label="Tous")
66
67 class SendPasswordForm(forms.Form):
68 email = forms.EmailField(required=True, label="courriel")
69 def clean_email(self):
70 cleaned_data = self.cleaned_data
71 email = cleaned_data.get("email")
72 if email:
73 try:
74 Utilisateur.objects.get(courriel=email)
75 except:
76 raise forms.ValidationError("Ce courriel n'existe pas dans notre base de données.")
77 return email
78
79 class NewPasswordForm(forms.Form):
80 password = forms.CharField(widget=forms.PasswordInput(), required=True, label="Mot de passe")
81 password_repeat = forms.CharField(widget=forms.PasswordInput(), required=True, label="Confirmez mot de passe")
82 def clean_password_repeat(self):
83 cleaned_data = self.cleaned_data
84 password = cleaned_data.get("password")
85 password_repeat = cleaned_data.get("password_repeat")
86 if password and password_repeat:
87 if password != password_repeat:
88 raise forms.ValidationError("Les mots de passe ne concordent pas")
89 return password_repeat
90