Revision 3e9b47e9
Added by Benjamin Dauvergne over 12 years ago
calebasse/agenda/views.py | ||
---|---|---|
19 | 19 |
from calebasse.actes.validation import (automated_validation, unlock_all_acts_of_the_day) |
20 | 20 |
from calebasse import cbv |
21 | 21 |
|
22 |
from forms import (NewAppointmentForm, NewEventForm, UpdateAppointmentForm, UpdateEventForm) |
|
22 |
from forms import (NewAppointmentForm, NewEventForm, |
|
23 |
UpdateAppointmentForm, UpdateEventForm) |
|
24 |
|
|
23 | 25 |
|
24 | 26 |
def redirect_today(request, service): |
25 | 27 |
'''If not date is given we redirect on the agenda for today''' |
26 | 28 |
return redirect('agenda', date=datetime.date.today().strftime('%Y-%m-%d'), |
27 | 29 |
service=service) |
28 | 30 |
|
29 |
class AgendaHomepageView(TemplateView): |
|
30 | 31 |
|
32 |
class AgendaHomepageView(TemplateView): |
|
31 | 33 |
template_name = 'agenda/index.html' |
32 | 34 |
|
33 | 35 |
def post(self, request, *args, **kwargs): |
... | ... | |
62 | 64 |
|
63 | 65 |
return context |
64 | 66 |
|
65 |
class AgendaServiceActivityView(TemplateView): |
|
66 | 67 |
|
68 |
class AgendaServiceActivityView(TemplateView): |
|
67 | 69 |
template_name = 'agenda/service-activity.html' |
68 | 70 |
|
69 | 71 |
def get_context_data(self, **kwargs): |
... | ... | |
117 | 119 |
class NewAppointmentView(cbv.ReturnToObjectMixin, cbv.ServiceFormMixin, CreateView): |
118 | 120 |
model = EventWithAct |
119 | 121 |
form_class = NewAppointmentForm |
120 |
template_name = 'agenda/nouveau-rdv.html'
|
|
122 |
template_name = 'agenda/new-appointment.html'
|
|
121 | 123 |
success_url = '..' |
122 | 124 |
|
123 | 125 |
def get_initial(self): |
... | ... | |
134 | 136 |
kwargs['service'] = self.service |
135 | 137 |
return kwargs |
136 | 138 |
|
139 |
|
|
137 | 140 |
class TodayOccurrenceMixin(object): |
138 | 141 |
def get_object(self, queryset=None): |
139 | 142 |
o = super(TodayOccurrenceMixin, self).get_object(queryset) |
140 | 143 |
return o.today_occurrence(self.date) |
141 | 144 |
|
142 |
class UpdateAppointmentView(TodayOccurrenceMixin, UpdateView): |
|
145 |
|
|
146 |
class BaseAppointmentView(UpdateView): |
|
143 | 147 |
model = EventWithAct |
144 | 148 |
form_class = UpdateAppointmentForm |
145 | 149 |
template_name = 'agenda/update-rdv.html' |
146 | 150 |
success_url = '..' |
147 | 151 |
|
148 | 152 |
def get_initial(self): |
149 |
initial = super(UpdateView, self).get_initial()
|
|
153 |
initial = super(BaseAppointmentView, self).get_initial()
|
|
150 | 154 |
initial['start_datetime'] = self.date |
151 | 155 |
initial['date'] = self.object.start_datetime.date() |
152 | 156 |
initial['time'] = self.object.start_datetime.time() |
... | ... | |
160 | 164 |
return initial |
161 | 165 |
|
162 | 166 |
def get_form_kwargs(self): |
163 |
kwargs = super(UpdateAppointmentView, self).get_form_kwargs()
|
|
167 |
kwargs = super(BaseAppointmentView, self).get_form_kwargs()
|
|
164 | 168 |
kwargs['service'] = self.service |
165 | 169 |
return kwargs |
166 | 170 |
|
167 | 171 |
|
172 |
class UpdateAppointmentView(TodayOccurrenceMixin, BaseAppointmentView): |
|
173 |
pass |
|
174 |
|
|
175 |
|
|
176 |
class UpdatePeriodicAppointmentView(BaseAppointmentView): |
|
177 |
form_class = NewAppointmentForm |
|
178 |
template_name = 'agenda/new-appointment.html' |
|
179 |
|
|
180 |
|
|
168 | 181 |
class NewEventView(CreateView): |
169 | 182 |
model = Event |
170 | 183 |
form_class = NewEventForm |
... | ... | |
187 | 200 |
return kwargs |
188 | 201 |
|
189 | 202 |
|
190 |
class UpdateEventView(TodayOccurrenceMixin, UpdateView):
|
|
203 |
class BaseEventView(UpdateView):
|
|
191 | 204 |
model = Event |
192 | 205 |
form_class = UpdateEventForm |
193 | 206 |
template_name = 'agenda/update-event.html' |
194 | 207 |
success_url = '..' |
195 | 208 |
|
196 | 209 |
def get_initial(self): |
197 |
initial = super(UpdateEventView, self).get_initial()
|
|
210 |
initial = super(BaseEventView, self).get_initial()
|
|
198 | 211 |
initial['start_datetime'] = self.date |
199 | 212 |
initial['date'] = self.object.start_datetime.date() |
200 | 213 |
initial['time'] = self.object.start_datetime.time() |
... | ... | |
208 | 221 |
return initial |
209 | 222 |
|
210 | 223 |
def get_form_kwargs(self): |
211 |
kwargs = super(UpdateEventView, self).get_form_kwargs()
|
|
224 |
kwargs = super(BaseEventView, self).get_form_kwargs()
|
|
212 | 225 |
kwargs['service'] = self.service |
213 | 226 |
return kwargs |
214 | 227 |
|
228 |
|
|
229 |
class UpdateEventView(TodayOccurrenceMixin, BaseEventView): |
|
230 |
pass |
|
231 |
|
|
232 |
|
|
233 |
class UpdatePeriodicEventView(BaseEventView): |
|
234 |
form_class = NewEventForm |
|
235 |
template_name = 'agenda/new-event.html' |
|
236 |
|
|
237 |
|
|
215 | 238 |
class DeleteEventView(TodayOccurrenceMixin, cbv.DeleteView): |
216 | 239 |
model = Event |
217 | 240 |
success_url = '..' |
... | ... | |
220 | 243 |
super(DeleteEventView, self).delete(request, *args, **kwargs) |
221 | 244 |
return HttpResponse(status=204) |
222 | 245 |
|
246 |
|
|
223 | 247 |
class AgendaServiceActValidationView(TemplateView): |
224 | 248 |
template_name = 'agenda/act-validation.html' |
225 | 249 |
|
Also available in: Unified diff
agenda: add editing of periodic events