Project

General

Profile

« Previous | Next » 

Revision 8da5a7b6

Added by Serghei Mihai almost 11 years ago

prototype of editing group absences

View differences:

calebasse/personnes/forms.py
232 232
    def __init__(self, *args, **kwargs):
233 233
        self.service = kwargs.pop('service', None)
234 234
        super(GroupHolidayForm, self).__init__(*args, **kwargs)
235
        self.fields['service'].choices = ((service.id, service.name) for service in Service.objects.all())
235 236
        if self.instance and self.instance.id:
236 237
            self.initial['for_all_services'] = self.instance.service is None
237 238
        self.fields['holiday_type'].queryset = \
......
249 250
        return instance
250 251

  
251 252
    class Meta:
252
        form = Holiday
253
        model = Holiday
253 254
        widgets = {
254
                'comment': forms.Textarea(attrs={'rows': 3}),
255
            'comment': forms.Textarea(attrs = {'rows': 3, 'cols': 18}),
256
            'service': forms.CheckboxSelectMultiple(attrs = {'class': ''})
255 257
        }
256 258

  
257 259
GroupHolidayFormSet = modelformset_factory(Holiday,
calebasse/personnes/urls.py
27 27

  
28 28
holidays_patterns = patterns('calebasse.personnes.views',
29 29
    url(r'^$', 'holiday_listing'),
30
    url(r'^groupe/$', 'group_holiday_update',
31
        name='group-holiday-update'),
30
    # url(r'^groupe/$', 'group_holiday_update',
31
    #     name='group-holiday-update'),
32
    url(r'^groupe/$', 'group_holidays', name = 'group-holidays'),
33
    url(r'^groupe/(?P<pk>\d+)/editer/?$', 'edit_group_holiday', name = 'edit-group-holiday'),
34
    url(r'^groupe/(?P<pk>\d+)/supprimer/?$', 'delete_group_holiday', name = 'delete-group-holiday'),
32 35
    )
33 36

  
34 37
urlpatterns = patterns('calebasse.personnes.views',
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

  
calebasse/settings/common.py
164 164
    'calebasse.statistics',
165 165
    'calebasse.middleware.request',
166 166
    'south',
167
    'django_jenkins',
167 168
)
168 169

  
169 170
INTERNAL_IPS=('127.0.0.1',)
calebasse/static/css/style.css
831 831
}
832 832

  
833 833
#info-membre div button.save,
834
div.group_holidays button.save,
834 835
div#tabs-7 div div.buttons,
835 836
div#tabs-4 div div.buttons,
836 837
div#tabs-3 div div.buttons,
......
854 855
	margin: 0;
855 856
}
856 857

  
857
#info-membre div {
858
#info-membre div, div.group_holidays {
858 859
  position: relative;
859 860
}
860 861

  
......
1485 1486
    padding: 0 .5em;
1486 1487
}
1487 1488

  
1489
#holidays.group li.date, #holidays.group li.hour {
1490
    width: 9%;
1491
}
1492

  
1493
#holidays.group .type, #holidays.group .all {
1494
    width: 8%;
1495
}
1496

  
1497
#holidays.group .comment {
1498
    width: 30%;
1499
}
1500

  
1488 1501
#services li {
1489 1502
    display: inline-block;
1490 1503
    list-style-type: none;
calebasse/static/js/calebasse.absences.js
1
function action(worker, on, action, selector, original_color, highlight_color, params, on_success) {
2
    var url = '';
1
function action(url, worker, on, action, selector, original_color, highlight_color, params, on_success) {
3 2
    if(on) {
4
        url = '/cmpp/personnes/gestion/' + worker + '/holidays/' + on + '/' + action + '/';
3
        if(worker)
4
            url += worker + '/holidays/' + on + '/' + action + '/';
5
        else
6
            url += on + '/' + action;
5 7
        $(selector).attr('style', 'background: ' + highlight_color);
6 8
    } else {
7
        url = '/cmpp/personnes/gestion/' + worker + '/holidays/' + action;
9
        if(worker)
10
            url += worker + '/holidays/' + action;
11
        else
12
            url += action;
8 13
    }
9 14
    $("#holiday-dlg").load(url,
10 15
                           function() {
......
54 59
        }
55 60

  
56 61
    };
57
    action(worker, null, 'ajouter', null, null, null, params, on_success);
62
    action('/cmpp/personnes/gestion/', worker, null, 'ajouter', null, null, null, params, on_success);
58 63
};
59 64

  
60
function delete_holiday(worker, holiday) {
65
function delete_holiday(worker, holiday, url = '/cmpp/personnes/gestion/') {
61 66
    var selector = '#' + holiday + ' ul';
62 67
    var initial_color = $(selector).attr('style');
63 68
    var params = {'title': 'Supprimer une absence',
......
71 76
            $("#holiday-dlg").dialog("close");
72 77
        }
73 78
    };
74
    action(worker, holiday, 'supprimer', selector, initial_color, '#f8b0b0', params, on_success);
79
    action(url, worker, holiday, 'supprimer', selector, initial_color,
80
           '#f8b0b0', params, on_success);
75 81
};
76 82

  
77
function edit_holiday(worker, holiday) {
83
function edit_holiday(worker, holiday, url = '/cmpp/personnes/gestion/') {
78 84
    var selector = '#' + holiday + ' ul';
79 85
    var initial_color = $(selector).attr('style');
80 86
    params = {'title': 'Éditer une absence',
......
97 103
        }
98 104

  
99 105
    }
100
    action(worker, holiday, 'editer', selector, initial_color,  '#af7', params, on_success);
101
};
106
    action(url, worker, holiday, 'editer', selector, initial_color,  '#af7', params, on_success);
107
};
108

  
109
function edit_group_holiday(holiday) {
110
    var url = '/cmpp/personnes/conges/groupe/';
111
    edit_holiday(null, holiday, url);
112
}
113

  
114
function delete_group_holiday(holiday) {
115
    var url = '/cmpp/personnes/conges/groupe/';
116
    delete_holiday(null, holiday, url);
117
}

Also available in: Unified diff