Commit eefd32c3 authored by fred's avatar fred
Browse files

use separate templates to render search results

parent 95b0d81e
......@@ -68,3 +68,27 @@ def append_tag_facet(url, facet):
def append_category_facet(url, facet):
facet = urllib2.quote(facet.encode('utf-8'), safe='')
return re.sub(r'&page=\d+', '', url + '&selected_facets=categories_exact:%s' % facet)
@register.tag
def search_result_template(parser, token):
try:
tag_name, result_str = token.split_contents()
except ValueError:
raise template.TemplateSyntaxError("%r tag requires exactly one argument" % token.contents.split()[0])
return FormatSearchResultNode(result_str)
class FormatSearchResultNode(template.Node):
def __init__(self, result_str):
self.result_var = template.Variable(result_str)
def render(self, context):
result = self.result_var.resolve(context)
dir_mapping = {
'newsitem': 'news',
'emission': 'emissions',
'episode': 'episodes'
}
t = template.loader.get_template('%s/search_result.html' % dir_mapping.get(result.model_name))
return t.render(template.context.Context({'result': result}, autoescape=context.autoescape))
<a href="{% url 'emission-view' slug=result.object.slug %}">{{ result.object.title }}</a>
<a href="{% url 'episode-view' emission_slug=result.object.emission.slug slug=result.object.slug %}">
{{ result.object.emission.title }}
{{ result.object.title }}
</a>
<a href="{% url 'news-view' slug=result.object.slug %}">{{ result.object.title }}</a>
{% extends 'panikdb/base.html' %}
{% load paniktags %}
{% load highlight %}
{% block player-class %}small-player{% endblock %}
......@@ -66,19 +67,7 @@
{% for result in page.object_list %}
<li>
{% if result.model_name == "episode" %}
<a href="{% url 'episode-view' emission_slug=result.object.emission.slug slug=result.object.slug %}">
{{ result.object.emission.title }}
{{ result.object.title }}
</a>
{% elif result.model_name == "emission" %}
<a href="{% url 'emission-view' slug=result.object.slug %}">
{{ result.object.title }}
</a>
{% else %}
{{ result.object.title }}
{% endif %}
{% search_result_template result %}
</li>
{% endfor %}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment