Commits

paj  committed edc5c8c

Add Pylons tutorial

  • Participants
  • Parent commits 6c60a35

Comments (0)

Files changed (1)

File docs/install/pylons_app.rst

 Pylons
 ======
 
-TBD: Write me
+This tutorial assumes basic familiarity with Pylons. Beginners should read the **TBD**. The tutorial was developed using Pylons 0.9.7rc4.
+
+First, create an app using the standard approach. It doesn't really matter what options you use, although this tutorial assumes mako templates and that SQLAlchemy is enabled::
+
+    $ paster create --template=pylons myapp
+    Enter template_engine (mako/genshi/jinja/etc: Template language) ['mako']:
+    Enter sqlalchemy (True/False: Include SQLAlchemy 0.4 configuration) [False]: True
+
+To enable ToscaWidget, edit ``myapp/config/middleware.py`` and add the following at the top::
+
+   import tw.api as twa
+
+And, after the line that says ``CUSTOM MIDDLEWARE HERE``, add::
+
+    app = twa.make_middleware(app, {
+        'toscawidgets.framework': 'pylons',
+        'toscawidgets.framework.default_view': 'mako',
+    })
+
+We'll now create a new controller to serve the test widget::
+
+    $ paster controller testwidget
+
+Inside the controller, we'll create the widget. Edit ``myapp/controllers/testwidget.py`` and add::
+
+    from tw.forms.samples import AddUserForm
+    test_form = AddUserForm('mytest')
+    
+In the same file, update the ``index`` method in ``TestwidgetController`` to use a template::
+
+    def index(self):
+        return render('/testwidget.mako')
+    
+We now need to create this template. Create ``myapp/templates/testwidget.mako`` with the following content::
+    
+    <%! from myapp.controllers.testwidget import test_form %>
+
+    <html>
+        <head><title>ToscaWidgets Tutorial</title></head>
+        <body>
+            <h1>Welcome to the ToscaWidgets tutorial!</h1>
+            ${test_form()}
+        </body>
+    </html>
+
+Finally, configure routing so the controller can be called. Edit ``myapp/config/routing.py`` and add (just before the ``return map`` line)::
+
+    map.connect('/testwidget', controller='testwidget')
+
+Start the app and load the ``/testwidget`` page; it should look like this:
+
+.. image:: pylons.png