Remplacé les champs Facebook et LinkedIn pour un champ "Réseau social" dans la
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / chercheurs / forms.py
CommitLineData
932eef9a
AJ
1# -*- encoding: utf-8 -*-
2from django import forms
3efbacbe 3from django.db.models import Q
932eef9a 4from models import *
6bd49ff1 5from savoirs.forms import SEPDateField
13146d99 6
932eef9a 7class PersonneForm(forms.ModelForm):
c18af6bd
AJ
8 password = forms.CharField(widget=forms.PasswordInput(), label="Mot de passe")
9 genre = forms.ChoiceField(widget=forms.RadioSelect(), choices=GENRE_CHOICES)
932eef9a 10 class Meta:
dab519fa
AJ
11 model = Utilisateur
12 fields = ('nom', 'prenom', 'courriel', 'password', 'genre')
5ecd9e43 13
3eb00212
AJ
14class GroupeForm(forms.ModelForm):
15 class Meta:
16 model = Chercheur
17 fields = ('groupes',)
932eef9a
AJ
18
19class ChercheurForm(forms.ModelForm):
20 class Meta:
21 model = Chercheur
a4e383ac 22 fields = ('statut', 'diplome', )
7c596de2 23
00755d9b
AJ
24class PublicationForm(forms.ModelForm):
25 class Meta:
26 model = Publication
6befc7c9 27 fields = ('titre', 'annee', 'revue', 'editeur', 'lieu_edition', 'nb_pages', 'url')
f810842d
AJ
28
29class TheseForm(PublicationForm):
2a36714f 30 titre = forms.CharField(required=True, label="Titre de la thèse ou du mémoire")
a4e383ac 31 annee = forms.IntegerField(required=True, label="Année de soutenance (réalisée ou prévue)")
2a36714f
AJ
32 editeur = forms.CharField(required=False, label="Directeur de thèse")
33 lieu_edition = forms.CharField(required=False, label="Établissement de soutenance")
e8e9e4fd
AJ
34 class Meta:
35 model = Publication
2a36714f
AJ
36 fields = ('titre', 'annee', 'editeur', 'lieu_edition', 'nb_pages', 'url')
37
5b9abc81 38class ExpertiseForm(forms.ModelForm):
6bd49ff1 39 date = SEPDateField(required=False, label="Date")
5b9abc81
AJ
40 class Meta:
41 model = Expertise
42 fields = ('nom', 'date', 'organisme_demandeur', 'organisme_demandeur_visible')
dab519fa 43
7c596de2
AJ
44class EtablissementForm(forms.ModelForm):
45 class Meta:
46 model = Chercheur
47 fields = ('etablissement',)
a4e383ac 48 def clean(self):
6bd49ff1 49 cleaned_data = self.cleaned_data
a4e383ac
AJ
50 etablissement = self.cleaned_data.get("etablissement")
51 etablissement_autre_nom = self.data.get("etablissement_autre-etablissement_autre_nom")
7f89d0b4
AJ
52 if not etablissement and not etablissement_autre_nom:
53 raise forms.ValidationError("")
6bd49ff1 54 return cleaned_data
7c596de2 55
00755d9b
AJ
56class EtablissementAutreForm(forms.ModelForm):
57 class Meta:
58 model = Chercheur
a4e383ac 59 fields = ('etablissement_autre_nom', 'etablissement_autre_pays' )
00755d9b 60
7c596de2
AJ
61class DisciplineForm(forms.ModelForm):
62 class Meta:
63 model = Chercheur
3c576696 64 fields = ('discipline', 'theme_recherche', 'mots_cles', 'url_site_web', 'url_blog', 'url_reseau_social')
13146d99 65
b3e1079e
AJ
66class PersonneEditForm(forms.ModelForm):
67 class Meta:
68 model = Personne
69 fields = ('nom', 'prenom', 'genre')
5b9abc81 70
13146d99 71class RepertoireSearchForm (forms.Form):
c56d992d 72 mots_cles = forms.CharField(required=False, label="Rechercher dans tous les champs")
3efbacbe 73 nom = forms.CharField(required=False, label="Nom")
0e9597af
AJ
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")
6bd49ff1 76 statut = forms.ChoiceField(choices=(('','Tous'),)+STATUT_CHOICES+(('expert','Expert'),), required=False, label="Statut")
0e9597af
AJ
77 pays = forms.ModelChoiceField(queryset=Pays.objects.all().order_by("nom"), required=False, label="Localisation", empty_label="Tous")
78
3efbacbe
EMS
79 def get_query_set(self):
80 qs = Chercheur.objects.all()
81 if self.is_valid():
82 nom = self.cleaned_data['nom']
83 if nom:
84 qs = qs.search_nom(nom)
85 pays = self.cleaned_data["pays"]
86 if pays:
87 qs = qs.filter(Q(etablissement__pays = pays.pk) | Q(etablissement_autre_pays = pays.pk))
88 discipline = self.cleaned_data["discipline"]
89 if discipline:
90 qs = qs.filter(discipline=discipline)
91 domaine = self.cleaned_data["domaine"]
92 if domaine:
93 qs = qs.filter(groupes=domaine)
94 mots_cles = self.cleaned_data["mots_cles"]
95 if mots_cles:
96 qs = qs.search(mots_cles)
97 statut = self.cleaned_data["statut"]
98 if statut:
99 if statut == "expert":
100 qs = qs.exclude(expertise=None)
101 else:
102 qs = qs.filter(statut=statut)
103 return qs
104
0e9597af
AJ
105class SendPasswordForm(forms.Form):
106 email = forms.EmailField(required=True, label="courriel")
107 def clean_email(self):
108 cleaned_data = self.cleaned_data
109 email = cleaned_data.get("email")
110 if email:
111 try:
112 Utilisateur.objects.get(courriel=email)
113 except:
114 raise forms.ValidationError("Ce courriel n'existe pas dans notre base de données.")
e427f068
AJ
115 return email
116
117class NewPasswordForm(forms.Form):
118 password = forms.CharField(widget=forms.PasswordInput(), required=True, label="Mot de passe")
119 password_repeat = forms.CharField(widget=forms.PasswordInput(), required=True, label="Confirmez mot de passe")
120 def clean_password_repeat(self):
121 cleaned_data = self.cleaned_data
122 password = cleaned_data.get("password")
123 password_repeat = cleaned_data.get("password_repeat")
124 if password and password_repeat:
125 if password != password_repeat:
126 raise forms.ValidationError("Les mots de passe ne concordent pas")
127 return password_repeat
0e9597af 128