Example #1
0
 def test_ChoiceField(self):
     field = forms.ChoiceField()
     self.assertEqual(field.attrs.get('name'), None)
     #
     self.assertEqual(field.options.all(), ())
     attrs = field.getattrs()
     self.assertEqual(attrs['options'], ())
     #
     field = forms.ChoiceField(options=('bla', 'foo'))
     self.assertEqual(field.options.all(), ('bla', 'foo'))
     attrs = field.getattrs()
     self.assertEqual(attrs['options'], ('bla', 'foo'))
Example #2
0
class TaskForm(forms.Form):
    model = 'tasks'
    subject = forms.CharField()
    done = forms.BooleanField(default=False)
    assigned = RelationshipField('people', required=False)
    enum_field = forms.ChoiceField(options=TestEnum, default='opt1')
    desc = forms.CharField(required=False)
Example #3
0
class SimpleForm(Mixin1, Mixin):
    name = forms.CharField(minlength=2, maxlength=30)
    email = forms.CharField(required=False)
    rank = forms.IntegerField(required=False)
    dt = forms.DateField(required=False)
    timestamp = forms.DateTimeField(required=False)
    enum_field = forms.ChoiceField(required=False, options=TestEnum)
Example #4
0
 def test_ChoiceField_Enum(self):
     field = forms.ChoiceField(options=TestEnum)
     self.assertEqual(field.attrs.get('name'), None)
     #
     self.assertEqual(field.options.all(), ['opt1', 'opt2'])
     attrs = field.getattrs()
     self.assertEqual(attrs['options'], ['opt1', 'opt2'])
Example #5
0
    def test_options_call(self):
        result = [(1, 'uno'), (2, 'due'), (3, 'tre')]

        def opts(form):
            self.assertEqual(form, None)
            return result

        field = forms.ChoiceField('foo', options=opts)
        self.assertEqual(field.options.all(), result)
        #
        self.assertEqual(repr(field), 'foo')
Example #6
0
class PageForm(forms.Form):
    '''The form for editing and adding a new page to the CMS.'''
    url = forms.CharField(widget_attrs={'readonly': 'readonly'})
    title = forms.CharField(required=False)
    body_class = forms.CharField(required=False)
    template = forms.ChoiceField(choices=template_choice)
Example #7
0
class PageForm(forms.Form):
    url = forms.CharField()
    markup = forms.ChoiceField(options=('bla', 'foo'))
    body = forms.CharField(type='textarea', required=False)
Example #8
0
class EntityMixin(forms.Form):
    timezone = forms.ChoiceField(options_url=lambda request: api_url(
        request, '%s/timezones' % request.config['API_INFO_URL']),
                                 options=common_timezones,
                                 required=False)
    link = forms.UrlField(label='Home page', required=False)
Example #9
0
class OrgMemberForm(forms.Form):
    role = forms.ChoiceField(options=MemberRole,
                             default=MemberRole.member.name)
    private = forms.BooleanField(required=False)
Example #10
0
 def test_options(self):
     opts = ('uno', 'due', 'tre')
     field = forms.ChoiceField(options=opts)
     self.assertEqual(field.options.all(), list(opts))
     self.assertEqual(field.options.get_initial(), 'uno')
Example #11
0
 def test_ChoiceField_Options(self):
     opts = [{'value': 'a', 'repr': 'foo'},
             {'value': 'b', 'repr': 'hello'}]
     field = forms.ChoiceField(options=opts)
     self.assertEqual(field.options.all(), opts)
     self.assertEqual(field.options.get_initial(), 'a')