Supprimé des sources qui ne fonctionnent plus
[auf_savoirs_en_partage_django.git] / auf_savoirs_en_partage / savoirs / forms.py
CommitLineData
544b4522 1# -*- encoding: utf-8 -*-
ff753fa4
EMS
2
3from auf.django.references.models import Thematique, Pays, Region
544b4522 4from django import forms
0a95ac89 5from django.utils.safestring import mark_safe
ff753fa4
EMS
6
7from savoirs.models import \
8 Evenement, Discipline, RessourceSearch, ActualiteSearch, \
9 AppelSearch, EvenementSearch, Search, RecordCategorie
73309469 10from savoirs.admin import EvenementAdminForm
ff753fa4 11
da44ce68 12
7bbf600c
EMS
13# Modifications custom aux champs Django
14
15class SEPDateField(forms.DateField):
16 """Un champ de date avec des valeurs par défaut un peu modifiées."""
17
18 def __init__(self, *args, **kwargs):
0a8666f8 19 super(SEPDateField, self).__init__(self, *args, **kwargs)
7bbf600c
EMS
20
21 # La classe "date" active le datepicker dans sep.js
7bbf600c 22 # Nous recevons les dates en format français
0a8666f8 23 format = '%d/%m/%Y'
24 self.widget = forms.DateInput(attrs={'class': 'date'}, format=format)
fdcf5874 25 self.input_formats = [format]
bd4cf37b 26 self.help_text = 'format: jj/mm/aaaa'
7bbf600c 27
ff753fa4 28
0a95ac89 29class SEPSplitDateTimeWidget(forms.MultiWidget):
ff753fa4 30
0a95ac89
EMS
31 def __init__(self):
32 self.date_format = '%d/%m/%Y'
a9e7bae1 33 self.time_format = '%H:%M'
ff753fa4
EMS
34 widgets = (
35 forms.DateInput(attrs={'class': 'date'}, format=self.date_format),
36 forms.TimeInput(attrs={'class': 'time'}, format=self.time_format)
37 )
0a95ac89
EMS
38 super(SEPSplitDateTimeWidget, self).__init__(widgets)
39
40 def decompress(self, value):
41 if value:
42 return [value.date(), value.time().replace(microsecond=0)]
43 return [None, None]
44
45 def format_output(self, rendered_widgets):
ff753fa4
EMS
46 return mark_safe(
47 u'Date: %s Heure: %s' % (rendered_widgets[0], rendered_widgets[1])
48 )
49
0a95ac89
EMS
50
51class SEPDateTimeField(forms.DateTimeField):
52 widget = SEPSplitDateTimeWidget
53
a9e7bae1 54 def __init__(self, *args, **kwargs):
ff753fa4 55 super(SEPDateTimeField, self).__init__(
bd4cf37b
EMS
56 input_formats=['%d/%m/%Y %H:%M'],
57 help_text='format: jj/mm/aaaa'
ff753fa4
EMS
58 )
59
a9e7bae1 60
da44ce68 61# Formulaires de recherche
544b4522 62
fdcf5874 63class RessourceSearchForm(forms.ModelForm):
da44ce68
EMS
64 """Formulaire de recherche pour les ressources."""
65
fdcf5874
EMS
66 class Meta:
67 model = RessourceSearch
ff753fa4
EMS
68 fields = ['q', 'auteur', 'titre', 'sujet', 'publisher', 'categorie',
69 'discipline', 'region']
70
fdcf5874
EMS
71
72class RessourceSearchEditForm(RessourceSearchForm):
73 """Formulaire d'édition de recherche sauvegardée."""
c9cbc784 74
fdcf5874 75 class Meta(RessourceSearchForm.Meta):
4b89a7df 76 fields = ['nom', 'alerte_courriel'] + RessourceSearchForm.Meta.fields
fdcf5874 77
ff753fa4 78
fdcf5874
EMS
79class ActualiteSearchForm(forms.ModelForm):
80 """Formulaire de recherche pour les actualités."""
ff753fa4
EMS
81 date_min = SEPDateField(required=False, label="Depuis le")
82 date_max = SEPDateField(required=False, label="Jusqu'au")
fdcf5874
EMS
83
84 class Meta:
85 model = ActualiteSearch
86 fields = ['q', 'date_min', 'date_max', 'discipline', 'region']
ff753fa4
EMS
87
88
fdcf5874
EMS
89class ActualiteSearchEditForm(ActualiteSearchForm):
90
91 class Meta(ActualiteSearchForm.Meta):
4b89a7df 92 fields = ['nom', 'alerte_courriel'] + ActualiteSearchForm.Meta.fields
4101cfc0 93
ff753fa4 94
4bef5dc2
EMS
95class AppelSearchForm(forms.ModelForm):
96 """Formulaire de recherche pour les actualités."""
ff753fa4
EMS
97 date_min = SEPDateField(required=False, label="Depuis le")
98 date_max = SEPDateField(required=False, label="Jusqu'au")
4bef5dc2
EMS
99
100 class Meta:
101 model = AppelSearch
102 fields = ['q', 'date_min', 'date_max', 'discipline', 'region']
ff753fa4
EMS
103
104
4bef5dc2
EMS
105class AppelSearchEditForm(AppelSearchForm):
106
107 class Meta(AppelSearchForm.Meta):
4b89a7df 108 fields = ['nom', 'alerte_courriel'] + AppelSearchForm.Meta.fields
4bef5dc2 109
ff753fa4 110
fdcf5874
EMS
111class EvenementSearchForm(forms.ModelForm):
112 """Formulaire de recherche pour les évènements."""
ff753fa4
EMS
113 date_min = SEPDateField(required=False, label="Depuis le")
114 date_max = SEPDateField(required=False, label="Jusqu'au")
fdcf5874
EMS
115
116 class Meta:
117 model = EvenementSearch
118 fields = ['q', 'type', 'date_min', 'date_max', 'discipline', 'region']
119
ff753fa4 120
fdcf5874
EMS
121class EvenementSearchEditForm(EvenementSearchForm):
122
123 class Meta(EvenementSearchForm.Meta):
4b89a7df 124 fields = ['nom', 'alerte_courriel'] + EvenementSearchForm.Meta.fields
fdcf5874 125
ff753fa4 126
fdcf5874
EMS
127class SearchEditForm(forms.ModelForm):
128
129 class Meta:
130 model = Search
4101cfc0 131
ff753fa4 132
da44ce68 133###
544b4522 134
73309469 135class EvenementForm(EvenementAdminForm):
0a95ac89
EMS
136 debut = SEPDateTimeField()
137 fin = SEPDateTimeField()
69ad0029 138 description = forms.CharField(
fe254ccc 139 label='Description', required=True,
ff753fa4
EMS
140 help_text=(
141 "Présenter les thématiques de l'évènement et donner "
142 "toutes les informations utiles aux futurs participants."
143 ),
69ad0029
EMS
144 widget=forms.Textarea
145 )
92ec10ad 146 pays = forms.ModelChoiceField(
731ef7ab 147 queryset=Pays.objects.all(), required=True, label='Pays',
ff753fa4
EMS
148 help_text=(
149 "La sélection du pays entraine la saisie automatique "
150 "du fuseau horaire."
151 )
92ec10ad 152 )
73309469 153
92c7413b
CR
154 class Meta:
155 model = Evenement
731ef7ab 156 exclude = ('contact', 'approuve', 'uid', 'regions')
0a77a7d6 157
ff753fa4 158
0a77a7d6 159# Admin views pour les associations par lots
160
656b9c0f 161class CategorieForm(forms.Form):
bd599940 162 categorie = forms.ModelChoiceField(queryset=RecordCategorie.objects.all())
656b9c0f 163
ff753fa4 164
0a77a7d6 165class PaysForm(forms.Form):
17bf37f5 166 pays = forms.ModelMultipleChoiceField(queryset=Pays.objects.all())
0a77a7d6 167
ff753fa4 168
0a77a7d6 169class RegionsForm(forms.Form):
264a3210 170 regions = forms.ModelMultipleChoiceField(queryset=Region.objects.all())
0a77a7d6 171
ff753fa4 172
0a77a7d6 173class ThematiquesForm(forms.Form):
ff753fa4
EMS
174 thematiques = forms.ModelMultipleChoiceField(
175 queryset=Thematique.objects.all()
176 )
177
0a77a7d6 178
179class DisciplinesForm(forms.Form):
ff753fa4
EMS
180 disciplines = forms.ModelMultipleChoiceField(
181 queryset=Discipline.objects.all()
182 )
183
0a77a7d6 184
185class ConfirmationForm(forms.Form):
186 pass