Exemplo n.º 1
0
    def layout(self):
        if settings.TARGET_PERMISSIONS_ONLY:
            groups = Div()
        else:
            groups = Row('groups')

        # Add filters to layout
        filter_layout = Layout(
            Row(
                Column(HTML('Exposure Time')),
                Column(HTML('No. of Exposures')),
                Column(HTML('Block No.')),
            ))
        for filter_name in self.filters:
            filter_layout.append(
                Row(MultiWidgetField(filter_name, attrs={'min': 0})))

        return Div(Div(filter_layout, css_class='col-md-6'),
                   Div(Row('max_airmass'),
                       Row(PrependedText('min_lunar_distance', '>')),
                       Row('instrument_type'),
                       Row('proposal'),
                       Row('observation_mode'),
                       Row('ipp_value'),
                       groups,
                       css_class='col-md-6'),
                   css_class='form-row')
Exemplo n.º 2
0
def test_multiwidget_field():
    template = Template("""
        {% load crispy_forms_tags %}
        {% crispy form %}
    """)

    test_form = SampleForm()
    test_form.helper = FormHelper()
    test_form.helper.layout = Layout(
        MultiWidgetField(
            "datetime_field",
            attrs=(
                {
                    "rel": "test_dateinput"
                },
                {
                    "rel": "test_timeinput",
                    "style": "width: 30px;",
                    "type": "hidden"
                },
            ),
        ))

    c = Context({"form": test_form})

    html = template.render(c)

    assert html.count('class="dateinput') == 1
    assert html.count('rel="test_dateinput"') == 1
    assert html.count('rel="test_timeinput"') == 2
    assert html.count('style="width: 30px;"') == 2
    assert html.count('type="hidden"') == 2
Exemplo n.º 3
0
    def test_multiwidget_field(self):
        template = get_template_from_string(u"""
            {% load crispy_forms_tags %}
            {% crispy form %}
        """)

        test_form = TestForm()
        test_form.helper = FormHelper()
        test_form.helper.layout = Layout(
            MultiWidgetField('datetime_field',
                             attrs=({
                                 'rel': 'test_dateinput'
                             }, {
                                 'rel': 'test_timeinput',
                                 'style': 'width: 30px;',
                                 'type': "hidden"
                             })))

        c = Context({'form': test_form})

        html = template.render(c)
        self.assertEqual(html.count('class="dateinput"'), 1)
        self.assertEqual(html.count('rel="test_dateinput"'), 1)
        self.assertEqual(html.count('rel="test_timeinput"'), 1)
        self.assertEqual(html.count('style="width: 30px;"'), 1)
        self.assertEqual(html.count('type="hidden"'), 1)
Exemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.form_method = 'post'
     self.layout = Layout(
         Div(
             Div(
                 HTML(self.card_header % self.card_data),
                 css_class="card-header",
             ),
             Div(Field('type', css_class='form-group'),
                 Row(Column('constructor',
                            css_class='form-group col-md-6 mb-0'),
                     Column('model', css_class='form-group col-md-6 mb-0'),
                     css_class='form-row'),
                 Row(Column('imatriculation_country',
                            css_class='form-group col-md-6 mb-0'),
                     Column('imatriculation',
                            css_class='from-group col-md-6 mb-0'),
                     css_class='form-row'),
                 Row(MultiWidgetField(
                     'radio_id',
                     css_class='form-group',
                     attrs=({
                         'class': 'form-control'
                     }, {
                         'class': 'form-control'
                     }),
                     template="aircraft_registration_crispy_field.html"),
                     css_class='form-row'),
                 css_class="card-body"),
             css_class='card',
         ), )
     self.render_required_fields = True
     self.add_input(Submit('submit', _('str_Submit')))
Exemplo n.º 5
0
def test_multiwidget_field():
    template = Template("""
        {% load crispy_forms_tags %}
        {% crispy form %}
    """)

    test_form = SampleForm()
    test_form.helper = FormHelper()
    test_form.helper.layout = Layout(
        MultiWidgetField('datetime_field',
                         attrs=({
                             'rel': 'test_dateinput'
                         }, {
                             'rel': 'test_timeinput',
                             'style': 'width: 30px;',
                             'type': "hidden"
                         })))

    c = Context({'form': test_form})

    html = template.render(c)

    assert html.count('class="dateinput') == 1
    assert html.count('rel="test_dateinput"') == 1
    assert html.count('rel="test_timeinput"') == 2
    assert html.count('style="width: 30px;"') == 2
    assert html.count('type="hidden"') == 2
Exemplo n.º 6
0
    def __init__(self, *args, **kwargs):

        super(UserProfileForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.layout = Layout(
            Fieldset(
                '',
                Div(
                    Div('name',css_class='col-md-6',),
                    Div(css_class='col-md-1',),
                    Div('gender',css_class='col-md-5',),
                    css_class='row',
                ),
                MultiWidgetField(
                    'birthday',
                    attrs=({'style': 'width: 32.7%; display: inline-block;'})),
            ),
            Fieldset(
                '',
                'username',
                'personal_slogan',
                'self_introduction',
            ),
            Fieldset(
                '',
                'place_of_origin',
                'current_residence',
                'education',
                'occupation',
                'skype_id',
            ),
            ButtonHolder(
                Submit('submit', _('Confirm'), css_class='btn btn-primary'),
            ),
        )
Exemplo n.º 7
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.layout = Layout(
         Fieldset(
             _('ข้อมูลผู้สมัครภาษาอังกฤษ'),
             Row(
                 Div('prefix_english', css_class='col-md-2'),
                 Div('first_name_english', css_class='col-md-3'),
                 Div('middle_name_english', css_class='col-md-3'),
                 Div('last_name_english', css_class='col-md-4'),
             ),
         ),
         Fieldset(
             _('ข้อมูลส่วนตัว'),
             self._show_passport_field(),
             MultiWidgetField('birthday',
                              attrs=({
                                  'class': 'd-inline col-md-3'
                              })),
         ),
         Fieldset(
             _('ข้อมูลบิดา (ภาษาไทย)'),
             Row(
                 Div('father_prefix', css_class='col-md-2'),
                 Div('father_first_name', css_class='col-md-5'),
                 Div('father_last_name', css_class='col-md-5'),
             )),
         Fieldset(
             _('ข้อมูลมารดา (ภาษาไทย)'),
             Row(
                 Div('mother_prefix', css_class='col-md-2'),
                 Div('mother_first_name', css_class='col-md-5'),
                 Div('mother_last_name', css_class='col-md-5'),
             )),
         Fieldset(
             _('ข้อมูลที่อยู่'),
             Row(
                 Div('house_number', css_class='col-md-2'),
                 Div('village_number', css_class='col-md-2'),
                 Div('avenue', css_class='col-md-2'),
                 Div('road', css_class='col-md-6'),
             ),
             Row(
                 Div('sub_district', css_class='col-md-6'),
                 Div('district', css_class='col-md-6'),
             ),
             Row(
                 Div('province', css_class='col-md-6'),
                 Div('postal_code', css_class='col-md-6'),
             ),
             Row(
                 Div('contact_phone', css_class='col-md-6'),
                 Div('mobile_phone', css_class='col-md-6'),
             ),
         ),
         ButtonHolder(
             Submit('submit', _('จัดเก็บ'), css_class='btn btn-primary')))
	def __init__(self, *args, **kwargs):
		super(ExpenseForm, self).__init__(*args, **kwargs)
		self.helper = FormHelper()

		self.helper.layout = Layout(
		    'description',
		    'total_cost',
		    'pay_to',
		    MultiWidgetField('due_by', attrs=({'style': 'width: 25%; display: inline-block;'})),
		)
Exemplo n.º 9
0
    def __init__(self, *args, **kwargs):
        super(DemographicsForm, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.form_tag = False
        self.helper.add_layout(
            MultiWidgetField(
                'birth_date',
                attrs=({
                    'style':
                    'width: 33%; display: inline-block;max-width:100px;'
                })))
Exemplo n.º 10
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.form_method = 'post'
     self.helper.layout = Layout(
         'profile_pic',
         'bio',
         MultiWidgetField('birth_date', attrs=({'style': 'width: 32%; display: inline-block;', 'class': 'mr-1','data-date-format': 'dd/mm/yyyy'})),
         'phone',
         'url_facebook',
         'url_twitter',
         Submit('submit', 'Save Changes', css_class='btn-info btn-block ')
     )
Exemplo n.º 11
0
def DynamicFields(title, field, count):
    return Div(
        MultiWidgetField(
            field,
            attrs=(
                {
                    'class': "col-sm-2",
                    'style': "width: %s%%; " % (100. / count)
                }
            )
        ),
        # css_class='row col-sm-10'
        # css_class='row progression-fields',
    )
Exemplo n.º 12
0
    def __init__(self, *args, **kwargs):
        super(In_patientForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.add_input(Submit('submit', 'Save'))

        self.helper.layout = Layout(
            'patient',
            MultiWidgetField('date_of_adm',
                             attrs=({
                                 'style':
                                 'width: 32.8%; display: inline-block;'
                             })),
            MultiWidgetField('date_of_discarge',
                             attrs=({
                                 'style':
                                 'width: 32.8%; display: inline-block;'
                             })),
            'diagnosis',
            'doctor',
            'room',
        )
Exemplo n.º 13
0
    def __init__(self, *args, **kwargs):
        super(BrandForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_tag = False

        self.helper.layout = Layout(
            'collector_name',
            'respondent_name',
            'respondent_city',
            'favourite_drink',
            MultiWidgetField('date_of_collection',
                             attrs=({
                                 'style':
                                 'width: 32.7%; display: inline-block;'
                             })),
        )
Exemplo n.º 14
0
    def __init__(self, *args, **kwargs):
        super(PatientForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.add_input(Submit('submit', 'Save'))

        self.helper.layout = Layout(
            'first_name', 'last_name', 'gender',
            MultiWidgetField('dob',
                             attrs=({
                                 'style':
                                 'width: 32.8%; display: inline-block;'
                             })), 'age',
            Fieldset(
                'Contact Information',
                Field('country', 'city', 'address', 'contact_no',
                      'next_of_kin')))
Exemplo n.º 15
0
    def __init__(self, *args, **kwargs):
        super(BlogPostModelForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        # self.helper.form_class = 'form-horizontal'
        # self.helper.form_method = 'post'
        # self.helper.add_input(Submit('submit', 'Save'))

        self.helper.layout = Layout(
            'title',
            'image',
            'slug',
            'content',
            MultiWidgetField('publish_date',
                             attrs=({
                                 'style':
                                 'width: 32.8%; display: inline-block;'
                             })),
        )
Exemplo n.º 16
0
def ProgressionFields(title, field, count):
    return Div(
        Div(
            HTML("<label clas='text-right'>%s</label>" % title),
            css_class='col-sm-2 progression-label',
        ),
        Div(
            MultiWidgetField(
                field,
                attrs=(
                    {
                        'class': "col-sm-2",
                        'style': "width: %s%%;" % (100. / count)
                    }
                )
            ),
            css_class='row col-sm-10'
        ),
        css_class='row progression-fields',
    )
Exemplo n.º 17
0
 def __init__(self, *args, **kwargs):
     self.create = kwargs.pop("create", False)
     super().__init__(*args, **kwargs)
     self.helper = FormHelper()
     self.helper.form_method = 'post'
     self.helper.add_input(
         Submit('submit',
                'Create' if self.create else 'Update',
                css_class='btn-primary'))
     self.helper.layout = Layout(
         Row(Column('content', css_class='form-group col-md-6 mb-0'),
             css_class='form-row'),
         Row(MultiWidgetField('deadline',
                              attrs=({
                                  'style':
                                  'width: 33%; display: inline-block;'
                              })),
             css_class='form-row'),
     )
     self.helper.label_class = 'd-block'
Exemplo n.º 18
0
    def __init__(self, *args, **kwargs):
        super(DoctorForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        # self.helper.form_class = 'form-horizontal'
        # self.helper.form_method = 'post'
        # self.helper.add_input(Submit('submit', 'Save'))
        self.helper.form_tag = False

        self.helper.layout = Layout(
            'first_name',
            'last_name',
            'gender',
            MultiWidgetField('dob',
                             attrs=({
                                 'style':
                                 'width: 32.8%; display: inline-block;'
                             })),
            'age',
            'country',
            'city',
            'address',
        )
Exemplo n.º 19
0
    def __init__(self, *args, **kwargs):
        super(TreatmentForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        # self.fields['symptoms'].widget.attrs['style'] = 'resize:none' //setting textarea resize to none
        # self.helper.form_class = 'form-horizontal'
        # self.helper.form_method = 'post'
        # self.helper.add_input(Submit('submit', 'Save'))
        self.helper.form_tag = False

        self.helper.layout = Layout(
            'patient',
            'doctor',
            MultiWidgetField(
                'date',
                attrs=(
                    {'style': 'width: 32.8%; display: inline-block;'}
                )
            ),
            'symptoms',
            'diagnosis',
            'doctors_comments',
        )
Exemplo n.º 20
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.helper = FormHelperWithDefaults()
     if (self.defaults.get('sender')):
         del self.fields['sender_name']
         del self.fields['sender_email']
         del self.fields['no_bots']
         self.helper.add_input(Submit('submit', pgettext_lazy(context=self.defaults['sender'].get_gender(), message='Send')))
     else:
         self.fields['sender_name'].required = True
         self.fields['sender_email'].required = True
         self.helper.add_layout(
             MultiWidgetField(
                 Row(
                     Div('sender_name', css_class='col-md-6'),
                     Div('sender_email', css_class='col-md-6'),
                 ),
                 'text',
                 'no_bots',
             ),
         )
         self.helper.add_input(Submit('submit', _('Send')))
Exemplo n.º 21
0
    def __init__(self, *args, **kwargs):
        """Selects custom layout and placeholders for the form."""
        super().__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        helper = self.helper
        helper.form_action = 'users:shipping-billing'
        helper.form_id = 'shipping_billing_form'
        helper.form_tag = False

        self.fields['shipping_phone_number'] = forms.CharField(
            widget=widgets.PhoneNumberPrefixWidget(), required=False)

        self.fields['billing_phone_number'] = forms.CharField(
            widget=widgets.PhoneNumberPrefixWidget(), required=False)

        self.fields['shipping_full_name'].label = _('Full Name')
        self.fields['shipping_street_address_1'].label = _('Street Address 1')
        self.fields['shipping_street_address_2'].label = _('Street Address 2')
        self.fields['shipping_town_or_city'].label = _('Town or City')
        self.fields['shipping_county'].label = _('County, State or Locality')
        self.fields['shipping_country'].label = _('Country')

        self.fields['billing_full_name'].label = _('Full Name')
        self.fields['billing_street_address_1'].label = _('Street Address 1')
        self.fields['billing_street_address_2'].label = _('Street Address 2')
        self.fields['billing_town_or_city'].label = _('Town or City')
        self.fields['billing_county'].label = _('County, State or Locality')
        self.fields['billing_postcode'].label = _('Postcode')
        self.fields['billing_country'].label = _('Country')

        helper.layout = Layout(
            Row(
                Column(
                    Fieldset(
                        _('SHIPPING DETAILS'),
                        Row(
                            Field('shipping_full_name',
                                  placeholder=_('Full Name'),
                                  css_class='p-font text-primary'),
                            MultiWidgetField(
                                'shipping_phone_number',
                                template='bootstrap4/phone_field.html'),
                            Field('shipping_street_address_1',
                                  placeholder=_('Street Address 1'),
                                  css_class='p-font text-primary'),
                            Field('shipping_street_address_2',
                                  placeholder=_('Street Address 2'),
                                  css_class='p-font text-primary'),
                            Field('shipping_town_or_city',
                                  placeholder=_('Town or City'),
                                  css_class='p-font text-primary'),
                            Field('shipping_county',
                                  placeholder=_('County, State or Locality'),
                                  css_class='p-font text-primary'),
                            Field('shipping_postcode',
                                  placeholder=_('Postcode'),
                                  css_class='p-font text-primary'),
                            Field(
                                'shipping_country',
                                css_class='form-select p-font text-primary'))),
                    css_class='col-12 col-md-6 p-2 px-md-4 pt-md-4 pb-md-2'),
                Column(
                    Fieldset(
                        _('BILLING DETAILS'),
                        Row(
                            Field('billing_full_name',
                                  placeholder=_('Full Name'),
                                  css_class='p-font text-primary'),
                            MultiWidgetField(
                                'billing_phone_number',
                                template='bootstrap4/phone_field.html'),
                            Field('billing_street_address_1',
                                  placeholder=_('Street Address 1'),
                                  css_class='p-font text-primary'),
                            Field('billing_street_address_2',
                                  placeholder=_('Street Address 2'),
                                  css_class='p-font text-primary'),
                            Field('billing_town_or_city',
                                  placeholder=_('Town or City'),
                                  css_class='p-font text-primary'),
                            Field('billing_county',
                                  placeholder=_('County, State or Locality'),
                                  css_class='p-font text-primary'),
                            Field('billing_postcode',
                                  placeholder=_('Postcode'),
                                  css_class='p-font text-primary'),
                            Field(
                                'billing_country',
                                css_class='form-select p-font text-primary'))),
                    css_class='col-12 col-md-6 p-2 px-md-4 pt-md-4 pb-md-2'),
                Column(StrictButton(
                    _('Save Details'),
                    type='submit',
                    css_class='p-font btn-tran btn btn-sm fw-bold \
                                        btn-warning text-primary shadow'),
                       css_class='col-12 col-md-auto ps-2 pb-2 px-md-4 \
                           pb-md-4 mx-md-auto')))
Exemplo n.º 22
0
class JobSearchForm(forms.Form):
  # Be sure to check whether fields match respective ones located in models.py
  
  # Form fields
  name_field = forms.CharField(
    label=False,
    required=False,
    max_length=200)
  deadline_date_field = forms.DateField(
    label=False,
    required=False,
    widget=forms.SelectDateWidget)
  location_field = forms.CharField(
    label=False,
    required=False,
    max_length=200)
  salary_field = forms.IntegerField(
    label=False,
    required=False)
  duration_field = forms.IntegerField(
    label=False,
    required=False)
  date_posted_field = forms.DateField(
    label=False,
    required=False,
    widget=forms.SelectDateWidget)
  tag_field = forms.ModelChoiceField(
    label=False,
    required=False,
    queryset=Tag.objects.all().order_by('name'))
  # Setting the layout of the form 
  helper = FormHelper()
  helper.form_method = 'GET'
  helper.form_id = 'search-form'
  helper.form_action = 'search/'
  helper.add_input(Submit('search', 'Search'))
  helper.layout = Layout(
    Field('name_field', placeholder='What do you want to do?'),
    Accordion(
      AccordionGroup('Deadline',
        MultiWidgetField(
          'deadline_date_field', 
          attrs=(
            {'style': 'width: 33%; display: inline-block;'})
        )
      ),
      AccordionGroup('Location',
        Field('location_field', placeholder='Type in location where you would like to work')
      ),
      AccordionGroup('Salary',
        Field('salary_field', placeholder='Type in minimal salary')
      ),
      AccordionGroup('Duration',
        Field('duration_field', placeholder='Type in minimal duration of the job (in weeks)')
      ),
      AccordionGroup('Date posted', 
        MultiWidgetField(
          'date_posted_field', 
          attrs=(
            {'style': 'width: 33%; display: inline-block;'})
        )
      ),
      AccordionGroup('Tag', 
        'tag_field'
      )
    )
  )