mirror of https://github.com/interlegis/sigi.git
Marcio Mazza
10 years ago
5 changed files with 60 additions and 1 deletions
@ -0,0 +1,34 @@ |
|||
from django.contrib import admin |
|||
from django.contrib.admin.views.main import ChangeList |
|||
|
|||
|
|||
class ClearAllFilter(object): |
|||
title = None |
|||
template = 'clear_all_filter.html' |
|||
|
|||
def __init__(self, disabled): |
|||
self.disabled = disabled |
|||
|
|||
def choices(self, cl): |
|||
return [self.disabled] |
|||
|
|||
def queryset(self, request, queryset): |
|||
return queryset |
|||
|
|||
|
|||
class BaseChangeList(ChangeList): |
|||
|
|||
def get_filters(self, request): |
|||
(filter_specs, has_filters, lookup_params, |
|||
use_distinct) = super(BaseChangeList, self).get_filters(request) |
|||
if filter_specs: |
|||
clear_all_disabled = not self.get_filters_params() |
|||
filter_specs = [ClearAllFilter(clear_all_disabled)] + filter_specs |
|||
|
|||
return (filter_specs, has_filters, lookup_params, use_distinct) |
|||
|
|||
|
|||
class BaseModelAdmin(admin.ModelAdmin): |
|||
|
|||
def get_changelist(self, request, **kwargs): |
|||
return BaseChangeList |
@ -0,0 +1,15 @@ |
|||
# -*- coding: utf-8 -*- |
|||
|
|||
|
|||
def test_clear_all_filters_is_disabled_if_no_filter_was_used(admin_client): |
|||
response = admin_client.get('/parlamentares/parlamentar', follow=True) |
|||
assert response.status_code == 200 |
|||
assert '<li class="clear-all-filter disabled"><a href="?">Clear All Filters</a></li>' in response.content |
|||
|
|||
|
|||
def test_clear_all_filters_is_enabled_if_some_filter_was_used(admin_client): |
|||
# now we filter by capital letter |
|||
response = admin_client.get('/parlamentares/parlamentar/?nome_completo=B', follow=True) |
|||
assert response.status_code == 200 |
|||
# and there is no "disabled" css class |
|||
assert '<li class="clear-all-filter"><a href="?">Clear All Filters</a></li>' in response.content |
@ -0,0 +1,5 @@ |
|||
{% load i18n %} |
|||
|
|||
{% with choices|first as disabled %} |
|||
<li class="clear-all-filter{% if disabled %} disabled{% endif %}"><a href="?">{% trans 'Clear All Filters' %}</a></li> |
|||
{% endwith %} |
Loading…
Reference in new issue