Embryon de recherche pour les ressources.
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / savoirs / forms.py
1 # -*- encoding: utf-8 -*-
2 from django import forms
3 from datamaster_modeles.models import Thematique, Pays, Region
4 from models import Evenement, Discipline, Record
5
6 # Formulaires de recherche
7
8 class RechercheAvancee (forms.Form):
9 creator = forms.CharField (max_length=60, required=False, \
10 label = "Auteur ou contributeur") # + contributor
11 title = forms.CharField (max_length=100, required=False, \
12 label = "Titre") # + alt_title
13 description = forms.CharField (max_length=100, required=False, \
14 label = "Description ou résumé") # + abstract
15 subject = forms.CharField (max_length=100, required=False, label = "Sujet")
16 operator = forms.ChoiceField (choices = (('or', 'ou'), ('and', 'et')), label = "Operateur")
17 type = forms.CharField (initial='avancee', required=False, widget=forms.HiddenInput)
18
19 class RecordSearchForm(forms.Form):
20 """Formulaire de recherche pour les ressources."""
21
22 q = forms.CharField(required=False, label="Mots-clés")
23
24 def get_query_set(self):
25 """Retourne l'ensemble des ressources qui correspondent aux valeurs
26 entrées dans le formulaire."""
27 records = Record.objects.all()
28 if self.is_valid():
29 query = self.cleaned_data['q']
30 if query:
31 records = records.search(query)
32 return records
33
34 ###
35
36 class EvenementForm(forms.ModelForm):
37 class Meta:
38 model = Evenement
39 exclude = ('approuve', 'uid')
40
41 # Admin views pour les associations par lots
42
43 class PaysForm(forms.Form):
44 values = [(p.id, p.nom) for p in Pays.objects.all()]
45 pays = forms.MultipleChoiceField(choices=values)
46
47 class RegionsForm(forms.Form):
48 values = [(r.id, r.nom) for r in Region.objects.all()]
49 regions = forms.MultipleChoiceField(choices=values)
50
51 class ThematiquesForm(forms.Form):
52 values = [(t.id, t.nom) for t in Thematique.objects.all()]
53 thematiques = forms.MultipleChoiceField(choices=values)
54
55 class DisciplinesForm(forms.Form):
56 values = [(t.id, t.nom) for t in Discipline.objects.all()]
57 disciplines = forms.MultipleChoiceField(choices=values)
58
59 class ConfirmationForm(forms.Form):
60 pass
61