Inspired heavily by Django newforms, yyafl is a partial-reimplementation and adaptation of the 'newforms' library to exist outside of the Django infastructure, letting it be used in other frameworks, such as CherryPy and Pylons. YYAFL extends the newforms model with new features:
- CSRF detection form tools can be automatically managed.
- Pluggable and skinnable forms, use either pure Python code or a compatible templating engine (such as Mako). Attach on the fly decorators or even apply whole layouts to forms.
- Comprehensive validation framework.
- Comprehensive widget collection, which is easy to grow, tweak, or extend for your application's needs.
News
Jan 5, 2009 yyafl 0.2.0 released. Get it today. 0.2.0 is the current stable version.
For more updates and musings on yyafl, see the blog posts.
Example
As yyafl borrows heavily from newforms, much of the syntax is the same. To create a form instance, you can do:
import yyafl
import yyafl.fields
class MyForm(yyafl.Form):
name = yyafl.fields.CharField()
email = yyafl.fields.EmailField()
A more complete example, with a default layout and using the form:
import yyafl.layout
import yyafl
from yyafl import fields
from yyafl.widgets import HiddenInput
class Form1(yyafl.Form):
# Two user filled forms
name = fields.CharField(label = "User name", required = True)
email = fields.CharField(label = "Your e-mail address", required = True)
# A hidden field
hidden = fields.CharField(widget = HiddenInput, default = "123")
# Define a default layout
_layout = yyafl.layout.TableLayout()
def webapp_handler(*args, **kwargs):
content = u""
# Create a form object from our form and pass it the request (POST) data.
f = Form1(data = kwargs)
# Check if the form is validated
if f.is_valid() == False:
# Handle form errors, stored in f.errors
pass
elif f.is_bound and f.is_valid():
# Handle form success here
pass
# Draw the form, including any widgets, decorators, or filled out data
# Note that this will typically be called by your templating system
content += f.render()
return content
Download
Version 0.2.0 (stable) is available for immediate cosumption. Download includes a set of examples (see examples/) which use CherryPy and various levels of integration with yyafl. [ Main download site ] [ PyPi ]
Repository
yyafl development is tracked in git. To clone:
git clone git://git.stackfoundry.com/yyafl.git
