Project

General

Profile

« Previous | Next » 

Revision c2953462

Added by Serghei Mihai over 10 years ago

personnes: individual holidays properly saved

Closes #3108

View differences:

calebasse/personnes/views.py
351 351
        worker = models.Worker.objects.get(pk=self.kwargs['worker_pk'])
352 352
        return {'services': worker.services.all()}
353 353

  
354
    def form_valid(self, form):
355
        holiday = form.save()
356
        worker = models.Worker.objects.get(pk=self.kwargs['worker_pk'])
357
        holiday.worker = worker
358
        holiday.save()
359

  
354 360
    def render_to_json(self, location, err = 0, **kwargs):
355 361
        data = {'err': err, 'location': location}
356 362
        response = json.dumps(data)
......
407 413
            messages.error(self.request, u'Une erreur est survenue lors de la mise à jour de l\'absence')
408 414
        return self.render_to_json(self.get_success_url())
409 415

  
416

  
410 417
edit_group_holiday = EditGroupHolidayView.as_view()
411 418

  
412 419
class HolidayCreateView(HolidayManagement, cbv.CreateView):
413 420

  
414 421
    def form_valid(self, form):
415 422
        try:
416
            holiday = form.save()
417
            worker = models.Worker.objects.get(pk=self.kwargs['worker_pk'])
418
            holiday.worker = worker
419
            holiday.save()
423
            super(HolidayCreateView, self).form_valid(form)
420 424
            messages.success(self.request, u'Absence ajoutée avec succès')
421 425
        except Exception, e:
422 426
            logger.debug('Error on creating a holiday: %s' % e)
423
            messages.error(self.request, u'Une erreur est survenue lors de la mise à jour de l\'absence')
427
            messages.error(self.request, u'Une erreur est survenue lors de l\'ajout de l\'absence')
424 428
        return self.render_to_json(self.get_success_url())
425 429

  
426 430
create_holiday = HolidayCreateView.as_view()
......
435 439

  
436 440
    def form_valid(self, form):
437 441
        try:
438
            form.save()
442
            super(EditHolidayView, self).form_valid(form)
439 443
            messages.success(self.request, u'Données mises à jour avec succès')
440 444
        except Exception, e:
441 445
            logger.debug('Error on updating a holiday: %s' % e)

Also available in: Unified diff