我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用wtforms.TextAreaField()。
def get_node_form(node_type): """Get a procedurally generated WTForm, based on the dyn_schema and node_schema of a specific node_type. :type node_type: dict :param node_type: Describes the node type via dyn_schema, form_schema and parent """ class ProceduralForm(Form): pass parent_prop = node_type['parent'] ProceduralForm.name = StringField('Name', validators=[DataRequired()]) # Parenting if parent_prop: parent_names = ", ".join(parent_prop) ProceduralForm.parent = HiddenField('Parent ({0})'.format(parent_names)) ProceduralForm.description = TextAreaField('Description') ProceduralForm.picture = FileSelectField('Picture', file_format='image') ProceduralForm.node_type = HiddenField(default=node_type['name']) add_form_properties(ProceduralForm, node_type) return ProceduralForm()
def add_form_properties(form_class, node_type): """Add fields to a form based on the node and form schema provided. :type node_schema: dict :param node_schema: the validation schema used by Cerberus :type form_class: class :param form_class: The form class to which we append fields :type form_schema: dict :param form_schema: description of how to build the form (which fields to show and hide) """ for prop_name, schema_prop, form_prop in iter_node_properties(node_type): # Recursive call if detects a dict field_type = schema_prop['type'] if field_type == 'dict': assert prop_name == 'attachments' field = attachments.attachment_form_group_create(schema_prop) elif field_type == 'list': if prop_name == 'files': schema = schema_prop['schema']['schema'] file_select_form = build_file_select_form(schema) field = FieldList(CustomFormField(file_select_form), min_entries=1) elif 'allowed' in schema_prop['schema']: choices = [(c, c) for c in schema_prop['schema']['allowed']] field = SelectMultipleField(choices=choices) else: field = SelectMultipleField(choices=[]) elif 'allowed' in schema_prop: select = [] for option in schema_prop['allowed']: select.append((str(option), str(option))) field = SelectField(choices=select) elif field_type == 'datetime': if form_prop.get('dateonly'): field = DateField(prop_name, default=date.today()) else: field = DateTimeField(prop_name, default=datetime.now()) elif field_type == 'integer': field = IntegerField(prop_name, default=0) elif field_type == 'float': field = FloatField(prop_name, default=0.0) elif field_type == 'boolean': field = BooleanField(prop_name) elif field_type == 'objectid' and 'data_relation' in schema_prop: if schema_prop['data_relation']['resource'] == 'files': field = FileSelectField(prop_name) else: field = StringField(prop_name) elif schema_prop.get('maxlength', 0) > 64: field = TextAreaField(prop_name) else: field = StringField(prop_name) setattr(form_class, prop_name, field)