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):
     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.º 3
0
 def fields(self, fields):
     """See class docstring"""
     fields.email = EmailField(required=True, label=_('Email'))
     fields.new_email = EmailField(required=True, label=_('New email'))
     fields.password = PasswordField(required=True, label=_('Password'))
     fields.stay_logged_in = BooleanField(default=False, label=_('Remember me?'))
     fields.secret = Field(required=True, label=_('Secret key'))
     fields.repeat_password = RepeatPasswordField(fields.password, required=True, label=_('Re-type password'), required_message=_('Please type your password again.'))
     fields.accept_terms = BooleanField(required=True,
                                       required_message=_('Please accept the terms of service'),
                                       default=False, label=_('I accept the terms of service'))
Exemplo n.º 4
0
def test_boolean_i18n():
    context = LocaleContextStub(locale='af').install()

    obj = EmptyStub()
    field = BooleanField()
    field.bind('boolean_attribute', obj)

    # Case: valid
    field.from_input('aan')
    assert obj.boolean_attribute is True
    assert field.as_input() == 'aan'
    field.from_input('af')
    assert obj.boolean_attribute is False
    assert field.as_input() == 'af'
Exemplo n.º 5
0
def test_marshalling_of_checkbox_input(web_fixture, checkbox_fixture):
    """When a form is submitted, the value of a checkbox is derived from
       whether the checkbox is included in the submission or not."""

    fixture = checkbox_fixture
    fixture.field = BooleanField(label='my text')

    model_object = fixture.model_object
    wsgi_app = web_fixture.new_wsgi_app(child_factory=fixture.new_Form(input_widget_class=CheckboxInput).factory('myform'))
    web_fixture.reahl_server.set_app(wsgi_app)
    web_fixture.driver_browser.open('/')

    # Case: checkbox is submitted with form (ie checked)
    web_fixture.driver_browser.set_selected("//input[@type='checkbox']")
    web_fixture.driver_browser.click("//input[@value='click me']")

    assert model_object.an_attribute
    assert fixture.checkbox.value == 'on'

    # Case: checkbox is not submitted with form (ie unchecked)
    web_fixture.driver_browser.set_deselected("//input[@type='checkbox']")
    web_fixture.driver_browser.click("//input[@value='click me']")

    assert not model_object.an_attribute
    assert fixture.checkbox.value == 'off'
Exemplo n.º 6
0
 def static_column(self):
     """StaticColumn represents an attribute of the item in a row, using a Field to translate the value of that attribute into a string and to specify a column header."""
     self.column = StaticColumn(BooleanField(label=self.heading),
                                'some_attribute',
                                sort_key=self.sort_key)
     self.expected_cell_html = 'on'  # as translated by BooleanField
     self.expected_heading_html = '<span>A heading</span>'
Exemplo n.º 7
0
def test_checkbox_input_restricted_to_use_with_boolean(web_fixture):
    """CheckboxInput is for toggling a true or false answer."""
    model_object = web_fixture
    form = Form(web_fixture.view, 'test')

    # case: with BooleanField
    boolean_field = BooleanField(label='Boolean')
    boolean_field.bind('a_choice', model_object)
    with expected(NoException):
        CheckboxInput(form, boolean_field)

    # case: with disallowed field
    not_a_boolean_field = IntegerField(label='Other')
    not_a_boolean_field.bind('not_a_boolean', model_object)

    with expected(IsInstance):
        CheckboxInput(form, not_a_boolean_field)
Exemplo n.º 8
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.º 9
0
    def boolean_i18n(self, fixture):
        @stubclass(ExecutionContext)
        class AfrikaansContext(ExecutionContext):
            @property
            def interface_locale(self):
                return 'af'
            
        with AfrikaansContext():
            obj = EmptyStub()
            field = BooleanField()
            field.bind('boolean_attribute', obj)

            # Case: valid
            field.from_input('aan')
            vassert( obj.boolean_attribute is True )
            vassert( field.as_input() == 'aan' )
            field.from_input('af')
            vassert( obj.boolean_attribute is False )
            vassert( field.as_input() == 'af' )
Exemplo n.º 10
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.º 11
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.º 12
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.º 13
0
 def fields(self, fields):
     fields.update_copies(super(TablePageIndex, self).fields)
     fields.sort_column_number = IntegerField(required=False, default=self.sort_column_number)
     fields.sort_descending = BooleanField(required=False, default=self.sort_descending)
Exemplo n.º 14
0
    def fields(self, fields):
        fields.name = Field(label='Name',
                            required=True,
                            writable=Action(self.user_may_edit))
        fields.email_address = EmailField(label='Email',
                                          required=self.is_user_super_user(),
                                          writable=Action(
                                              self.is_user_super_user))

        fields.surname = Field(label='Surname',
                               required=True,
                               writable=Action(self.user_may_edit))
        fields.username_on_za = Field(label='Username on za.pycon.org',
                                      required=True,
                                      writable=Action(self.user_may_edit))
        fields.origin_country = Field(label='Country of origin',
                                      required=True,
                                      writable=Action(self.user_may_edit))
        fields.resident_country = Field(label='Country of residence',
                                        required=True,
                                        writable=Action(self.user_may_edit))
        fields.motivation = Field(label='Motivation',
                                  required=True,
                                  writable=Action(self.user_may_edit))

        fields.willing_to_help = BooleanField(
            label='Are you willing to help out at the event?',
            writable=Action(self.user_may_edit))

        fields.total_expenses = IntegerField(label='Total expenses',
                                             required=True,
                                             writable=Action(
                                                 self.user_may_edit))
        fields.amount_requested = IntegerField(label='Aid amount requested',
                                               required=True,
                                               writable=Action(
                                                   self.user_may_edit))
        fields.budget_own_contribution = IntegerField(label='Own contribution',
                                                      required=True,
                                                      writable=Action(
                                                          self.user_may_edit))
        fields.budget_ticket = IntegerField(label='Conference ticket',
                                            writable=Action(
                                                self.user_may_edit))
        fields.budget_travel = IntegerField(label='Travel',
                                            writable=Action(
                                                self.user_may_edit))
        fields.budget_accommodation = IntegerField(label='Accommodation',
                                                   writable=Action(
                                                       self.user_may_edit))
        fields.budget_food = IntegerField(label='Food',
                                          writable=Action(self.user_may_edit))
        fields.budget_transport = IntegerField(label='Local transport',
                                               writable=Action(
                                                   self.user_may_edit))
        fields.budget_other = IntegerField(label='Other expenses',
                                           writable=Action(self.user_may_edit))
        fields.budget_other_describe = Field(
            label='Explaination of other expenses',
            writable=Action(self.user_may_edit))

        fields.allow_user_changes = BooleanField(
            label='Allow user changes',
            default=True,
            readable=Action(self.is_user_super_user),
            writable=Action(self.is_user_super_user))

        fields.number_talks_proposed = IntegerField(
            label='Number of talks proposed',
            readable=Action(self.is_user_super_user),
            writable=Action(self.is_user_super_user))
        fields.number_talks_accepted = IntegerField(
            label='Number of talks accepted',
            readable=Action(self.is_user_super_user),
            writable=Action(self.is_user_super_user))
        fields.number_keynote_talks = IntegerField(
            label='Number of talks accepted as keynote',
            readable=Action(self.is_user_super_user),
            writable=Action(self.is_user_super_user))

        fields.grant_status = Field(label='Application status',
                                    writable=Action(self.is_user_super_user))
        fields.feedback_message = Field(label='Feedback',
                                        writable=Action(
                                            self.is_user_super_user))
Exemplo n.º 15
0
 def enabled_input(self):
     self.field = BooleanField(writable=lambda field: True)
     self.expects_disabled_class = False
Exemplo n.º 16
0
 def new_field(self):
     return BooleanField(label='Subscribe to newsletter?')
Exemplo n.º 17
0
 def fields(self, fields):
     fields.toggle_sort_descending = BooleanField(
         writable=lambda field: False)
Exemplo n.º 18
0
 def fields(self, fields):
     fields.an_attribute = BooleanField(label='Some input',
                                        required=True)
Exemplo n.º 19
0
 def fields(self, fields):
     fields.sort_column_number = IntegerField(
         required=False, default=self.sort_column_number)
     fields.sort_descending = BooleanField(required=False,
                                           default=self.sort_descending)
Exemplo n.º 20
0
 def fields(self, fields):
     fields.trigger_field = BooleanField(label='Trigger field')
     fields.nested_trigger_field = BooleanField(label='Nested trigger field')
Exemplo n.º 21
0
 def new_field(self):
     field = BooleanField()
     field.bind('field', self)
     return field
Exemplo n.º 22
0
 def fields(self, fields):
     fields.field = BooleanField(label='a checkbox')
Exemplo n.º 23
0
 class ModelObject:
     fields = ReahlFields()
     fields.field1 = IntegerField()
     fields.field2 = BooleanField()
Exemplo n.º 24
0
 def fields(self, fields):
     fields.field1 = IntegerField()
     fields.field2 = BooleanField()
Exemplo n.º 25
0
 def new_field(self):
     return BooleanField(label='my text')
Exemplo n.º 26
0
def test_boolean_validation(fixture):

    obj = EmptyStub()
    field = BooleanField()
    field.bind('boolean_attribute', obj)

    # Case: invalid
    invalid_boolean_name = ['negative', 'affirmative', '+', '-', None]
    for boolean_candidate in invalid_boolean_name:
        with expected(AllowedValuesConstraint):
            field.set_user_input(boolean_candidate)
        assert field.validation_error is field.get_validation_constraint_named(
            'pattern')

        # Case: valid
    field.from_input('on')
    assert obj.boolean_attribute is True
    assert field.as_input() == 'on'
    field.from_input('off')
    assert obj.boolean_attribute is False
    assert field.as_input() == 'off'

    # Case: required means True for BooleanField
    field = BooleanField(required=True)
    field.bind('boolean_attribute', obj)
    with expected(AllowedValuesConstraint):
        field.set_user_input('off')
    assert field.validation_error is field.get_validation_constraint_named(
        'pattern')
    with expected(NoException):
        field.from_input('on')
Exemplo n.º 27
0
 def fields(self, fields):
     fields.choice = BooleanField(label=u'Choice',
                                  true_value=u'true_value', false_value=u'false_value')
Exemplo n.º 28
0
 def fields(self, fields):
     fields.selected_by_user = BooleanField(label='')
Exemplo n.º 29
0
 def fields(self, fields):
     fields.trigger_field = BooleanField(label='Trigger field')
     fields.email = EmailField(required=True, label='Email')