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
1 # -*- encoding: utf-8 -*-
2 from django import forms
3 from django.db.models import Q
4 from models import *
5 from savoirs.forms import SEPDateField
6
7 class PersonneForm(forms.ModelForm):
8 password = forms.CharField(widget=forms.PasswordInput(), label="Mot de passe")
9 genre = forms.ChoiceField(widget=forms.RadioSelect(), choices=GENRE_CHOICES)
10 class Meta:
11 model = Utilisateur
12 fields = ('nom', 'prenom', 'courriel', 'password', 'genre')
13
14 class GroupeForm(forms.ModelForm):
15 class Meta:
16 model = Chercheur
17 fields = ('groupes',)
18
19 class ChercheurForm(forms.ModelForm):
20 class Meta:
21 model = Chercheur
22 fields = ('statut', 'diplome', )
23
24 class PublicationForm(forms.ModelForm):
25 class Meta:
26 model = Publication
27 fields = ('titre', 'annee', 'revue', 'editeur', 'lieu_edition', 'nb_pages', 'url')
28
29 class TheseForm(PublicationForm):
30 titre = forms.CharField(required=True, label="Titre de la thèse ou du mémoire")
31 annee = forms.IntegerField(required=True, label="Année de soutenance (réalisée ou prévue)")
32 editeur = forms.CharField(required=False, label="Directeur de thèse")
33 lieu_edition = forms.CharField(required=False, label="Établissement de soutenance")
34 class Meta:
35 model = Publication
36 fields = ('titre', 'annee', 'editeur', 'lieu_edition', 'nb_pages', 'url')
37
38 class ExpertiseForm(forms.ModelForm):
39 date = SEPDateField(required=False, label="Date")
40 class Meta:
41 model = Expertise
42 fields = ('nom', 'date', 'organisme_demandeur', 'organisme_demandeur_visible')
43
44 class EtablissementForm(forms.ModelForm):
45 class Meta:
46 model = Chercheur
47 fields = ('etablissement',)
48 def clean(self):
49 cleaned_data = self.cleaned_data
50 etablissement = self.cleaned_data.get("etablissement")
51 etablissement_autre_nom = self.data.get("etablissement_autre-etablissement_autre_nom")
52 if not etablissement and not etablissement_autre_nom:
53 raise forms.ValidationError("")
54 return cleaned_data
55
56 class EtablissementAutreForm(forms.ModelForm):
57 class Meta:
58 model = Chercheur
59 fields = ('etablissement_autre_nom', 'etablissement_autre_pays' )
60
61 class DisciplineForm(forms.ModelForm):
62 class Meta:
63 model = Chercheur
64 fields = ('discipline', 'theme_recherche', 'mots_cles', 'url_site_web', 'url_blog', 'url_reseau_social')
65
66 class PersonneEditForm(forms.ModelForm):
67 class Meta:
68 model = Personne
69 fields = ('nom', 'prenom', 'genre')
70
71 class RepertoireSearchForm (forms.Form):
72 mots_cles = forms.CharField(required=False, label="Rechercher dans tous les champs")
73 nom = forms.CharField(required=False, label="Nom")
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 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
105 class 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.")
115 return email
116
117 class 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
128