def create_settings_form(): """Create settings form for ZMIForm. """ form = BasicForm('manage_settings') title = fields.StringField('title', title="Title", required=False, default="") row_length = fields.IntegerField( 'row_length', title='Number of groups in row (in order tab)', required=True, default=4) name = fields.StringField('name', title="Form name", required=False, default="") action = fields.StringField('action', title='Form action', required=False, default="") method = fields.ListField('method', title='Form method', items=[('POST', 'POST'), ('GET', 'GET')], required=True, size=1, default='POST') enctype = fields.ListField('enctype', title='Form enctype', items=[('No enctype', ""), ('application/x-www-form-urlencoded', 'application/x-www-form-urlencoded'), ('multipart/form-data', 'multipart/form-data')], required=False, size=1, default=None) encoding = fields.StringField('encoding', title='Encoding of pages the form is in', default="UTF-8", required=True) stored_encoding = fields.StringField('stored_encoding', title='Encoding of form properties', default='ISO-8859-1', required=True) unicode_mode = fields.CheckBoxField('unicode_mode', title='Form properties are unicode', default=False, required=True) form.add_fields([ title, row_length, name, action, method, enctype, encoding, stored_encoding, unicode_mode ]) return form
class PatternValidator(StringValidator): # does the real work checker = PatternChecker.PatternChecker() property_names = StringValidator.property_names +\ ['pattern'] pattern = fields.StringField('pattern', title="Pattern", required=1, default="", description=( "The pattern the value should conform to. Patterns are " "composed of digits ('d'), alphabetic characters ('e') and " "alphanumeric characters ('f'). Any other character in the pattern " "should appear literally in the value in that place. Internal " "whitespace is checked as well but may be included in any amount. " "Example: 'dddd ee' is a Dutch zipcode (postcode). " "NOTE: currently experimental and details may change!") ) message_names = StringValidator.message_names +\ ['pattern_not_matched'] pattern_not_matched = "The entered value did not match the pattern." def validate(self, field, key, REQUEST): value = StringValidator.validate(self, field, key, REQUEST) if value == "" and not field.get_value('required'): return value value = self.checker.validate_value([field.get_value('pattern')], value) if value is None: self.raise_error('pattern_not_matched', field) return value