Opened 18 years ago
Closed 17 years ago
#130 closed enhancement (fixed)
`callback` was not beying fetched by Genshi's Buffet pugin interface
Reported by: | palgarvio | Owned by: | palgarvio |
---|---|---|---|
Priority: | major | Milestone: | 0.4.3 |
Component: | Template engine plugin | Version: | 0.4.2 |
Keywords: | Cc: |
Description
Here a fix for that problem:
-
genshi/template/plugin.py
48 48 49 49 self.default_encoding = options.get('genshi.default_encoding', 'utf-8') 50 50 auto_reload = options.get('genshi.auto_reload', '1') 51 callback = options.get('genshi.callback', None) 51 52 if isinstance(auto_reload, basestring): 52 53 auto_reload = auto_reload.lower() in ('1', 'on', 'yes', 'true') 53 54 search_path = filter(None, options.get('genshi.search_path', '').split(':')) … … 67 68 auto_reload=auto_reload, 68 69 max_cache_size=max_cache_size, 69 70 default_class=self.template_class, 70 variable_lookup=lookup_errors) 71 variable_lookup=lookup_errors, 72 callback=callback) 71 73 72 74 def load_template(self, templatename, template_string=None): 73 75 """Find a template specified in python 'dot' notation, or load one from
Attachments (1)
Change History (9)
comment:1 Changed 17 years ago by cmlenz
- Priority changed from blocker to major
- Type changed from defect to enhancement
comment:2 follow-up: ↓ 3 Changed 17 years ago by palgarvio
- Owner changed from cmlenz to palgarvio
- Status changed from new to assigned
First of all why not include that callback option in AbstractTemplateEnginePluginsince you already have default_encoding, auto_reload, max_cache_size and search_path there, which are also options of TemplateLoader?
Seccond, next release of Pylons will accept specifying the templating engine when creating a new project which will make the necessary changes/additions and still keep it pretty simple.
The path you're specifying might be possible(I haven't tested it) but will complicate stuff a lot more.
Currently to use genshi as templating engine all one has to do is:
config.init_app(global_conf, app_conf, package='<app_name>', template_engine="genshi")
With the callback option we use the above and on another file:
def template_loaded(template): template.filters.insert(0, Translator(ugettext)) (.....) tmpl_options['genshi.callback'] = template_loaded
Or in just a single file:
def template_loaded(template): template.filters.insert(0, Translator(ugettext)) (.....) config.init_app(global_conf, app_conf, package='audioserv') config.template_engines = [] config.add_template_engine('genshi', 'audioserv.templates', {'genshi.callback': template_loaded})
Still want me to investigate your option?
comment:3 in reply to: ↑ 2 Changed 17 years ago by anonymous
Replying to palgarvio:
First of all why not include that callback option in AbstractTemplateEnginePluginsince you already have default_encoding, auto_reload, max_cache_size and search_path there, which are also options of TemplateLoader?
As I said, those options are expected to be strings, usually, because they are often read from configuration files. I'm not sure about adding an option that cannot be easily represented as a string, in this case a function that needs context to be useful.
Still want me to investigate your option?
Yeah. If it's possible, I can't imagine it'd be that much more complex.
comment:4 Changed 17 years ago by palgarvio
- Resolution set to worksforme
- Status changed from assigned to closed
Ok here's the solution for Pylons, aka, monkey patching:
config.init_app(global_conf, app_conf, package='audioserv', template_engine="genshi") # Monkey patch Genshi's TemplateLoader so we can get i18n working from genshi.template.loader import TemplateLoader TemplateLoader.callback = template_loaded
comment:5 Changed 17 years ago by palgarvio
- Resolution worksforme deleted
- Status changed from closed to reopened
Re-Opening as per cmlenz request.
comment:6 Changed 17 years ago by palgarvio
Also consider this one an ugly approach, ie, I instantiate it myself?
from pylons.templating import available_engines genshi = available_engines['genshi']() genshi.loader.callback = template_loaded
Pylons seems to pass only the method, which is probably called elsewhere. Look here.
comment:7 Changed 17 years ago by palgarvio
The above Monkey Patch approaches do not solve the problem, sometimes the Translator filter does not get added to the template filters. Seems accepting this patch might be the only way.
comment:8 Changed 17 years ago by cmlenz
- Milestone changed from 0.5 to 0.4.3
- Resolution set to fixed
- Status changed from reopened to closed
This is a bit weird, I'd normally expect every config option to be represented (or at least representable) as a string in a configuration file.
Is there no other way to set this up via Pylons? Can't you access the plugin object, and through that the associated template loader, and set up the callback that way?