OK Diez, now I understand, but I don't think I need to refresh these
variables on every request nor every transaction either.  I'll try to
explain what I have done to solve this in my particular noob point of
view.

1.  I Created a folder at the same level of controllers named
'listeners' (no other name came up to my mind)
2. Then created a module named 'context.py'
3. Inside created a class named 'ContextInit' with the following code:

class ContextInit():
    initialized = False

    def setupContext(self):
        appSetting = model.DBSession.query(model.Settings)\
            .filter(model.Settings.name == u'product_images_path').one
()
        app_globals.Globals.PRODUCT_IMAGES_PATH = appSetting.value
        # insert more globals initialization here

    def __init__(self):
        if not self.initialized:
            log.debug(u'Initializing context')
            self.setupContext()
            self.initialized = True

context_init = ContextInit()

4. Then I add just before the 'RootController' class declaration the
following:
#{ Initialize context
from myapp.listeners.context import context_init

context = context_init
#}

5. Whenever I need to refresh globals I just do a 'context.setupContext
()'

It works, don't know if it's the best way to do it or even a best
practice, but I needed to test it.

Juan Pablo

On Oct 6, 5:11 pm, "Diez B. Roggisch" <[email protected]> wrote:
> Juparave schrieb:
>
> > I didn't understand your approach completely, if I have globals
> > variables/callables like ${g} and ${h}, why would I need another
> > wrapper (variable_provider)?  With Helpers and Globals I'm covering
> > all my bases right now.  Maybe I misunderstand your point.
>
> No, I didn't explain it enough.
>
> The point is that ORMs like SqlAlchemy and SQLObject (and actually
> Java-ORMs often as well) only allow objects to exist inside an ongoing
> transaction (SA encapsulates this within a session). And these objects
> can't be used in another transaction/session.
>
> So you need to "refresh" your objects on each request which spans a
> transaction.
>
> And this is why variable_providers is the place for it.
>
> I'm not aware of a hook that is inoked *after* the DB is connected, but
> only once - you might do that in <package>.config.middlware, when you
> explicitly open and close a transaction.
>
> Diez
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to