Upgrading to 1.0-dev

1 view
Skip to first unread message

Mike Orr

unread,
Jan 29, 2010, 4:11:08 PM1/29/10
to pylons-...@googlegroups.com
I upgraded an application from Pylons 0.9.7 to dev (which is almost
1.0) yesterday, and I'm happy to report that it went pretty smoothly
and only took an hour or two. I used "paster create -t pylons
AppName" and the option to make *.bak's of changed files. Then I
looked through the differences to see what to keep from the old
version and what to add from the new.

The biggest change is in the config initialization. The magic
``pylons.config`` is set as late as possible. Instead, a regular
config object is passed around. (This is to make it friendlier to
nested apps.)

# environment.py
config = PylonsConfig()
config.init_app(global_conf, app_conf, package="myapp", paths=paths)
...
return config

Several middleware items now take a 'config' argument:

# middleware.py
config = load_environment(global_conf, app_conf)
app = PylonsApp(config=config)
app = SessionMiddleware(app, config)
...
app.config = config
return app

So I made these minor changes to the syntax. I removed the 'template'
argument to init_app and the CacheMiddleware, which are no longer
used. I added the 'static_files' argument to middleware.py (which
tells whether something external is serving the static files).

The next biggest change was replacing ``redirect_to(...)`` with
``redirect(url(...))``. ('redirect' is in pylons.controllers.util.
'url' is ``pylons.url``.) I went ahead and replaced all my
``h.url_for()``'s with ``ur()`` while I was at it.

I also discovered some uses of 'g' in my templates which no longer
worked, so I replaced those with 'app_globals'.

That was it, and I had a smiling, running application.

--
Mike Orr <slugg...@gmail.com>

mickgardner

unread,
Jan 29, 2010, 6:38:28 PM1/29/10
to pylons-discuss
Is there anything documented on how to use the 'g'? I'm curious...

> Mike Orr <sluggos...@gmail.com>

Mike Orr

unread,
Jan 29, 2010, 8:51:58 PM1/29/10
to pylons-...@googlegroups.com
On Fri, Jan 29, 2010 at 3:38 PM, mickgardner <mickg...@gmail.com> wrote:
> Is there anything documented on how to use the 'g'? I'm curious...

http://pylonsbook.com/en/1.1/exploring-pylons.html#app-globals-object

There should be a table of the special globals somewhere, but I can't
find it offhand.

'app_globals' (formerly known as 'g') is shared between threads and
requests but is unique to the application instance. This matters if
there are multiple Pylons applications running in the same process
(i.e., multiple applications under different URLs, as in /blog1 and
/blog2.) Pylons uses 'app_globals' for Mako's TemplateLookup. Some
people use it for database connections or external resources, or for a
threadlocal object, a cache of files that have been read, etc. You
can also put flags in it, especially if they're liable to change
during runtime. (Generally you don't expect 'config' variables to
change.)

This should all be put into the documentation.

--
Mike Orr <slugg...@gmail.com>

Reply all
Reply to author
Forward
0 new messages