Skip to content

Commit 4dc34e3

Browse files
committed
Add support for admin show_facets option. #396
1 parent 714f246 commit 4dc34e3

File tree

5 files changed

+103
-37
lines changed

5 files changed

+103
-37
lines changed

admin_interface/static/admin_interface/css/admin-interface.css

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,19 @@
413413
border-radius: var(--admin-interface-module-border-radius);
414414
}
415415

416+
.admin-interface .module.filtered .changelist-filter-clear-container {
417+
margin: 12px 0;
418+
}
419+
416420
.admin-interface .module.filtered #changelist-filter h3#changelist-filter-clear {
417-
margin-bottom: 0;
421+
margin-top: 5px;
422+
margin-bottom: 10px;
418423
}
419424

420425
.admin-interface .module.filtered #changelist-filter .changelist-filter-clear a {
421-
font-size: 13px;
426+
font-size: 12px;
422427
margin: .3em 0;
423-
padding: 0 15px;
428+
padding: 0 15px 0 32px;
424429
}
425430

426431
.admin-interface .module.filtered #changelist-filter .changelist-filter-clear a:focus,
@@ -441,7 +446,8 @@
441446
text-decoration: none;
442447
}
443448

444-
.admin-interface.list-filter-highlight .module.filtered #changelist-filter h3.active {
449+
.admin-interface.list-filter-highlight .module.filtered #changelist-filter h3.active,
450+
.admin-interface.list-filter-highlight .module.filtered #changelist-filter summary.active {
445451
font-weight: bold;
446452
}
447453

@@ -473,6 +479,19 @@
473479
color: var(--admin-interface-generic-link-hover-color);
474480
}
475481

482+
.admin-interface .module.filtered #changelist-filter a,
483+
.admin-interface .module.filtered #changelist-filter a:link,
484+
.admin-interface .module.filtered #changelist-filter a:visited {
485+
color: var(--admin-interface-generic-link-color);
486+
text-decoration: none;
487+
}
488+
489+
.admin-interface .module.filtered #changelist-filter a:hover,
490+
.admin-interface .module.filtered #changelist-filter a:active {
491+
color: var(--admin-interface-generic-link-hover-color);
492+
text-decoration: none;
493+
}
494+
476495
/* begin fix issue #11 - Inline border bottom should not be rounded */
477496
.admin-interface .module h2,
478497
.admin-interface.dashboard .module caption,

admin_interface/static/admin_interface/css/list-filter-dropdown.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ list-filter-dropdown
88
}
99

1010
.admin-interface #changelist-filter h2 + .list-filter-dropdown,
11+
.admin-interface #changelist-filter #changelist-filter-extra-actions + .list-filter-dropdown,
1112
.admin-interface #changelist-filter .list-filter-dropdown + .list-filter-dropdown {
1213
margin-top: 5px;
1314
}

admin_interface/static/admin_interface/css/list-filter.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@
1313
}
1414
}
1515

16+
.admin-interface .module.filtered #changelist-filter h2#changelist-filter-header {
17+
margin-bottom: 0;
18+
}
19+
20+
.admin-interface .module.filtered #changelist-filter h2#changelist-filter-header + details {
21+
margin-top: 12px;
22+
}
23+
1624
.admin-interface .module.filtered #changelist-filter h2 {
1725
font-size: 11px;
1826
padding: 10px 15px;
@@ -26,3 +34,10 @@
2634
margin-top: 12px;
2735
margin-bottom: 12px;
2836
}
37+
38+
/* fix summary shift when expanding/collapsing list filter */
39+
.admin-interface .module.filtered #changelist-filter details > summary::before {
40+
display: inline-block;
41+
width: 14px;
42+
text-align: center;
43+
}
Lines changed: 53 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,60 @@
11
{% extends "admin/change_list.html" %}
22
{% load i18n admin_list admin_interface_tags %}
3-
{# copied from django 4.0.7 #}
3+
{# copied from django 5.1.2 #}
44

5-
{% block filters %}
6-
{% if cl.has_filters %}
7-
<div id="changelist-filter">
8-
<h2>{% translate 'Filter' %}</h2>
5+
{% block filters %}
6+
{% if cl.has_filters %}
7+
<nav id="changelist-filter" aria-labelledby="changelist-filter-header">
8+
<h2 id="changelist-filter-header">{% translate 'Filter' %}</h2>
9+
10+
{% if cl.is_facets_optional or cl.has_active_filters %}
11+
<div id="changelist-filter-extra-actions">
12+
{% if cl.is_facets_optional %}
13+
<h3>
14+
{% if cl.add_facets %}
15+
<a href="{{ cl.remove_facet_link }}" class="hidelink">{% translate "Hide counts" %}</a>
16+
{% else %}
17+
<a href="{{ cl.add_facet_link }}" class="viewlink">{% translate "Show counts" %}</a>
18+
{% endif %}
19+
</h3>
20+
{% endif %}
21+
22+
<!-- {# begin "list_filter_removal_links" #} -->
923
{% get_admin_interface_active_date_hierarchy cl as active_date_hierarchy %}
1024
{% get_admin_interface_setting "list_filter_removal_links" as list_filter_removal_links %}
11-
{% if cl.has_active_filters %}
12-
{% if list_filter_removal_links %}
13-
{% if active_date_hierarchy %}{% admin_interface_date_hierarchy_removal_link cl active_date_hierarchy %}{% endif %}
14-
{% for spec in cl.filter_specs %}{% admin_interface_filter_removal_link cl spec %}{% endfor %}
15-
<h3 id="changelist-filter-clear">
16-
<a href="{{ cl.clear_all_filters_qs }}">{% translate "Clear all filters" %} &#10006;</a>
17-
</h3>
18-
{% else %}
19-
<h3 id="changelist-filter-clear">
20-
{# Translators: don't translate this, the django catalog already contains it #}
21-
<a href="{{ cl.clear_all_filters_qs }}">&#10006; {% translate "Clear all filters" %}</a>
22-
</h3>
23-
{% endif %}
24-
{% elif active_date_hierarchy and list_filter_removal_links %}
25-
{% admin_interface_date_hierarchy_removal_link cl active_date_hierarchy %}
26-
<h3 id="changelist-filter-clear">
27-
<a href="{{ cl.clear_all_filters_qs }}">{% translate "Clear all filters" %} &#10006;</a>
28-
</h3>
25+
{% if list_filter_removal_links %}
26+
{% if cl.has_active_filters or active_date_hierarchy %}
27+
<div class="changelist-filter-clear-container">
28+
<h3 id="changelist-filter-clear">
29+
<a href="{{ cl.clear_all_filters_qs }}">&#10006; {% translate "Clear all filters" %}</a>
30+
</h3>
31+
{% if active_date_hierarchy %}
32+
{% admin_interface_date_hierarchy_removal_link cl active_date_hierarchy %}
33+
{% endif %}
34+
{% if cl.has_active_filters %}
35+
{% for spec in cl.filter_specs %}
36+
{% admin_interface_filter_removal_link cl spec %}
37+
{% endfor %}
38+
{% endif %}
39+
</div>
40+
{% endif %}
41+
{% else %}
42+
<!-- {# use default django template code #} -->
43+
{% if cl.has_active_filters %}
44+
<h3>
45+
<a href="{{ cl.clear_all_filters_qs }}">&#10006; {% translate "Clear all filters" %}</a>
46+
</h3>
47+
{% endif %}
48+
<!-- {# end use default django template code #} -->
2949
{% endif %}
30-
{% for spec in cl.filter_specs %}{% admin_list_filter cl spec %}{% endfor %}
31-
</div>
50+
<!-- {# end "list_filter_removal_links" #} -->
51+
52+
</div>
3253
{% endif %}
33-
{% endblock %}
54+
55+
{% for spec in cl.filter_specs %}
56+
{% admin_list_filter cl spec %}
57+
{% endfor %}
58+
</nav>
59+
{% endif %}
60+
{% endblock %}

admin_interface/templates/admin/filter.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010

1111
{# Use a changed default list filter template -> https://github.com/django/django/blob/master/django/contrib/admin/templates/admin/filter.html #}
1212

13-
<h3 {% if spec.lookup_val or spec.value %}class="active"{% endif %}>{% blocktrans with filter_title=title %} By {{ filter_title }} {% endblocktrans %}</h3>
14-
<ul {% if spec.lookup_val or spec.value %}class="active"{% endif %}>
15-
{% for choice in choices %}
16-
<li{% if choice.selected %} class="selected"{% endif %}>
17-
<a href="{{ choice.query_string|iriencode }}">{{ choice.display }}</a></li>
18-
{% endfor %}
19-
</ul>
13+
<details data-filter-title="{{ title }}" open>
14+
<summary {% if spec.lookup_val or spec.value %}class="active"{% endif %}>
15+
{% blocktranslate with filter_title=title %} By {{ filter_title }} {% endblocktranslate %}
16+
</summary>
17+
<ul {% if spec.lookup_val or spec.value %}class="active"{% endif %}>
18+
{% for choice in choices %}
19+
<li{% if choice.selected %} class="selected"{% endif %}>
20+
<a href="{{ choice.query_string|iriencode }}">{{ choice.display }}</a></li>
21+
{% endfor %}
22+
</ul>
23+
</details>
2024

2125
{% endif %}

0 commit comments

Comments
 (0)