Commits

TakeruWolf committed e61c358

implemented the aimed rendering behaviour including default templates

Comments (0)

Files changed (3)

django_easyfilters/filterset.py

 from django import template
+from django.template.loader import get_template
 from django.utils.safestring import mark_safe
 from django.utils.html import escape
 from django.utils.text import capfirst
 
 class FilterSet(object):
 
-    template = u"""
-<div class="filterline"><span class="filterlabel">{{ filterlabel }}:</span>
-{% for choice in choices %}
-  {% if choice.link_type == 'add' %}
-    <span class="addfilter"><a href="{{ choice.url }}" title="Add filter">{{ choice.label }}&nbsp;({{ choice.count }})</a></span>&nbsp;&nbsp;
-  {% else %}
-    {% if choice.link_type == 'remove' %}
-    <span class="removefilter"><a href="{{ choice.url }}" title="Remove filter">{{ choice.label }}&nbsp;&laquo;&nbsp;</a></span>
-    {% else %}
-      <span class="displayfilter">{{ choice.label }}</span>
-    {% endif %}
-  {% endif %}
-{% endfor %}
-</div>
-"""
+    template_name = 'easyfilters/filters.html'
+    field_template_name = 'easyfilters/filter.html'
     title_fields = None
 
     def __init__(self, queryset, params):
         return self.get_template(filter_.field).render(template.Context(ctx))
 
     def get_template(self, field_name):
-        return template.Template(self.template)
+        return get_template(self.field_template_name)
 
     def render(self):
-        return mark_safe(u'\n'.join(self.render_filter(f) for f in self.filters))
+        self.rendered_fields = (self.render_filter(f) for f in self.filters)
+        return get_template(self.template_name).render(template.Context({'filter': self}))
 
     def get_fields(self):
         return self.fields

django_easyfilters/templates/easyfilters/filter.html

+<th class="filterlabel">{{ filterlabel }}:</th>
+<td class="filteritems">
+	{% for choice in choices %}
+		{% if choice.link_type == 'add' %}
+			<span class="addfilter">
+			<a href="{{ choice.url }}" title="Add filter">{{ choice.label }}</a>
+			({{ choice.count }})
+			</span>
+		{% else %}
+			{% if choice.link_type == 'remove' %}
+				<span class="removefilter"><a href="{{ choice.url }}" title="Remove filter">{{ choice.label }}&nbsp;&laquo;&nbsp;</a></span>
+			{% else %}
+				<span class="displayfilter">{{ choice.label }}</span>
+			{% endif %}
+		{% endif %}
+	{% endfor %}
+</td>

django_easyfilters/templates/easyfilters/filters.html

+{% if filter.rendered_fields %}
+	<table>
+		<col width="0"/>
+		<col width="*" />
+		{% for rendered_field in filter.rendered_fields %}
+			<tr class="filterline {% cycle 'row1' 'row2' %}">
+				{{ rendered_field }}
+			</tr>
+		{% endfor %}
+	</table>
+{% endif %}