Created
February 27, 2012 22:14
-
-
Save witsch/1927484 to your computer and use it in GitHub Desktop.
dynamic forms on deform
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from colander import MappingSchema, SchemaNode, String | |
from deform import Form | |
def magnet(schema): | |
def decorator(node): | |
for child in node().children: | |
schema.add(child) | |
return node | |
return decorator | |
class CommentSchema(MappingSchema): | |
""" dynamically constructed schema """ | |
schema = CommentSchema() | |
schema_magnet = magnet(schema) | |
# in this package... | |
@schema_magnet | |
class Comment(MappingSchema): | |
username = SchemaNode(String(), title='First name') | |
fullname = SchemaNode(String(), title='Last name') | |
email = SchemaNode(String()) | |
title = SchemaNode(String()) | |
text = SchemaNode(String()) | |
# in some other package... | |
@schema_magnet | |
class Captcha(MappingSchema): | |
captcha = SchemaNode(String()) | |
# again in this package... | |
form = Form(schema, button=['send']) | |
print form.render() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment