Browse Source

modified filter box macro to add multiple boxes on one page

php2python
Holger Frey 7 years ago
parent
commit
8c4adaad1f
  1. 5
      development.ini
  2. 14
      ordr2/templates/macros.jinja2
  3. 4
      ordr2/templates/tests.py

5
development.ini

@ -33,6 +33,11 @@ session.secret = 'Change Me 2'
session.auto_csrf = true session.auto_csrf = true
static_views.cache_max_age = 0 static_views.cache_max_age = 0
# custom jinja filters and tests
jinja2.filters =
are_extras_active = ordr2.templates.tests:are_extras_active
### ###
# wsgi server configuration # wsgi server configuration
### ###

14
ordr2/templates/macros.jinja2

@ -16,16 +16,20 @@
{%- endmacro %} {%- endmacro %}
{% macro filter_box(title, query_key, items) -%} {% macro filter_box(title, query_key, items, extras=None) -%}
{% if not extras %}
{% set extras = dict() %}
{% endif %}
{% set extras_active = context|are_extras_active(extras) %}
<div class="well sidebar-nav"> <div class="well sidebar-nav">
<ul class="nav nav-list"> <ul class="nav nav-list">
<li class="nav-header">{{ title }}</li> <li class="nav-header">{{ title }}</li>
<li {% if not context.filters.get(query_key) %}class="active"{% endif %}> <li {% if not context.filters.get(query_key) and extras_active %}class="active"{% endif %}>
<a href="{{ context.url( (query_key, None), (context.query_key_current_page, 1) ) }}">All</a> <a href="{{ context.url( (query_key, None), (context.query_key_current_page, 1), *extras.items() ) }}">All</a>
</li> </li>
{% for filter, display in items %} {% for filter, display in items %}
<li {% if context.filters.get(query_key) == filter %}class="active"{% endif %}> <li {% if context.filters.get(query_key) == filter and extras_active %}class="active"{% endif %}>
<a href="{{ context.url( (query_key, filter), (context.query_key_current_page, 1) ) }}">{{ display }}</a> <a href="{{ context.url( (query_key, filter), (context.query_key_current_page, 1), *extras.items() ) }}">{{ display }}</a>
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>

4
ordr2/templates/tests.py

@ -0,0 +1,4 @@
def are_extras_active(context, extras):
if extras is None:
return True
return all(context.filters.get(k) == v for k, v in extras.items())