Expertise
[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 = ('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 (réalisée ou prévue)")
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 class ExpertiseForm(forms.ModelForm):
38 class Meta:
39 model = Expertise
40 fields = ('nom', 'date', 'organisme_demandeur', 'organisme_demandeur_visible')
41
42 class EtablissementForm(forms.ModelForm):
43 class Meta:
44 model = Chercheur
45 fields = ('etablissement',)
46
47 class EtablissementAutreForm(forms.ModelForm):
48 class Meta:
49 model = Chercheur
50 fields = ('etablissement_autre_nom', 'etablissement_autre_pays', 'enseignant' )
51
52 class DisciplineForm(forms.ModelForm):
53 class Meta:
54 model = Chercheur
55 fields = ('discipline', 'theme_recherche', 'mots_cles', 'url_site_web', 'url_blog', 'url_facebook', 'url_linkedin')
56
57 class PersonneEditForm(forms.ModelForm):
58 class Meta:
59 model = Personne
60 fields = ('nom', 'prenom', 'genre')
61
62 class RepertoireSearchForm (forms.Form):
63 mots_cles = forms.CharField (required = False, label="Mots-clés")
64 discipline = forms.ModelChoiceField(queryset=Discipline.objects.all(), required=False, label="Discipline", empty_label="Tous")
65 domaine = forms.ModelChoiceField(queryset=Groupe.objects.all(), required=False, label="Domaine de recherche", empty_label="Tous")
66 #fonction = forms.ChoiceField(choices=(('','Tous'),)+FONCTION_CHOICES, required=False, label="Fonction")
67 pays = forms.ModelChoiceField(queryset=Pays.objects.all().order_by("nom"), required=False, label="Localisation", empty_label="Tous")
68
69 class SendPasswordForm(forms.Form):
70 email = forms.EmailField(required=True, label="courriel")
71 def clean_email(self):
72 cleaned_data = self.cleaned_data
73 email = cleaned_data.get("email")
74 if email:
75 try:
76 Utilisateur.objects.get(courriel=email)
77 except:
78 raise forms.ValidationError("Ce courriel n'existe pas dans notre base de données.")
79 return email
80
81 class NewPasswordForm(forms.Form):
82 password = forms.CharField(widget=forms.PasswordInput(), required=True, label="Mot de passe")
83 password_repeat = forms.CharField(widget=forms.PasswordInput(), required=True, label="Confirmez mot de passe")
84 def clean_password_repeat(self):
85 cleaned_data = self.cleaned_data
86 password = cleaned_data.get("password")
87 password_repeat = cleaned_data.get("password_repeat")
88 if password and password_repeat:
89 if password != password_repeat:
90 raise forms.ValidationError("Les mots de passe ne concordent pas")
91 return password_repeat
92