Exemplo n.º 1
0
 def fields(self, fields):
     fields.text_input_field = Field(label='A TextInput')
     fields.password_field = Field(label='A PasswordInput')
     fields.text_area_field = Field(label='A TextArea')
     fields.text_input_without_label = Field(label='A TextInput without a label')
     fields.cue_field = Field(label='A TextInput in a CueInput')
     fields.choice_field = ChoiceField([Choice(False, BooleanField(label='None selected')),
                                        ChoiceGroup('Numbers', [Choice(1, IntegerField(label='One')), 
                                                                Choice(2, IntegerField(label='Two')),
                                                                Choice(3, IntegerField(label='Three'))]),
                                        ChoiceGroup('Colours', [Choice('r', Field(label='Red')),
                                                                Choice('g', Field(label='Green'))])
                                        ], label='A SelectInput')
     fields.multi_choice_field = MultiChoiceField([Choice(1, IntegerField(label='One')), 
                                                   Choice(2, IntegerField(label='Two')), 
                                                   Choice(3, IntegerField(label='Three'))], 
                                                  label='A SelectInput allowing multiple choices')
     fields.another_multi_choice_field = MultiChoiceField([Choice('a', Field(label='Newton')),
                                                           Choice('b', Field(label='Archimedes')),
                                                           Choice('c', Field(label='Einstein')),
                                                           ],
                                                          default=['a', 'c'],
                                                          label='A CheckboxInput allowing multiple choices')
     fields.boolean_field = BooleanField(label='A CheckboxInput to toggle')
     fields.radio_choice_field = ChoiceField([Choice(1, IntegerField(label='One')), 
                                              Choice(2, IntegerField(label='Two')), 
                                              Choice(3, IntegerField(label='Three'))],
                                             label='A RadioButtonSelectInput')
     fields.fuzzy_date_field = DateField(label='A fuzzy TextInput for a Date')
Exemplo n.º 2
0
 def fields(self, fields):
     types = [
         Choice('passport', Field(label='Passport')),
         Choice('id_card', Field(label='National ID Card'))
     ]
     fields.document_type = ChoiceField(types, label='Type', required=True)
     fields.id_card_number = Field(label='ID card number', required=True)
     fields.passport_number = Field(label='Passport number', required=True)
     countries = [
         Choice('Australia', Field(label='Australia')),
         Choice('Chile', Field(label='Chile')),
         Choice('China', Field(label='China')),
         Choice('France', Field(label='France')),
         Choice('Germany', Field(label='Germany')),
         Choice('Ghana', Field(label='Ghana')),
         Choice('India', Field(label='India')),
         Choice('Japan', Field(label='Japan')),
         Choice('Kenya', Field(label='Kenya')),
         Choice('Namibia', Field(label='Namibia')),
         Choice('Nigeria', Field(label='Nigeria')),
         Choice('South Africa', Field(label='South Africa')),
         Choice('United States', Field(label='United States of America')),
         Choice('United Kingdom', Field(label='United Kingdom')),
         Choice('Zimbabwe', Field(label='Zimbabwe'))
     ]
     fields.country = ChoiceField(countries, label='Country', required=True)
Exemplo n.º 3
0
    def radio_button(self):
        self.model_object.an_attribute = 2

        choices = [
            Choice(1, IntegerField(label='One')),
            Choice(2, IntegerField(label='Two'))
        ]
        self.field = ChoiceField(choices)
        self.field.bind('an_attribute', self.model_object)

        self.widget = self.form.add_child(
            RadioButtonInput(self.form, self.field))

        validations = html_escape(
            '{"validate": {"messages": {"pattern": "an_attribute should be one of the following: 1\|2"}}}'
        )
        radio_button = r'<span class="reahl-radio-button">'\
                       r'<input name="an_attribute"%s form="test" pattern="\(1\|2\)" '\
                              r'title="an_attribute should be one of the following: 1\|2" '\
                              r'type="radio" value="%s" class="%s">%s'\
                       r'</span>'

        outer_div = r'<div class="reahl-radio-button-input">%s</div>'
        buttons = (radio_button % ('', '1', validations, 'One')) +\
                  (radio_button % (' checked="checked"', '2', validations, 'Two'))
        self.expected_html = outer_div % buttons
        self.field_controls_visibility = True
Exemplo n.º 4
0
    def radio_button(self):
        self.model_object.an_attribute = 2

        choices = [
            Choice(1, IntegerField(label='One')),
            Choice(2, IntegerField(label='Two'))
        ]
        self.field = ChoiceField(choices)
        self.field.bind('an_attribute', self.model_object)

        self.widget = self.form.add_child(
            RadioButtonSelectInput(self.form, self.field))

        radio_button = '<label>'\
                       '<input name="test-an_attribute" id="id-test-an_attribute-%s"%s '\
                              'data-msg-pattern="an_attribute should be one of the following: 1|2" '\
                              '%s'\
                              'form="test" pattern="(1|2)" '\
                              'title="an_attribute should be one of the following: 1|2" '\
                              'type="radio" value="%s">%s'\
                       '</label>'

        outer_div = '<div class="reahl-primitiveinput reahl-radio-button-input">%s</div>'
        buttons = (radio_button % ('1', '', '', '1', 'One')) +\
                  (radio_button % ('2', ' checked="checked"', '', '2', 'Two'))
        self.expected_html = outer_div % buttons
        self.field_controls_visibility = True
Exemplo n.º 5
0
 def new_field(self):
     choices = [
         Choice(1, Field(label='One')),
         Choice(2, Field(label='Two'))
     ]
     field = ChoiceField(choices)
     field.bind('field', self)
     return field
Exemplo n.º 6
0
 def fields(self, fields):
     fields.choice = ChoiceField([Choice(1, IntegerField(label='One')),
                                 Choice(2, IntegerField(label='Two')),
                                 Choice(3, IntegerField(label='Three'))],
                                 label='Choice')
     fields.choice2 = ChoiceField([Choice(4, IntegerField(label='Four')),
                                 Choice(5, IntegerField(label='Five')),
                                 Choice(6, IntegerField(label='Six'))],
                                 label='Choice2')
     fields.calculated_state = IntegerField(label='Calculated', writable=Allowed(False))
Exemplo n.º 7
0
 def fields(self, fields):
     fields.choice = ChoiceField([Choice(1, IntegerField(label='One')),
                                 Choice(2, IntegerField(label='Two')),
                                 Choice(3, IntegerField(label='Three'))],
                                 label='Choice')
     fields.choice3 = ChoiceField([Choice(7, IntegerField(label='Seven')),
                                 Choice(8, IntegerField(label='Eight')),
                                 Choice(9, IntegerField(label='Nine'))],
                                 label='Choice3')
     fields.calculated_state = IntegerField(label='Calculated', writable=Allowed(False))
Exemplo n.º 8
0
 def fields(self, fields):
     fields.agreed_to_terms = BooleanField(label='I agree to the terms and conditions')
     fields.new_or_existing = ChoiceField([Choice('new', Field(label='New')),
                                           Choice('existing', Field(label='Existing'))],
                                          label='Are you a new or existing investor?')
     fields.existing_account_number = IntegerField(label='Existing account number', required=True)
     fields.name         = Field(label='Name', required=True)
     fields.surname      = Field(label='Surname', required=True)
     fields.amount       = IntegerField(label='Total amount', required=True)
     fields.amount_or_percentage  = ChoiceField([Choice('amount', Field(label='Amount')),
                                                 Choice('percentage', Field(label='Percentage'))],
                                         label='Allocate using', required=True)
Exemplo n.º 9
0
def test_unique_choices(fixture):
    """All choices must have unique values."""
    duplicate_choices = [Choice(1, IntegerField(label='One')),
                         Choice(1, IntegerField(label='Two')),
                         Choice(3, IntegerField(label='Three'))]
    with expected(ProgrammerError, test='Duplicate choices are not allowed'):
        ChoiceField(duplicate_choices)
Exemplo n.º 10
0
def test_checkbox_select_input_allowed_fields(web_fixture):
    """A CheckboxSelectInput can only be used with a MultiChoiceField."""

    model_object = web_fixture
    form = Form(web_fixture.view, 'test')

    choice_field = ChoiceField([])
    choice_field.bind('an_attribute', model_object)

    with expected(ProgrammerError, test='<class \'reahl.component.modelinterface.ChoiceField\'> is not allowed to be used with <class \'reahl.web.ui.CheckboxSelectInput\'>'):
        CheckboxSelectInput(form, choice_field)

    multi_choice_field = MultiChoiceField([])
    multi_choice_field.bind('another_attribute', model_object)

    with expected(NoException):
        CheckboxSelectInput(form, multi_choice_field)
Exemplo n.º 11
0
    def setup_checkbox_scenario(self, boolean_value):
        self.model_object.an_attribute = boolean_value

        self.field = BooleanField(required=True, label='my text', required_message='$label is needed here')
        self.field.bind('an_attribute', self.model_object)

        self.widget = self.form.add_child(CheckboxInput(self.form, self.field))
        self.field_controls_visibility = True
Exemplo n.º 12
0
 def fields(self, fields):
     fields.amount = IntegerField(label='Total amount', required=True)
     fields.amount_or_percentage = ChoiceField([
         Choice('amount', Field(label='Amount')),
         Choice('percentage', Field(label='Percentage'))
     ],
                                               label='Allocate using',
                                               required=True)
Exemplo n.º 13
0
 def fields(self, fields):
     fields.operandA = IntegerField(label='A')
     fields.operandB = ChoiceField([
         Choice(4, IntegerField(label='4')),
         Choice(5, IntegerField(label='5')),
         Choice(6, IntegerField(label='6'))
     ],
                                   label='B')
Exemplo n.º 14
0
 def fields(self, fields):
     collaborators = [
         Choice(i.id, IntegerField(label=i.email))
         for i in Session.query(EmailAndPasswordSystemAccount).all()
     ]
     fields.chosen_collaborator = ChoiceField(collaborators,
                                              label='Choose collaborator')
     fields.may_edit_address = BooleanField(
         label='May edit existing addresses')
     fields.may_add_address = BooleanField(label='May add new addresses')
Exemplo n.º 15
0
    def select_input(self):
        self.model_object.an_attribute = 2

        choices = [Choice(False, BooleanField(label='None')),
                   ChoiceGroup('grouped', [
                       Choice(1, IntegerField(label='One')),
                       Choice(2, IntegerField(label='Two'))])
                  ]
        self.field = ChoiceField(choices)
        self.field.bind('an_attribute', self.model_object)

        self.widget = self.form.add_child(SelectInput(self.form, self.field))
        group = '<optgroup label="grouped">'+\
                                  '<option id="id-test-an_attribute-1" value="1">One</option>'+\
                                  '<option id="id-test-an_attribute-2" selected="selected" value="2">Two</option>'+\
                '</optgroup>'
        option = '<option id="id-test-an_attribute-off" value="off">None</option>'
        self.expected_html = r'<select name="test-an_attribute" id="id-test-an_attribute" form="test" class="reahl-primitiveinput">%s%s</select>' % (option, group)
        self.bound_field = self.widget.bound_field
Exemplo n.º 16
0
    def select_input(self):
        self.model_object.an_attribute = 2

        choices = [
            Choice(False, BooleanField(label='None')),
            ChoiceGroup('grouped', [
                Choice(1, IntegerField(label='One')),
                Choice(2, IntegerField(label='Two'))
            ])
        ]
        self.field = ChoiceField(choices)
        self.field.bind('an_attribute', self.model_object)

        self.widget = self.form.add_child(SelectInput(self.form, self.field))
        group = r'<optgroup label="grouped"><option value="1">One</option><option selected="selected" value="2">Two</option></optgroup>'
        option = r'<option value="off">None</option>'
        self.expected_html = r'<select name="an_attribute" form="test">%s%s</select>' % (
            option, group)
        self.field_controls_visibility = True
Exemplo n.º 17
0
    def select_input_multi(self):
        self.model_object.an_attribute = [2]

        choices = [Choice(1, IntegerField(label='One')),
                   Choice(2, IntegerField(label='Two'))]
        self.field = MultiChoiceField(choices)
        self.field.bind('an_attribute', self.model_object)

        self.widget = self.form.add_child(SelectInput(self.form, self.field))
        options = '<option id="id-test-an_attribute-91--93--1" value="1">One</option><option id="id-test-an_attribute-91--93--2" selected="selected" value="2">Two</option>'
        self.expected_html = '<select name="test-an_attribute[]" id="id-test-an_attribute-91--93-" form="test" multiple="multiple" class="reahl-primitiveinput">%s</select>' % (options)
        self.field_controls_visibility = True
Exemplo n.º 18
0
    def checkbox_input_multi(self):
        selected_checkboxes = [2, 3]
        self.model_object.an_attribute = selected_checkboxes

        choices = [Choice(1, IntegerField(label='One')),
                   Choice(2, IntegerField(label='Two')),
                   Choice(3, IntegerField(label='Three'))
                  ]
        self.field = MultiChoiceField(choices)
        self.field.bind('an_attribute', self.model_object)

        self.widget = self.form.add_child(CheckboxSelectInput(self.form, self.field))
        not_checked_option = r'<label><input name="test-an_attribute[]" id="id-test-an_attribute-91--93--1" form="test" type="checkbox" value="1">One</label>'
        checked_options = r'<label><input name="test-an_attribute[]" id="id-test-an_attribute-91--93--2" checked="checked" form="test" type="checkbox" value="2">Two</label>'
        checked_options += r'<label><input name="test-an_attribute[]" id="id-test-an_attribute-91--93--3" checked="checked" form="test" type="checkbox" value="3">Three</label>'
        options = not_checked_option + checked_options
        self.expected_html = r'<div class="reahl-checkbox-input reahl-primitiveinput">%s</div>' % (options)
        self.field_controls_visibility = True
Exemplo n.º 19
0
class Scenarios(WebFixture, InputMixin):
    @scenario
    def text_input(self):
        self.widget = TextInput(self.form, self.field)
        self.expected_html = r'<input name="an_attribute" form="test" type="text" value="field value" class="reahl-textinput">'
        self.field_controls_visibility = True

    @scenario
    def text_input_placeholder_default(self):
        self.widget = TextInput(self.form, self.field, placeholder=True)
        self.expected_html = r'<input name="an_attribute" form="test" placeholder="the label" type="text" value="field value" class="reahl-textinput">'
        self.field_controls_visibility = True

    @scenario
    def text_input_placeholder_specified(self):
        self.widget = TextInput(self.form, self.field, placeholder="some text")
        self.expected_html = r'<input name="an_attribute" form="test" placeholder="some text" type="text" value="field value" class="reahl-textinput">'
        self.field_controls_visibility = True

    @scenario
    def input_label(self):
        html_input = TextInput(self.form, self.field)
        self.widget = Label(self.view, for_input=html_input)
        self.expected_html = r'<label for="%s">the label</label>' % html_input.css_id
        self.field_controls_visibility = True

    @scenario
    def input_label_with_text(self):
        html_input = TextInput(self.form, self.field)
        self.widget = Label(self.view, for_input=html_input, text='some text')
        self.expected_html = r'<label for="%s">some text</label>' % html_input.css_id
        self.field_controls_visibility = True

    @scenario
    def button_input(self):
        self.widget = self.form.add_child(ButtonInput(self.form, self.event))
        self.expected_html = r'<input name="event.aname\?" form="test" type="submit" value="click me">'
        self.field_controls_visibility = False

    @scenario
    def password(self):
        self.widget = self.form.add_child(PasswordInput(self.form, self.field))
        self.expected_html = r'<input name="an_attribute" form="test" type="password">'
        self.field_controls_visibility = True

    def setup_checkbox_scenario(self, boolean_value):
        self.model_object.an_attribute = boolean_value

        self.field = BooleanField(required=True,
                                  label='my text',
                                  required_message='$label is needed here')
        self.field.bind('an_attribute', self.model_object)

        self.widget = self.form.add_child(CheckboxInput(self.form, self.field))
        self.field_controls_visibility = True

    @scenario
    def checkbox_true(self):
        """A checkbox needs a 'checked' an_attribute if its field is True. It also renders ONLY the
            validation message for its required validation_constraint, not for all constraints"""
        self.setup_checkbox_scenario(True)
        self.expected_html = r'<input name="an_attribute" checked="checked" form="test" required="\*" type="checkbox" ' \
                             r'class="{&quot;validate&quot;: {&quot;messages&quot;: {&quot;required&quot;: &quot;my text is needed here&quot;}}}">'

    @scenario
    def checkbox_false(self):
        self.setup_checkbox_scenario(False)
        self.expected_html = r'<input name="an_attribute" form="test" required="\*" type="checkbox" '\
                             r'class="{&quot;validate&quot;: {&quot;messages&quot;: {&quot;required&quot;: &quot;my text is needed here&quot;}}}">'

    @scenario
    def text_area_input(self):
        self.widget = self.form.add_child(
            TextArea(self.form, self.field, rows=30, columns=20))
        self.expected_html = r'<textarea name="an_attribute" cols="20" rows="30">field value</textarea>'
        self.field_controls_visibility = True

    @scenario
    def select_input(self):
        self.model_object.an_attribute = 2

        choices = [
            Choice(False, BooleanField(label='None')),
            ChoiceGroup('grouped', [
                Choice(1, IntegerField(label='One')),
                Choice(2, IntegerField(label='Two'))
            ])
        ]
        self.field = ChoiceField(choices)
        self.field.bind('an_attribute', self.model_object)

        self.widget = self.form.add_child(SelectInput(self.form, self.field))
        group = r'<optgroup label="grouped"><option value="1">One</option><option selected="selected" value="2">Two</option></optgroup>'
        option = r'<option value="off">None</option>'
        self.expected_html = r'<select name="an_attribute" form="test">%s%s</select>' % (
            option, group)
        self.field_controls_visibility = True

    @scenario
    def select_input_multi(self):
        self.model_object.an_attribute = [2]

        choices = [
            Choice(1, IntegerField(label='One')),
            Choice(2, IntegerField(label='Two'))
        ]
        self.field = MultiChoiceField(choices)
        self.field.bind('an_attribute', self.model_object)

        self.widget = self.form.add_child(SelectInput(self.form, self.field))
        options = r'<option value="1">One</option><option selected="selected" value="2">Two</option>'
        self.expected_html = r'<select name="an_attribute" form="test" multiple="multiple">%s</select>' % (
            options)
        self.field_controls_visibility = True

    @scenario
    def radio_button(self):
        self.model_object.an_attribute = 2

        choices = [
            Choice(1, IntegerField(label='One')),
            Choice(2, IntegerField(label='Two'))
        ]
        self.field = ChoiceField(choices)
        self.field.bind('an_attribute', self.model_object)

        self.widget = self.form.add_child(
            RadioButtonInput(self.form, self.field))

        validations = html_escape(
            '{"validate": {"messages": {"pattern": "an_attribute should be one of the following: 1\|2"}}}'
        )
        radio_button = r'<span class="reahl-radio-button">'\
                       r'<input name="an_attribute"%s form="test" pattern="\(1\|2\)" '\
                              r'title="an_attribute should be one of the following: 1\|2" '\
                              r'type="radio" value="%s" class="%s">%s'\
                       r'</span>'

        outer_div = r'<div class="reahl-radio-button-input">%s</div>'
        buttons = (radio_button % ('', '1', validations, 'One')) +\
                  (radio_button % (' checked="checked"', '2', validations, 'Two'))
        self.expected_html = outer_div % buttons
        self.field_controls_visibility = True
Exemplo n.º 20
0
 def fields(self, fields):
     fields.factor = ChoiceField(
         [Choice(i, IntegerField(label=str(i))) for i in range(1, 10)])
Exemplo n.º 21
0
class InputScenarios(SimpleInputFixture):
    @scenario
    def text_input(self):
        self.widget = TextInput(self.form, self.field)
        self.expected_html = '<input name="test-an_attribute" id="id-test-an_attribute" form="test" type="text" value="field value" class="reahl-primitiveinput reahl-textinput">'
        self.field_controls_visibility = True

    @scenario
    def text_input_placeholder_default(self):
        self.widget = TextInput(self.form, self.field, placeholder=True)
        self.expected_html = '<input name="test-an_attribute" id="id-test-an_attribute" aria-label="the label" form="test" placeholder="the label" type="text" value="field value" class="reahl-primitiveinput reahl-textinput">'
        self.field_controls_visibility = True

    @scenario
    def text_input_placeholder_specified(self):
        self.widget = TextInput(self.form, self.field, placeholder="some text")
        self.expected_html = '<input name="test-an_attribute" id="id-test-an_attribute" aria-label="some text" form="test" placeholder="some text" type="text" value="field value" class="reahl-primitiveinput reahl-textinput">'
        self.field_controls_visibility = True

    @scenario
    def input_label(self):
        html_input = TextInput(self.form, self.field)
        self.widget = Label(self.web_fixture.view, for_input=html_input)
        self.expected_html = '<label for="%s">the label</label>' % html_input.css_id
        self.field_controls_visibility = True

    @scenario
    def input_label_with_text(self):
        html_input = TextInput(self.form, self.field)
        self.widget = Label(self.web_fixture.view, for_input=html_input, text='some text')
        self.expected_html = '<label for="%s">some text</label>' % html_input.css_id
        self.field_controls_visibility = True

    @scenario
    def button_input(self):
        self.widget = self.form.add_child(ButtonInput(self.form, self.event))
        self.expected_html = '<input name="event.test-aname?" id="id-event-46-test-aname-63-" form="test" type="submit" value="click me" class="reahl-primitiveinput">'
        self.field_controls_visibility = False

    @scenario
    def password(self):
        self.widget = self.form.add_child(PasswordInput(self.form, self.field))
        self.expected_html = '<input name="test-an_attribute" id="id-test-an_attribute" form="test" type="password" class="reahl-primitiveinput">'
        self.field_controls_visibility = True

    def setup_checkbox_scenario(self, boolean_value):
        self.model_object.an_attribute = boolean_value

        self.field = BooleanField(required=True, label='my text', required_message='$label is needed here')
        self.field.bind('an_attribute', self.model_object)

        self.widget = self.form.add_child(CheckboxInput(self.form, self.field))
        self.field_controls_visibility = True

    @scenario
    def checkbox_true(self):
        """A checkbox needs a 'checked' an_attribute if its field is True. It also renders ONLY the
            validation message for its required validation_constraint, not for all constraints"""
        self.setup_checkbox_scenario(True)
        self.expected_html = '<input name="test-an_attribute" id="id-test-an_attribute" checked="checked" data-false-boolean-value="off" data-is-boolean="" data-msg-required="my text is needed here" data-true-boolean-value="on" form="test" required="*" type="checkbox" class="reahl-primitiveinput">'

    @scenario
    def checkbox_false(self):
        self.setup_checkbox_scenario(False)
        self.expected_html = '<input name="test-an_attribute" id="id-test-an_attribute" data-false-boolean-value="off" data-is-boolean="" data-msg-required="my text is needed here" data-true-boolean-value="on" form="test" required="*" type="checkbox" class="reahl-primitiveinput">'

    @scenario
    def text_area_input(self):
        self.widget = self.form.add_child(TextArea(self.form, self.field, rows=30, columns=20))
        self.expected_html = '<textarea name="test-an_attribute" id="id-test-an_attribute" cols="20" rows="30" class="reahl-primitiveinput">field value</textarea>'
        self.field_controls_visibility = True

    @scenario
    def select_input(self):
        self.model_object.an_attribute = 2

        choices = [Choice(False, BooleanField(label='None')),
                   ChoiceGroup('grouped', [
                       Choice(1, IntegerField(label='One')),
                       Choice(2, IntegerField(label='Two'))])
                  ]
        self.field = ChoiceField(choices)
        self.field.bind('an_attribute', self.model_object)

        self.widget = self.form.add_child(SelectInput(self.form, self.field))
        group = '<optgroup label="grouped">'+\
                                  '<option id="id-test-an_attribute-1" value="1">One</option>'+\
                                  '<option id="id-test-an_attribute-2" selected="selected" value="2">Two</option>'+\
                '</optgroup>'
        option = '<option id="id-test-an_attribute-off" value="off">None</option>'
        self.expected_html = r'<select name="test-an_attribute" id="id-test-an_attribute" form="test" class="reahl-primitiveinput">%s%s</select>' % (option, group)
        self.field_controls_visibility = True

    @scenario
    def select_input_multi(self):
        self.model_object.an_attribute = [2]

        choices = [Choice(1, IntegerField(label='One')),
                   Choice(2, IntegerField(label='Two'))]
        self.field = MultiChoiceField(choices)
        self.field.bind('an_attribute', self.model_object)

        self.widget = self.form.add_child(SelectInput(self.form, self.field))
        options = '<option id="id-test-an_attribute-91--93--1" value="1">One</option><option id="id-test-an_attribute-91--93--2" selected="selected" value="2">Two</option>'
        self.expected_html = '<select name="test-an_attribute[]" id="id-test-an_attribute-91--93-" form="test" multiple="multiple" class="reahl-primitiveinput">%s</select>' % (options)
        self.field_controls_visibility = True

    @scenario
    def checkbox_input_multi(self):
        selected_checkboxes = [2, 3]
        self.model_object.an_attribute = selected_checkboxes

        choices = [Choice(1, IntegerField(label='One')),
                   Choice(2, IntegerField(label='Two')),
                   Choice(3, IntegerField(label='Three'))
                  ]
        self.field = MultiChoiceField(choices)
        self.field.bind('an_attribute', self.model_object)

        self.widget = self.form.add_child(CheckboxSelectInput(self.form, self.field))
        not_checked_option = r'<label><input name="test-an_attribute[]" id="id-test-an_attribute-91--93--1" form="test" type="checkbox" value="1">One</label>'
        checked_options = r'<label><input name="test-an_attribute[]" id="id-test-an_attribute-91--93--2" checked="checked" form="test" type="checkbox" value="2">Two</label>'
        checked_options += r'<label><input name="test-an_attribute[]" id="id-test-an_attribute-91--93--3" checked="checked" form="test" type="checkbox" value="3">Three</label>'
        options = not_checked_option + checked_options
        self.expected_html = r'<div class="reahl-checkbox-input reahl-primitiveinput">%s</div>' % (options)
        self.field_controls_visibility = True

    @scenario
    def radio_button(self):
        self.model_object.an_attribute = 2

        choices = [ Choice(1, IntegerField(label='One')),
                    Choice(2, IntegerField(label='Two'))]
        self.field = ChoiceField(choices)
        self.field.bind('an_attribute', self.model_object)

        self.widget = self.form.add_child(RadioButtonSelectInput(self.form, self.field))

        radio_button = '<label>'\
                       '<input name="test-an_attribute" id="id-test-an_attribute-%s"%s '\
                              'data-msg-pattern="an_attribute should be one of the following: 1|2" '\
                              '%s'\
                              'form="test" pattern="(1|2)" '\
                              'title="an_attribute should be one of the following: 1|2" '\
                              'type="radio" value="%s">%s'\
                       '</label>'

        outer_div = '<div class="reahl-primitiveinput reahl-radio-button-input">%s</div>'
        buttons = (radio_button % ('1', '', '', '1', 'One')) +\
                  (radio_button % ('2', ' checked="checked"', '', '2', 'Two'))
        self.expected_html = outer_div % buttons
        self.field_controls_visibility = True
Exemplo n.º 22
0
 def fields(self, fields):
     fields.choice = ChoiceField([Choice(1, IntegerField(label='One')),
                                 Choice(2, IntegerField(label='Two')),
                                 Choice(3, IntegerField(label='Three'))],
                                 label='Choice')
     fields.calculated_state = IntegerField(label='Calculated', writable=Allowed(not fixture.read_only))
Exemplo n.º 23
0
 def fields(self, fields):
     fields.choice = ChoiceField([Choice(1, IntegerField(label='One')),
                                  Choice(2, IntegerField(label='Two')),
                                  Choice(3, IntegerField(label='Three'))],
                                 label='Choice')
Exemplo n.º 24
0
 def fields(self, fields):
     fields.choice = ChoiceField([
         Choice(1, IntegerField(label='1')),
         Choice(2, IntegerField(label='2'))
     ])