My OSQA custom module uses a custom tag modelled after OSQA's own question_list_item tag. My tag, like question_list_item, loads a template. This works OK (by adding the import of my tag's .py file to the startup.py of my module), but it breaks when my tag's template tries to load a custom filter library my module uses.
If I move the custom filter and custom tag into the /templatetags folder of the overall OSQA app, everything works fine.
Any idea how to enable templates loaded by my custom tag to be able to load custom tags and filters?
Here's the implementation of my custom tag:
from django import template
from django.utils.translation import ugettext as _
from django.utils.safestring import mark_safe
from forum.models import Tag, MarkedTag
from forum.templatetags import argument_parser
from forum import settings
register = template.Library()
class SplunkAppItemNode(template.Node):
# this template load fails when trying to load my custom filters
template = template.loader.get_template('modules/splunk/splunk_app_item.html')
def __init__(self, question, options):
self.question = template.Variable(question)
self.options = options
def render(self, context):
return self.template.render(template.Context({
'question': self.question.resolve(context),
'favorite_count': self.options.get('favorite_count', 'no') == 'yes',
'signature_type': self.options.get('signature_type', 'lite'),
}))
@register.tag
def splunk_app_list_item(parser, token):
tokens = token.split_contents()[1:]
return SplunkAppItemNode(tokens[0], argument_parser(tokens[1:]))
Here's a subset of my template to illustrate the failing load:
{% load i18n humanize extra_filters extra_tags user_tags%}
{% load splunk_filters %}
<!-- the line above fails -->
<div class="short-summary">
<div class="counts">{% if favorite_count %}
...
asked
26 Dec '10, 02:57
Justin Grant
1.1k●16●35●32
accept rate:
12%