Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion adding filters to jinja : templatetools
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Remi Jolin  
View profile  
 More options Sep 29 2012, 9:53 am
From: Remi Jolin <remi.jo...@sysgroup.fr>
Date: Sat, 29 Sep 2012 15:53:11 +0200
Local: Sat, Sep 29 2012 9:53 am
Subject: Re: [TurboGears] adding filters to jinja : templatetools
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<remi.jo...@sysgroup.fr>  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 turbogears@googlegroups.com.
>> To unsubscribe from this group, send email to
>> turbogears+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/turbogears?hl=en.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.