Permalink
Browse files

polishing the example app

  • Loading branch information...
1 parent d798e16 commit 5614fecc1cf49396cb747ba49cd52b14785f0b55 @gustavofonseca gustavofonseca committed with alvesjnr May 31, 2011
Showing with 78 additions and 36 deletions.
  1. +33 −21 examples/bibitex/bibitex.py
  2. +19 −0 examples/bibitex/form.pt
  3. +26 −0 examples/bibitex/index.pt
  4. +0 −15 examples/bibitex/template.pt
View
54 examples/bibitex/bibitex.py
@@ -10,29 +10,38 @@
import deform
import couchdbkit
+def new(request):
+ bibitex_form = BibitexForm.get_form()
+ if 'submit' in request.POST:
+ controls = request.POST.items()
+ try:
+ appstruct = bibitex_form.validate(controls)
+ except deform.ValidationFailure, e:
+ return render_to_response('bibitex:form.pt',
+ {'content': e.render()})
-def hello_world(request):
- return Response('Hello world!')
+ bibitex = Bibitex.from_python(appstruct)
+ bibitex.save(db)
-def goodbye_world(request):
- return Response('Goodbye world!')
+ return Response('Saved under id: %s' % bibitex._id)
+ else:
+ if 'id' in request.matchdict: #edit
+ bibitex = Bibitex.get(db, request.matchdict['id'])
+
+ return render_to_response('bibitex:form.pt',
+ {'content': bibitex_form.render(bibitex.to_python())})
+
+ return render_to_response('bibitex:form.pt',
+ {'content': bibitex_form.render()})
-def new_entry(request):
- bibitex_form = BibitexForm.get_form()
- if 'submit' in request.POST:
- return Response('OK')
- else:
- return render_to_response('bibitex:template.pt',
- {'content': bibitex_form.render()},
- )
-def list_all(request):
- pass
+def index(request):
+ records = db.view('_all_docs', include_docs=True)
-def view_entry(request):
- pass
+ return render_to_response('bibitex:index.pt',
+ {'records':records})
if __name__ == '__main__':
@@ -45,10 +54,13 @@ def view_entry(request):
"""Adding static views"""
config.add_static_view('deform_static', 'deform:static')
- """Adding views"""
- config.add_view(list_all)
- config.add_view(new_entry, name="new_entry")
- config.add_view(view_entry, name="view_entry")
+ """Registering views and routes"""
+ config.add_view(view=index, route_name='index')
+ config.add_view(view=new, route_name='new')
+ config.add_view(view=new, route_name='edit')
+ config.add_route('index', '/')
+ config.add_route('new', '/new')
+ config.add_route('edit', '/edit/{id}')
app = config.make_wsgi_app()
- serve(app, host='0.0.0.0')
+ serve(app, host='0.0.0.0:6543')
View
19 examples/bibitex/form.pt
@@ -0,0 +1,19 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <link rel="stylesheet" href="/deform_static/css/form.css" type="text/css"></link>
+ <link rel="stylesheet" href="/deform_static/css/theme.css" type="text/css"></link>
+ <script type="text/javascript" src="/deform_static/scripts/jquery-1.4.2.min.js"></script>
+ <script type="text/javascript" src="/deform_static/scripts/deform.js"></script>
+ <script type="text/javascript">
+ deform.load()
+ </script>
+ </head>
+ <body>
+ <div>
+ <h1><a href="http://github.com/bireme/isisdm">ISISDM Sample Application</a></h1>
+ <span tal:replace="structure content"></span>
+ </div>
+ </body>
+</html>
View
26 examples/bibitex/index.pt
@@ -0,0 +1,26 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+ <head>
+ <link rel="stylesheet" href="/deform_static/css/theme.css" type="text/css"></link>
+ </head>
+ <body>
+ <div>
+ <h1><a href="http://github.com/bireme/isisdm">ISISDM Sample Application</a></h1>
+ <p><a href="/new">add</a></p>
+ <table>
+ <tr>
+ <th>Entry type</th>
+ <th>Reference name</th>
+ <th>Title</th>
+ </tr>
+ <tr tal:repeat="record records">
+ <td tal:content="record.doc.entry_type"></td>
+ <td tal:content="record.doc.reference_name"></td>
+ <td tal:content="record.doc.title"></td>
+ <td><a href="/edit/${record.id}">edit</a></td>
+ </tr>
+ </table>
+ </div>
+ </body>
+</html>
View
15 examples/bibitex/template.pt
@@ -1,15 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
-"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <script type="text/javascript" src="/deform_static/scripts/deform.js"></script>
- <script type="text/javascript">
- deform.load()
- </script>
- </head>
- <body>
- <div>
- <span tal:replace="structure content"></span>
- </div>
- </body>
-</html>

0 comments on commit 5614fec

Please sign in to comment.