pyconjp2011 / wtforms / pyconjp2011 / wtforms_demo /

import os
from webob import Request, Response
from webob.dec import wsgify
from sqlalchemy import engine_from_config
from mako.lookup import TemplateLookup
import wtforms
from wtforms.ext.sqlalchemy.fields import QuerySelectMultipleField

from .. import models

here = os.path.dirname(__file__)
templates_dir = os.path.join(here, "templates")

templates = TemplateLookup(directories=[templates_dir])

class UserForm(wtforms.Form):
    username = wtforms.TextField('User Name')
    password = wtforms.PasswordField('Password')
    groups = QuerySelectMultipleField(query_factory=lambda: models.DBSession.query(models.Group))

def index(request):
    user_form = UserForm()
    tmpl = templates.get_template('index.mak')
    return Response(tmpl.render(form=user_form))

def main(global_conf, **settings):
    engine = engine_from_config(settings)
    application = index
    return application
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.