I worked out a solution which seems to work OK. My approach isn't appropriate when creating a whole new skin, but if you simply want to override a few templates it will probably work fine.
First, I created a template_overrides directory underneath my module's root directory. Any template files put there will be used instead of files with the same name inside the OSQA skins folders.
Second, I added the code below to __init.py__ of my OSQA module, which will load templates from that new folder:
import os
from django.template import TemplateDoesNotExist
def template_overrides_loader(name, dirs=None):
file_name = os.path.join(os.path.dirname(__file__),'template_overrides', name)
if os.path.exists(file_name):
try:
f = open(file_name, 'r')
source = f.read()
f.close()
return (source, file_name)
except:
pass
raise TemplateDoesNotExist, name
template_overrides_loader.is_usable = True
Third, in settings_local.py for my OSQA site, I added the custom loader above as the first entry in the list of template loaders that Django uses. This overrides the folders set in settings.py.
# insert our override loader first
# TODO: optimize this, e.g. using the Django caching template loader
TEMPLATE_LOADERS = (
'forum_modules.splunk.template_overrides_loader',
'django.template.loaders.filesystem.load_template_source',
'django.template.loaders.app_directories.load_template_source',
'forum.modules.module_templates_loader',
'forum.skins.load_template_source',
# 'django.template.loaders.eggs.load_template_source',
)
answered
27 Dec '10, 13:58
Justin Grant
1.1k●16●35●32
accept rate:
12%