Browse files

Remove some references to tw1 in core parts of the doc

  • Loading branch information...
1 parent d810333 commit 6e30eabce9e8fcf2841132e1ff9e850603cb519a @amol- amol- committed Mar 25, 2012
@@ -27,11 +27,11 @@ Defining The Validator
First we will need to define our ProcessCard() class which will be the
chained FancyValidator for processing the card::
- import tw.forms as twf
+ from formencode import FancyValidator, Invalid
from authorize import aim as aim_api
# FancyValidator to process the Credit Card using the authorize package
- class ProcessCard(twf.validators.FancyValidator):
+ class ProcessCard(FancyValidator):
def _to_python(self, value, state):
# Setup the aim Api object.
aim = aim_api.Api(AUTHNET_LOGIN, AUTHNET_KEY, is_test=False)
@@ -49,13 +49,14 @@ chained FancyValidator for processing the card::
return value
# failure
- raise twf.validators.Invalid(result_dict['reason_text'], value, state)
+ raise Invalid(result_dict['reason_text'], value, state)
Defining The Form
Next we'll define our form class that will end up being passed to the
+view. This example defines the form using ToscaWidgets1, but it should
+be fairly simple to adapt it to ToscaWidgets2 which is now the default::
from tw.api import WidgetsList
@@ -46,7 +46,7 @@ easy to use forms creation & validation framework:
| Security Framework: | Security component | ``repoze.who`` & ``repoze.what`` |
-| Forms Framework: | Form helper | ``tw.forms`` & ``formencode`` |
+| Forms Framework: | Form helper | ``tw2.forms`` & ``formencode`` |
| Caching Framework: | Yes | ``beaker`` |
@@ -264,7 +264,7 @@ TurboGears equivalent that is typically used:
| Cache | ``beaker`` |
-| Form | ``tw.forms`` and/or ``sprox`` |
+| Form | ``tw2.forms`` and/or ``sprox`` |
| HTML | ``webhelpers.html`` |
@@ -6,7 +6,7 @@ DataGrid Tutorial
DataGrid is a quick way to present data in tabular form.
The columns to put inside the table are specified with the *fields* constructor argument in a list.
-Each entry of the list can be an accessor (attribute name or function), a tuple (title, accessor) or a ``tw.forms.datagrid.Column`` instance.
+Each entry of the list can be an accessor (attribute name or function), a tuple (title, accessor) or a ``tw2.forms.datagrid.Column`` instance.
Preparing Application
@@ -42,7 +42,7 @@ Basic DataGrid
With a model and some data set up, we can now start declaring our DataGrid and the fields it has to show::
- from tw.forms import DataGrid
+ from tw2.forms import DataGrid
addressbook_grid = DataGrid(fields=[
('Name', 'name'),
@@ -64,7 +64,7 @@ Now the grid can be displayed in the template like this:
Template code necessary to show the grid in ``templates/index.html``::
- <div>${grid(data)}</div>
+ <div>${grid(value=data)}</div>
Paginating DataGrid
@@ -95,7 +95,7 @@ a working pagination for our datagrid.
Template in ``templates/index.html`` would become::
- <div>${grid(data)}</div>
+ <div>${grid(value=data)}</div>
Now the page should render with both the datagrid and the pages under the grid itself, making possible to switch between the pages.
@@ -104,14 +104,14 @@ Sorting Columns
DataGrid itself does not provide a way to implement columns sorting, but it can be easilly achieved by inheriting
-from ``tw.forms.datagrid.Colun`` to add a link that can provide sorting.
+from ``tw2.forms.datagrid.Column`` to add a link that can provide sorting.
.. highlight:: python
First of all we need to declare or SortableColumn class that will return the link with the sorting request as the title for our DataGrid::
from sqlalchemy import asc, desc
- from tw.forms.datagrid import Column
+ from tw2.forms.datagrid import Column
import genshi
class SortableColumn(Column):
@@ -193,12 +193,11 @@ complete with password verification:
from sprox.formbase import AddRecordForm
from formencode import Schema
from formencode.validators import FieldsMatch
- from tw.forms import PasswordField, TextField
+ from tw2.forms import PasswordField, TextField
- form_validator = Schema(chained_validators=(FieldsMatch('password',
- 'verify_password',
- messages={'invalidNoMatch':
- 'Passwords do not match'}),))
+ form_validator = FieldsMatch('password', 'verify_password',
+ messages={'invalidNoMatch': 'Passwords do not match'})
class RegistrationForm(AddRecordForm):
__model__ = User
__require_fields__ = ['password', 'user_name', 'email_address']
@@ -227,49 +227,6 @@ database using :class:`sprox.formbase.AddRecordForm`::
__omit_fields__ = ['genre_id', 'movie_id']
movie_add_form = MovieAddForm(DBSession)
-You might be wondering about what is behind-the-scenes of Sprox that
-allows it to generate widgets. The package responsible for building
-the widgets is called `ToscaWidgets
-<>`_. It makes no
-decisions about how the widgets should be created, it only does what
-you tell it. Since both TW and Sprox produce widgets, you may use
-them interchangeably within CrudRestController. Therefore, if Sprox
-is not providing the behavior for your widgets that you desire, you
-can drop-down to the lower-level TW library and still accomplish your
-goals. The same form definition in TW might look something like
- from tw.core import WidgetsList
- from tw.forms import TableForm, TextField, CalendarDatePicker, SingleSelectField, TextArea
- from formencode.validators import Int, NotEmpty, DateConverter, DateValidator
- class MovieForm(TableForm):
- # This WidgetsList is just a container
- class fields(WidgetsList):
- title = TextField(validator=NotEmpty)
- description = TextArea(attrs=dict(rows=3, cols=25))
- release_date = CalendarDatePicker(validator=DateConverter())
- genrechoices = ((1,"action"),
- (2,"animation"),
- (3,"comedy"),
- (4,"documentary"),
- (5,"drama"),
- (6,"sci-fi"))
- genre = SingleSelectField(options=genrechoices)
- #then, we create an instance of this form
- movie_add_form = MovieForm("create_movie_form")
-Notice that the TW version of the form has the genre's options
-hard-coded, where the Sprox version these are plucked from the DB.
-This could be fixed with the TW version by setting the options in the
-widget's :meth:`tw.api.Widget.update_params` function, but that topic
-is outside the scope of this tutorial. Also notice the care that must
-be taken adding validation for each field.
Adding this to your movie controller would look make it now look
something like this::
@@ -484,66 +441,6 @@ Which results in a new listing page like this.
.. image:: images/menu_items.png
-Using Dojo
-Dojo_ is a JavaScript library that
-provides AJAX_ functionality, DHTML manipulation, and other
-functionality that works across browsers.
-CrudRestController has built-in JSON_ functionality for the get_all
-function. This makes it relatively easy to integrate Dojo_ tables into
-your application. Since `Sprox supports Dojo
-<>`_ out of the box, it is simple enough to
-provide new imports for your custom tables and achieve infinitely
-scrollable tables. First, we need to install the ToscaWidgets Dojo
- easy_install tw.dojo
-Then, we create our form using Sprox's Dojo support::
- from sprox.dojo.tablebase import DojoTableBase
- class MovieTable(DojoTableBase):
- __model__ = Movie
- __omit_fields__ = ['genre_id']
- movie_table = MovieTable(DBSession)
-Then, Since Dojo has a different format to fill it's table, we must
-also provide a :class:`sprox.dojo.fillerbase.TableFiller`::
- from sprox.dojo.fillerbase import DojoTableFiller
- class MovieTableFiller(DojoTableFiller):
- __model__ = Movie
- movie_table_filler = MovieTableFiller(DBSession)
-The resulting table looks like this.
-.. image:: images/dojo_table.png
-Support for more sophisticated forms has also been added to Sprox.
-This is especially useful when you have a many to many relationship in
-your Models. For these kinds of relationships, Dojo provides Sprox
-with a ``SelectShuttle`` widget. Here is a code snippet showing how
-to use the Dojo forms in your application.::
- from sprox.dojo.formbase import DojoEditableForm
- class MovieTableFiller(DojoEditableForm):
- __model__ = Movie
- movie_table_filler = MovieTableFiller(DBSession)
-Since there are no many-to-many relationship objects in our example
-model, here is an image of the Dojo-enabled form as it appears using
-.. image:: images/dojo_form.png
CRC: The Sweet Spot
@@ -556,12 +453,5 @@ really looking for something that makes all of the forms for you, but
can be configured, take a look at the `Turbogears Admin System
-Example Project
-`Moviedemo <>`_ was created while developing these documents.
.. _JSON:
-.. _Dojo:
.. _AJAX:
@@ -8,11 +8,25 @@ Pagination Quickstart For Turbogears2
-We start where the MovieDemo left off. See the `ToscaSample`_ tutorial
-or download the zipped ToscaWidgetsFormsExample (TODO: must be
-recreated, not currently available).
+We start from an existing projects name *paginatesample* supposing a model that looks like:
-.. _ToscaSample:
+.. code-block:: python
+ class Movie(DeclarativeBase):
+ __tablename__ = 'movie'
+ id = Column(Integer, primary_key=True)
+ title = Column(String(100), nullable=False)
+ description = Column(Text, nullable=True)
+ year = Column(Integer, nullable=True)
+ genre = Column(Integer, nullable=True)
+ release_date = Column(Date, nullable=True)
+ def __str__(self):
+ if self.year:
+ return '"%s" (%d)' % (self.title, self.year)
+ else:
+ return '"%s"' % self.title
Populating The Database
@@ -59,12 +73,12 @@ Import paginate in your ``controllers/`` and modify the
from webhelpers import paginate
- @expose("toscasample.templates.movie_list")
+ @expose("paginatesample.templates.movie_list")
def list(self, page=1):
"""List and paginate all movies in the database"""
movies = DBSession.query(Movie)
currentPage = paginate.Page(movies, page, items_per_page=5)
- return dict(movies=currentPage.items, page='ToscaSample Movie list', currentPage=currentPage)
+ return dict(movies=currentPage.items, page='paginatesample Movie list', currentPage=currentPage)
This creates and passes a ``paginate.Page`` object to our template, so
we can use it there to access a ``pager()``.
@@ -120,13 +134,13 @@ combine with `expose()`. To use it, you simply have to pass it the
name of a collection to paginate. In ``controller/``::
from tg.decorators import paginate as paginatedeco
- @expose("toscasample.templates.movie_list_deco")
+ @expose("paginatesample.templates.movie_list_deco")
@paginatedeco("movies", items_per_page=5)
def decolist(self):
"""List and paginate all movies in the database using the
paginate() decorator."""
movies = DBSession.query(Movie)
- return dict(movies=movies, page='ToscaSample Movie list')
+ return dict(movies=movies, page='paginatesample Movie list')
.. highlight:: python
@@ -690,7 +690,6 @@ that you re-use throughout your app.
from tg import TGController, tmpl_context
from tg.render import render
from tg import request
- from tw.api import WidgetBunch
import my_intranet.model as model
__all__ = ['BaseController']

0 comments on commit 6e30eab

Please sign in to comment.