StackFoundry LCC
 
yyafl - Yann's Yet Another Form Library

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:

News

Jan 22, 2009 yyafl 0.2.1 released. Includes numerous fixes for the decorator framework, in addition to some small refactorings for consistency.

Jan 5, 2009 yyafl 0.2.0 released. Get it today.

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.1 (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

Valid XHTML 1.1 Valid CSS!