示例#1
0
    def __init__(self, requestion, *args, **kwargs):
        # сделать optgroups
        is_preferred_sadiks = kwargs.pop('is_preferred_sadiks', [])
        sadiks_query = kwargs.pop('sadiks_query', [])
        self.requestion = requestion

        def select_list_from_qs(queryset, requestion):
            '''Делает из queryset список для параметра choices'''
            select_list = []
            for obj in queryset:
                select_list.append((obj.id, unicode(obj)))
            return select_list

        choices = []
        if is_preferred_sadiks:
            choices.append((u'Предпочитаемые МДОУ', select_list_from_qs(sadiks_query, requestion)))
        else:
            choices.append((u'МДОУ этого района', select_list_from_qs(sadiks_query, requestion)))

        super(SelectSadikForm, self).__init__(*args, **kwargs)
        self.fields['sadik'].choices = choices
        self.fields['requestion_id'].initial = self.requestion.id
        # изменяем порядок полей
        if requestion.needs_location_confirmation:
            self.fields['accept_location'] = forms.BooleanField(label=u'Координаты на карте совпадают с адресом',)
            self.fields['accept_location'].error_messages['required'] = u'Подтвердите местоположение заявки'
            if not requestion.location:
                self.fields['accept_location'].widget.attrs['disabled'] = 'disabled'
                self.fields['accept_location'].error_messages['required'] = u'Необходимо указать местоположение заявки'
            fields_order = self.fields.keys()
            fields_order.remove('accept_location')
            fields_order.insert(0, 'accept_location')
            self.fields = reorder_fields(self.fields, fields_order)
示例#2
0
 def __init__(self, *args, **kwargs):
     super(QueueFilterForm, self).__init__(*args, **kwargs)
     fields_order = [
         'requestion_number',
         'status',
         'area',
         'age_group',
         'benefit_category',
         'admission_date',
         'decision_date',
         'without_facilities',
     ]
     self.fields = reorder_fields(self.fields, fields_order)
     if 'not_appeared' in self.fields:
         del self.fields['not_appeared']
     admission_date_choices = [
         (year.year, year.year) for year in
         Requestion.objects.queue().dates('admission_date', 'year')]
     admission_date_choices = [('', '---------'),] + admission_date_choices
     self.fields['admission_date'].choices = admission_date_choices
     decision_date_choices = [
         (year.year,year.year) for year in
         Requestion.objects.queue().dates('decision_datetime', 'year')]
     decision_date_choices = [('', '---------'),] + decision_date_choices
     self.fields['decision_date'].choices = decision_date_choices