etablissement obligatoire
[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 etablissement = self.cleaned_data.get("etablissement")
52 etablissement_autre_nom = self.data.get("etablissement_autre-etablissement_autre_nom")
53 if not etablissement and not etablissement_autre_nom:
54 raise forms.ValidationError("")
55 return cleaned_data
56
57 class EtablissementAutreForm(forms.ModelForm):
58 class Meta:
59 model = Chercheur
60 fields = ('etablissement_autre_nom', 'etablissement_autre_pays' )
61
62 class DisciplineForm(forms.ModelForm):
63 class Meta:
64 model = Chercheur
65 fields = ('discipline', 'theme_recherche', 'mots_cles', 'url_site_web', 'url_blog',)
66
67 class PersonneEditForm(forms.ModelForm):
68 class Meta:
69 model = Personne
70 fields = ('nom', 'prenom', 'genre')
71
72 class RepertoireSearchForm (forms.Form):
73 mots_cles = forms.CharField (required = False, label="Mots-clés")
74 discipline = forms.ModelChoiceField(queryset=Discipline.objects.all(), required=False, label="Discipline", empty_label="Tous")
75 domaine = forms.ModelChoiceField(queryset=Groupe.objects.all(), required=False, label="Domaine de recherche", empty_label="Tous")
76 statut = forms.ChoiceField(choices=(('','Tous'),)+STATUT_CHOICES+(('expert','Expert'),), required=False, label="Statut")
77 pays = forms.ModelChoiceField(queryset=Pays.objects.all().order_by("nom"), required=False, label="Localisation", empty_label="Tous")
78
79 class SendPasswordForm(forms.Form):
80 email = forms.EmailField(required=True, label="courriel")
81 def clean_email(self):
82 cleaned_data = self.cleaned_data
83 email = cleaned_data.get("email")
84 if email:
85 try:
86 Utilisateur.objects.get(courriel=email)
87 except:
88 raise forms.ValidationError("Ce courriel n'existe pas dans notre base de données.")
89 return email
90
91 class NewPasswordForm(forms.Form):
92 password = forms.CharField(widget=forms.PasswordInput(), required=True, label="Mot de passe")
93 password_repeat = forms.CharField(widget=forms.PasswordInput(), required=True, label="Confirmez mot de passe")
94 def clean_password_repeat(self):
95 cleaned_data = self.cleaned_data
96 password = cleaned_data.get("password")
97 password_repeat = cleaned_data.get("password_repeat")
98 if password and password_repeat:
99 if password != password_repeat:
100 raise forms.ValidationError("Les mots de passe ne concordent pas")
101 return password_repeat
102