-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

FYI.

- -------- Original Message --------
Subject: [storm] RFC: Storm with Pylons and Repoze.tm2
Date: Sun, 27 Jul 2008 18:29:19 +0200
From: Olaf Conradi <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]

Hello,

I modified the Zope module for Storm to use repoze.tm2 as transactions
and add a middleware layer for use with Pylons.

Let's describe it with a Pylons example:

In development.ini:

# Add repoze.tm2 in the pipeline
[pipeline:main]
pipeline = egg:Paste#cgitb
           egg:Paste#httpexceptions
           egg:repoze.tm2#tm
           your-app

In middleware.py:

# add import
from storm.tm.middleware import StormMiddleware

# inside make_app(global_conf, full_stack=True, **app_conf):

    # CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
    app = StormMiddleware(app)

In the controller of your app:

# add import
from storm.store import Store
from storm.tm.session import storm_session

from yourapp.model import Person

class MyController(BaseController):
    def index(self):
        store = storm_session.get('persondb',
config['storm.database.persons.uri'])
        c.persons = list(store.find(Person))
        return render('list.mako')

Just like the zope module had global_zstorm, this module uses
storm_session for use in your Pylons application. It's now a
StackedObjectProxy, and I think I can therefore remove the thread
local stuff from TMStorm.

A lot of code is the same between the Zope module and this module. It
would be nice to share that, and not duplicate it.

Because of repoze.tm2 each request will be a transaction, it will
abort on 401 or raised exceptions, or otherwise commit.

An example of a controller which adds a records:

    def new(self):
        store = storm_session.get('persondb',
config['storm.database.persons.uri'])
        p = Person()
        p.firstname = u"Boo"
        p.lastname = u"Foo"
        p.gender = "Male"
        p.date_of_birth = date(1975, 2, 8)
        store.add(p)
        return 'Done'

So no need to use store.commit, it will be handled by repoze.tm2.
If you add a second store both will either commit or rollback.

The code is hosted in a launchpad branch, use:
bzr branch lp:~olaf-conradi/storm/tmstorm

Comments are welcome ;)

Cheers,
 -Olaf

- --
storm mailing list
[EMAIL PROTECTED]
Modify settings or unsubscribe at:
https://lists.ubuntu.com/mailman/listinfo/storm

- --
===================================================================
Tres Seaver          +1 540-429-0999          [EMAIL PROTECTED]
Palladion Software   "Excellence by Design"    http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIjU0A+gerLs4ltQ4RAghHAKCVff+6G9mu+yABQhB3LFcJHLpx4wCgslyb
uU3dkzIQf9YQp6s0Y7dzvEw=
=aqm+
-----END PGP SIGNATURE-----
_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to