Skip to content

Commit

Permalink
Merge pull request cguardia#4 from dag/master
Browse files Browse the repository at this point in the history
Some fixes by dag
  • Loading branch information
cguardia committed Jun 8, 2011
2 parents eca6e63 + 202d0f1 commit 49c2974
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions book/transactions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ Context manager support
-----------------------

Instead of calling commit or abort explicitly to define transaction boundaries,
its possible to use the context manager protocol and define the boundaries
it's possible to use the context manager protocol and define the boundaries
using the with statement. For example, in our SQLAlchemy examples above, we could
have used this code after setting up our session:

Expand All @@ -769,13 +769,15 @@ have used this code after setting up our session:
import transaction
session = Session()
with transaction:
with transaction.manager:
session.add(User(id=1, name='John', fullname='John Smith', password='123'))
session.add(User(id=2, name='John', fullname='John Watson', password='123'))
We can have as many statements as we like inside the with block. If an exception
occurs, the transaction will be aborted at the end. Otherwise, it will be
committed.
committed. Note that if you doom the transaction inside the context, it
will still try to commit which will result in a DoomedTransaction
exception.


Take advantage of the notes feature
Expand Down Expand Up @@ -1170,7 +1172,9 @@ transaction explicitly.
To use repoze.tm2, you first need to add it to your WSGI pipeline. If you are
using PasteDeploy for deploying your applications, that means that the
repoze.tm2 egg needs to be added to your main pipeline in your .ini
configuration file::
configuration file:

.. code-block:: ini
[pipeline:main]
pipeline =
Expand Down Expand Up @@ -1237,7 +1241,9 @@ As you can see, this commit veto looks for a header named 'x-tm-abort' or any
conditions applies.

To use your own commit veto you need to configure it into the middleware. On
PasteDeploy configurations::
PasteDeploy configurations:

.. code-block:: ini
[filter:tm]
commit_veto = my.package:commit_veto
Expand Down Expand Up @@ -1463,6 +1469,7 @@ Our application is almost ready to try, we only need to add a todo.pt template
in the same directory as the todo.py file, with the following contents:

.. literalinclude:: ../code/transaction/todo_single_file/todo.pt
:language: xml
:linenos:

Pyramid has bindings for various template languages, but comes with chameleon and
Expand All @@ -1479,7 +1486,9 @@ contains a tuple of id (key) and task. Each task is itself a tuple of descriptio
and status. These values are used to populate the form with the task list.

You can now run the application and try it out on the browser. From the root of
the virtualenv type::
the virtualenv type:

.. code-block:: console
$ bin/python todo.py
serving on 0.0.0.0:8080 view at http://127.0.0.1:8080
Expand Down

0 comments on commit 49c2974

Please sign in to comment.