On Mon, Jan 19, 2009 at 4:52 AM, Wolverine <[email protected]> wrote:
>
> Hello.
> I've quite standard Pylons project that I'm working on for last few
> months. Recently I've cleaned up the code and created
> project.lib.helperslib subdir where I have created multiple python
> modules with corresponding functions e.g. date.py, buttons.py, links.py,
> etc. When functions were under project.lib.helpers everything worked
> fine. However when I moved those functions to different modules under
> helperslib subdir I cannot use pylons variables anymore. For example.
> When I'm importing config like this:
>

> TypeError: No object (name: translator) has been registered for this
> thread

It doesn't matter where the helpers are defined.  What matters is the
environment when they're called.  The Pylons special globals (c,
translator, etc) are valid only when a request is active.  If you want
to use them in other contexts, you'd have to put fake objects onto
them.  The testing thread today had an example.

> Also. When I'm trying to use config.get('value') I'm getting null
> values. It worked fine with Pylons 0.9.6.1, but after updating to Pylons
> 0.9.7rc-4 it's not working anymore.

What does "working fine" mean.  'config.get"'nonexistent_variable")'
should return None.  Like the other special globals, pylons.config is
a StackedObjectProxy which has a value pushed onto it at the beginning
of each request, and popped at the end.  However, unlike the others,
the configuration is also pushed at the beginning of the application
so it's available outside a request.  However, this happens at a
certain point, after load_environment is finished I think.

> When I'm importing it like this:
>
> from project.config.environment import load_environment
>
> I'm getting this error:
>
>  File
> "/home/wolverine/development/project/project/lib/helperslib/date.py",
> line 6, in <module>
>    from project.config.environment import load_environment
> ImportError: cannot import name load_environment

Import errors can happen for a lot of reasons.  Can you import
anything from the project?

However, a helper module should not be calling load_environment.
Let's start from the beginning.  Where are you calling this date
function?  Does the function have to use the Pylons globals directly,
or could you pass the needed values as arguments?  Most helpers do not
use the globals directly, precisely because that limits where the
helpers can be used.

-- 
Mike Orr <[email protected]>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" 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/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to