Project

General

Profile

« Previous | Next » 

Revision 5b90c12e

Added by Serghei Mihai over 11 years ago

Group absences refactored

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())
236 235
        if self.instance and self.instance.id:
237
            self.initial['for_all_services'] = self.instance.service is None
236
            self.initial['for_all_services'] = self.instance.services.count() == Service.objects.count()
238 237
        self.fields['holiday_type'].queryset = \
239 238
                HolidayType.objects.filter(for_group=True)
240 239

  
241 240

  
242 241
    def save(self, commit=True):
243 242
        instance = super(GroupHolidayForm, self).save(commit=False)
244
        if self.cleaned_data.get('for_all_services', False):
245
            instance.service = None
246
        else:
247
            instance.service = self.service
248 243
        if commit:
249 244
            instance.save()
250 245
        return instance
......
253 248
        model = Holiday
254 249
        widgets = {
255 250
            'comment': forms.Textarea(attrs = {'rows': 3, 'cols': 18}),
256
            'service': forms.CheckboxSelectMultiple(attrs = {'class': ''})
251
            'services': forms.CheckboxSelectMultiple()
257 252
        }
258 253

  
259 254
GroupHolidayFormSet = modelformset_factory(Holiday,

Also available in: Unified diff