Esempio n. 1
0
 def form_example(self, ctx):
     form = formal.Form()
     # This actually installs a RequiredValidator for you.
     form.addField('required', formal.String(required=True))
     # Exactly the same as above, only with a "manually" installed validator.
     form.addField('required2',
                   formal.String(validators=[formal.RequiredValidator()]))
     # Check for a minimum length, if anything entered.
     form.addField(
         'atLeastFiveChars',
         formal.String(validators=[formal.LengthValidator(min=5)]))
     # Check for a minimum length, if anything entered.
     form.addField(
         'ipAddress',
         formal.String(strip=True,
                       validators=[
                           formal.PatternValidator(regex=IP_ADDRESS_PATTERN)
                       ]))
     # Check for the word 'silly'
     form.addField('silly', formal.String(validators=[SillyValidator()]))
     # Check age is between 18 and 30
     form.addField(
         'ohToBeYoungAgain',
         formal.Integer(validators=[formal.RangeValidator(min=18, max=30)]))
     form.addAction(self.submitted)
     return form
Esempio n. 2
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('hiddenString', formal.String(), widgetFactory=formal.Hidden)
     form.addField('hiddenInt', formal.Integer(), widgetFactory=formal.Hidden)
     form.addField('visibleString', formal.String())
     form.addAction(self.submitted)
     form.data = {
         'hiddenString': 'foo',
         'hiddenInt': 1,
     }
     return form
Esempio n. 3
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('restString',
                   formal.String(required=True),
                   widgetFactory=formal.ReSTTextArea)
     if docutilsAvailable:
         w = Writer()
         w.translator_class = CustomisedHTMLTranslator
         form.addField(
             'customRestString', formal.String(required=True),
             formal.widgetFactory(formal.ReSTTextArea, restWriter=w))
     form.addAction(self.submitted)
     return form
Esempio n. 4
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('aString', formal.String())
     form.addField('aTime', formal.Time())
     form.addAction(self.submitted)
     form.data = {
         'aTime': datetime.utcnow().time(),
     }
     return form
    def form_example(self, ctx):
        form = formal.Form()
        form.addField('required', formal.String(required=True))
        form.addField('file', formal.File(), formal.FileUploadWidget)
        form.addField(
            'removeableFile', formal.File(),
            formal.widgetFactory(formal.FileUploadWidget, removeable=True))

        form.addAction(self.submitted)
        return form
Esempio n. 6
0
    def form_example(self, ctx):
        form = formal.Form()
        form.addField(
            'myTextArea', formal.String(),
            formal.widgetFactory(TextAreaWithSelect,
                                 values=(('aval', 'alabel'), ('bval',
                                                              'blabel'))))

        form.addAction(self.submitted)
        return form
Esempio n. 7
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('aString', formal.String())
     form.addField('aInteger', formal.Integer())
     form.addField('aFloat', formal.Float())
     if haveDecimal:
         form.addField('aDecimal', formal.Decimal())
     form.addField('aBoolean', formal.Boolean())
     form.addField('aDate', formal.Date())
     form.addField('aTime', formal.Time())
     form.addAction(self.submitted)
     return form
Esempio n. 8
0
    def form_example(self, ctx):
        def makeAddressGroup(name):
            address = formal.Group(name)
            address.add(formal.Field('address', formal.String()))
            address.add(formal.Field('city', formal.String()))
            address.add(formal.Field('postalCode', formal.String()))
            return address

        def makePersonGroup(name):
            person = formal.Group(name, cssClass=name)
            person.add(formal.Field('name', formal.String(required=True)))
            person.add(formal.Field('dateOfBirth', formal.Date(required=True)))
            person.add(makeAddressGroup('address'))
            return person

        form = formal.Form()
        form.add(formal.Field('before', formal.String()))
        form.add(makePersonGroup('me'))
        form.add(makePersonGroup('you'))
        form.add(formal.Field('after', formal.String()))
        form.addAction(self.submitted)

        return form
Esempio n. 9
0
 def form_setDowntime(self, ctx):
     form = formal.Form()
     form.addField(
         "scheduled",
         formal.String(),
         label="Schedule downtime for",
         description="Note that this is purely informative.  The server"
         " will not take down the services at this point in time."
         " Leave empty to cancel.  This will also be cleared on a"
         " reload.")
     form.addAction(self.setDowntime, label="Ok")
     form.data = {
         "scheduled": base.getMetaText(self.clientRD, "_scheduledDowntime")
     }
     return form
Esempio n. 10
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('aString', formal.String(required=True))
     form.addAction(self.submitted, label="Click, click, clickety-click!")
     form.addAction(self.redirect, 'back', validate=False)
     return form
Esempio n. 11
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('name', formal.String(required=True))
     form.addField('age', formal.Integer())
     form.addAction(self.submitted)
     return form
Esempio n. 12
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('aString', formal.String(missing='<nothing>'))
     form.addField('aDate', formal.Date(missing=date(2005, 8, 1)))
     form.addAction(self.submitted)
     return form
Esempio n. 13
0
 def form_example(self, ctx):
     form = formal.Form()
     form.addField('aString', formal.String())
     form.addAction(self.submitted)
     return form
Esempio n. 14
0
    def form_example(self, ctx):
        form = formal.Form()
        form.addField('required', formal.String(required=True))
        form.addField(
            'oneString', formal.String(),
            formal.widgetFactory(formal.SelectChoice, options=strings))
        form.addField(
            'anotherString', formal.String(),
            formal.widgetFactory(formal.SelectChoice, options=data_strings))
        form.addField(
            'oneMoreString', formal.String(required=True),
            formal.widgetFactory(formal.RadioChoice, options=data_strings))
        form.addField('oneDate', formal.Date(),
                      formal.widgetFactory(formal.SelectChoice, options=dates))
        form.addField(
            'multipleStrings', formal.Sequence(formal.String()),
            formal.widgetFactory(formal.CheckboxMultiChoice,
                                 options=data_strings))
        form.addField(
            'multipleDates', formal.Sequence(formal.Date()),
            formal.widgetFactory(formal.CheckboxMultiChoice, options=dates))

        form.addField(
            'multipleTuples', formal.Sequence(formal.Sequence()),
            formal.widgetFactory(formal.CheckboxMultiChoice, options=tuples))

        form.addField(
            'differentNoneSelect', formal.String(),
            formal.widgetFactory(formal.SelectChoice,
                                 options=strings,
                                 noneOption=differentNone))
        form.addField(
            'differentNoneRadios', formal.String(),
            formal.widgetFactory(formal.RadioChoice,
                                 options=data_strings,
                                 noneOption=differentNone))
        form.addField(
            'selectOther', formal.String(),
            formal.widgetFactory(formal.SelectOtherChoice,
                                 options=['Mr', 'Mrs']))
        form.addField(
            'selectOtherCustomOther', formal.String(),
            formal.widgetFactory(formal.SelectOtherChoice,
                                 options=['Mr', 'Mrs'],
                                 otherOption=('...', 'Other (Please Enter)')))
        form.addField(
            'selectOtherRequired', formal.String(required=True),
            formal.widgetFactory(formal.SelectOtherChoice,
                                 options=['Mr', 'Mrs']))
        form.addField(
            'multiselect', formal.String(),
            formal.widgetFactory(formal.MultiselectChoice, options=strings))
        form.addAction(self.submitted)
        return form
Esempio n. 15
0
 def makePersonGroup(name):
     person = formal.Group(name, cssClass=name)
     person.add(formal.Field('name', formal.String(required=True)))
     person.add(formal.Field('dateOfBirth', formal.Date(required=True)))
     person.add(makeAddressGroup('address'))
     return person
Esempio n. 16
0
 def makeAddressGroup(name):
     address = formal.Group(name)
     address.add(formal.Field('address', formal.String()))
     address.add(formal.Field('city', formal.String()))
     address.add(formal.Field('postalCode', formal.String()))
     return address