Ah, right, I saw right now that it imports the module itself not using
from form.

Probably the most pythonic way to solve the issue is change the jinja
filters setup to care about __all__, in the mean time you can simply
write your jinja filters inside something like jinja_filters_impl.py
and then just do from jinja_filter_impl import whatyouwant into
.lib.templatetools.jinja_filters

On Sat, Sep 29, 2012 at 3:53 PM, Remi Jolin <[email protected]> wrote:
> No, I tried this...  It does nothing but adding one more filter '__all__' to
> the filters' list. The __dict__ of an imported module containes all the
> definitions, imported modules, etc.
>
> Le 29/09/2012 15:14, Alessandro Molina a écrit :
>
>> I'm not actually sure, but shouldn't defining __all__ inside your
>> jinja_filter.py solve the issue?
>>
>> On Sat, Sep 29, 2012 at 12:09 PM, Remi Jolin<[email protected]>
>> wrote:
>>>
>>> Hello,
>>>
>>> I want to add a custom filter to jinja2 and I found that there is a way
>>> to
>>> do that through adding a .lib.templatetools.jinja_filters.py module, so I
>>> tryed it...
>>> Every function defined in this module become a filter. But not only
>>> functions :-(, everything imported in this module is included in the
>>> filter's dict !
>>>
>>> I'm not sure this was the expected behavior.
>>>
>>> Could not it be a .lib.templatetools.py that would contain functions and
>>> a
>>> dict named jinja_filters that would contain the filters like in the
>>> config
>>> file ? jinja_filters = dict(filter_name=filter_fct, ...) ?
>>>
>>> The only change in tg.configuration.app_config.py
>>> change :
>>>          # Try to load custom filters module under
>>> app_package.lib.templatetools
>>>          try:
>>>              filter_package = self.package.__name__ +
>>> ".lib.templatetools"
>>>              autoload_lib = __import__(filter_package, {}, {},
>>> ['jinja_filters'])
>>>              autoload_filters = autoload_lib.jinja_filters.__dict__
>>>          except (ImportError, AttributeError):
>>>              autoload_filters = {}
>>>
>>> by :
>>>          # Try to load custom filters module under
>>> app_package.lib.templatetools
>>>          try:
>>>              filter_package = self.package.__name__ +
>>> ".lib.templatetools"
>>>              autoload_lib = __import__(filter_package, {}, {},
>>> ['jinja_filters'])
>>>              autoload_filters = autoload_lib.jinja_filters
>>> # suppress the .__dict__
>>>          except (ImportError, AttributeError):
>>>              autoload_filters = {}
>>>
>>> or
>>>
>>>          # Try to load custom filters module under
>>> app_package.lib.templatetools
>>>          try:
>>>              filter_package = self.package.__name__ +
>>> ".lib.templatetools"
>>>              autoload_lib = __import__(filter_package, {}, {},
>>> ['jinja_filters'])
>>>              try:
>>>                  autoload_filters = autoload_lib.jinja_filters.__dict__
>>>              except AttributeError:
>>>                  autoload_filters = autoload_lib.jinja_filters
>>>          except (ImportError, AttributeError):
>>>              autoload_filters = {}
>>>
>>> to support both...
>>>
>>> --
>>> 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.
>>>
>
> --
> 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.
>

-- 
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