I'm not an expert in Pyramid, if I'm wrong I hope someone in the list
corrects me, so take my advice as an opinion from someone who uses
Pyramid sporadically.
I see Pyramid as just an application (a WSGI app) that just takes
requests and returns responses. The rest of Pyramid functionality is
to configure the application in the way it processes the requests and
returns the responses. Well, you have also events that are sent when
the Pyramid application is created but the focus is on
request-response machinery. See:
http://docs.pylonsproject.org/projects/pyramid/1.0/narr/router.html
For things related to the database I use some maintenance I run some
cron jobs with scripts that connect directly to ZODB. Those scripts
connect directly to ZODB, they don't need any Pyramid code. Nothing
stops you from working with ZODB directly from plain Python, you only
have to be careful if you need multiple processes connecting at the
same time, you need to run ZODB with ZEO in that case. See:
http://www.zodb.org/zodbbook/installing.html#setting-up-a-connection
http://docs.repoze.org/zodbconn/
What other things you have mind where you think you it's awkward to
use a request?
--
Danny Navarro | http://dannynavarro.net
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to
> pylons-discus...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
>
I see Pyramid as just an application (a WSGI app) that just takes
requests and returns responses. The rest of Pyramid functionality is
to configure the application in the way it processes the requests and
returns the responses.
What other things you have mind where you think you it's awkward to
use a request?
If you mean accessing the settings, the database configuration
settings, have a look at repoze.zodbconn, you can reuse the same
configuration for ZEO/ZODB that you have for Pyramid, just use the
script the same URL you use in your paster ini file to configure
ZEO/ZODB.
Testing is another story. You can use
``pyramid.threadlocal.get_current_request`` anywhere in your
application to get the current request. It's not recommended in a real
application but it's OK while testing.
http://docs.pylonsproject.org/projects/pyramid/1.0/api/threadlocal.html
``pyramid.testing`` offers you many helpers to ease the creation of
dummy requests and for the activation of a dummy registry so that the
request runs as if it were within pyramid.
http://docs.pylonsproject.org/projects/pyramid/1.0/narr/testing.html
http://docs.pylonsproject.org/projects/pyramid/1.0/api/testing.html
> Thanks, Danny.
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To post to this group, send email to pylons-...@googlegroups.com.
> To unsubscribe from this group, send email to
> pylons-discus...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
>
--
Danny Navarro | http://dannynavarro.net
There are about four patterns for accessing application state/request
state. One is to import a global object, as Pylons and CherryPy do.
Another is to call a global function, as Quixote does. Another is to
pass the request object through to every utility function, as Pyramid
does. Another is to save it in an instance variable in the view
handler, as Pyramid applications often do.
Part of the transition from Pylons to Pyramid was an intentional move
away from magic globals. They work but they depend on complex
threadlocals or StackedObjectProxies, which violate the principle of
encapsulation. They create complex interdependencies between the
modules in the application and the framework, which in turn makes it
more difficult to use the features outside of a request.
``pylons.app_globals`` was the most obvious example of this. People
would put a db connection or data structure into app_globals, and then
their model would depend on it, and then suddenly they'd discover in a
standalone script or a test, that app_globals wasn't initialized. So
then the had to research and write custom code to initialize it, and
that code would be different from how you normally access it. It's
better to just create objects explicitly and pass them through as
arguments, then you'll know that they'll work and how they work,
without depending on something behind the scenes in the framework,
something that might break.
--
Mike Orr <slugg...@gmail.com>