My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
Declaratives  
dbsprockets declaratives allow for easy class-based form creation
declaratives, Featured
Updated Feb 4, 2010 by perciou...@gmail.com

Declaratives

dbsprockets.declaratives is intended to allow the programmer create only the form/record/table view associated with the SA object they are using. This is a very powerful approach to creating forms, not unlike newforms in Django.

FormBase

Take a look a the simplest example, a login form:

from dbsprockets.declaratives import FormBase
from myProject.myModel import User

class LoginForm(FormBase):
    __model__ = User
    __limit_fields__ = 'username', 'password'

login_form = LoginForm()

In your template, you would render the form like this:

${login_form()}

Here is what the form looks like:

More information about the [wiki:demoModel model] that created this form.

TableBase

And here is an example showing what it looks like to display a list of users:

from dbsprockets.declaratives import TableBase
from dbsprockets.primitives import get_table_value
from myProject import User
     
class UserTable(TableBase):
    __model__ = User

user_table = UserTable()
value = get_table_value(User)

user_table(value=value)

Which when rendered through a web framework looks something like this:

Notice that the town name (Arvada) has been automatically added.

RecordBase

And here is an example of how to display a single record:

from dbsprockets.declaratives import RecordBase
from myProject.model import User, DBSession 

class UserRecord(RecordBase):
    __model__ = user

user_record = UserRecord()
value = DBSession.query(User).first()
user_table(value)

Sign in to add a comment
Powered by Google Project Hosting