Project

General

Profile

« Previous | Next » 

Revision 8da5a7b6

Added by Serghei Mihai almost 11 years ago

prototype of editing group absences

View differences:

calebasse/personnes/views.py
270 270
                    service=self.service.slug, pk=holiday.worker.pk))
271 271
            else:
272 272
                slug = holiday.service.slug if holiday.service else self.service.slug
273
                return reverse('group-holiday-update', kwargs=dict(
273
                return reverse('group-holidays', kwargs=dict(
274 274
                    service=slug))
275 275

  
276 276
        currents = []
......
325 325

  
326 326
group_holiday_update = GroupHolidayUpdateView.as_view()
327 327

  
328
# ===================================================================
329

  
330
class GroupHolidaysList(cbv.ListView):
331
    model = models.Holiday
332
    template_name = 'personnes/group_holidays_list.html'
333
    queryset = model.objects.future()
334

  
335
group_holidays = GroupHolidaysList.as_view()
336

  
337
class CreateGroupHolidayView(cbv.CreateView):
338
    form_class = forms.GroupHolidayForm
339
    model = models.Holiday
340

  
341
    def post(self, request, *args, **kwargs):
342
        # créer l'objet
343
        pass
344

  
345
create_group_holiday = CreateGroupHolidayView.as_view()
346

  
347
class EditGroupHolidayView(cbv.FormView):
348
    template_name = 'personnes/group_holiday_update_form.html'
349
    form_class = forms.GroupHolidayForm
350
    model = models.Holiday
351

  
352
    def get_form_kwargs(self):
353
        kwargs = super(EditGroupHolidayView, self).get_form_kwargs()
354
        kwargs['instance'] = self.model.objects.get(pk = self.kwargs['pk'])
355
        print kwargs['instance'].service
356
        return kwargs
357

  
358
    def post(self, request, *args, **kwargs):
359
        return super(EditGroupHolidayView, self).post(request, *args, **kwargs)
360

  
361
edit_group_holiday = EditGroupHolidayView.as_view()
362

  
363
class DeleteGroupHolidayView(cbv.DeleteView):
364
    model = models.Holiday
365
    template_name = 'personnes/group_holiday_update_form.html'
366
    success_url = '.'
367

  
368
    def delete(self, request, *args, **kwargs):
369
        response = HttpResponse('', content_type = 'application/json')
370
        context = {'err': 0, 'message': ''}
371
        try:
372
            super(DeleteGroupHolidayView, self).delete(request, *args, **kwargs)
373
        except Exception, e:
374
            context['message'] = '%s' % e
375
        response.content = json.dumps(context)
376
        return response
377

  
378
delete_group_holiday = DeleteGroupHolidayView.as_view()
379

  
328 380
class HolidayManagement(object):
329 381

  
330 382
    def render_to_json(self, id, context, err = 0, **kwargs):
......
363 415
    model = models.Holiday
364 416
    form_class = forms.HolidayForm
365 417

  
366
    def get_form_kwargs(self, *args, **kwargs):
367
        kwargs = super(HolidayCreateView, self).get_form_kwargs(*args, **kwargs)
368
        return kwargs
369

  
370 418
    def post(self, request, *args, **kwargs):
371 419
        worker, post = self.update_post_data(request)
372 420
        form = self.form_class(post)
......
405 453

  
406 454
    def post(self, request, *args, **kwargs):
407 455
        response = HttpResponse('', content_type = 'application/json')
408
        context = {'err': 0, }
456
        context = {'err': 0, 'message': ''}
409 457
        try:
410
            worker = models.Worker.objects.get(pk = self.kwargs['worker_pk'])
411
            self.model.objects.for_worker(worker).get(pk = self.kwargs['pk']).delete()
458
            #worker = models.Worker.objects.get(pk = self.kwargs['worker_pk'])
459
            super(DeleteHolidayView, self).post(request, *args, **kwargs)
460
            #self.model.objects.for_worker(worker).get(pk = self.kwargs['pk']).delete()
412 461
        except Exception, e:
413
            context['error': e.message]
462
            context['message'] = '%s' % e.message
414 463
        response.content = json.dumps(context)
415 464
        return response
416 465

  

Also available in: Unified diff