Atsushi Odagiri avatar Atsushi Odagiri committed b3bfb22

garden forms

Comments (0)

Files changed (5)

crosswiki/forms.py

+import colander as c
+import deform.widget as w
+
+
+class PageSchema(c.MappingSchema):
+    content = c.SchemaNode(c.String(),
+        widget=w.TextAreaWidget())

crosswiki/templates/create_page_form.mak

 <html>
-<form method="POST">
-<textarea name='content'></textarea>
-</form>
+<body>
+${form.render() | n}
+</body>
 </html>

crosswiki/views.py

+from deform.form import Form
 from pyramid.view import view_config
 from pyramid.httpexceptions import HTTPFound, HTTPNotFound
 from .models import Page
 from .helpers import page_url, create_page_url
+from . import forms
+
 
 @view_config(route_name='page', renderer='page.mak')
 @view_config(route_name='edit_page', renderer='edit_page.mak', request_method="GET")
 
 @view_config(route_name='create_page', request_method='GET', renderer='create_page_form.mak')
 def create_page_form(request):
-    return dict()
+    form = Form(forms.PageSchema(), buttons='create')
+    return dict(form=form)
 
-@view_config(route_name='create_page', request_method='POST')
+@view_config(route_name='create_page', request_method='POST', renderer='create_page.mak')
 def create_page(request):
+    form = Form(forms.PageSchema(), buttons='create')
+    controls = request.params.items()
+    try:
+        params = form.validate(controls)
+    except ValidationFailure, e:
+        return dict(form=e)
+
     page = Page(page_name=request.matchdict['page_name'],
-        content=request.params['content'])
+        content=params['content'])
     request.context.add(page)
 
     return HTTPFound(location=page_url(request, page))
 Mako==0.5.0
 MarkupSafe==0.15
 PasteDeploy==1.5.0
+Pillow==1.7.5
 Pygments==1.4
 SQLAHelper==1.0
 SQLAlchemy==0.7.4
 WebOb==1.2b2
 WebTest==1.3.3
+colander==0.9.5
 coverage==3.5.1
+deform==0.9.3
 distribute==0.6.24
 docutils==0.8.1
+iso8601==0.1.4
 lxml==2.3.3
 mock==0.7.2
 nose==1.1.2
+peppercorn==0.3
 pyramid==1.3a5
 pyramid-debugtoolbar==0.9.8
 pyramid-tm==0.3
     'pyramid_tm',
     'sqlahelper',
     'pillow',
+    'colander',
+    'deform',
     ]
 
 setup(name='crosswiki',
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 ProjectModifiedEvent.java.
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.