Skip to content

Commit

Permalink
Merge branch 'release/1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyue92tree committed Jul 1, 2019
2 parents 2f71f1d + 4b774e0 commit 42a7d37
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 49 deletions.
2 changes: 1 addition & 1 deletion adminlteui/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version = '1.1.0'
version = '1.1.1'
# default_app_config = 'adminlteui.apps.AdminlteUIConfig'
16 changes: 8 additions & 8 deletions adminlteui/templates/admin/change_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,10 @@ <h4 class="box-title">
<script src="{% static "admin/plugins/datatables/dataTables.bootstrap.min.js" %}"></script>

<script>
var selectors = document.querySelector('#changelist-search').querySelectorAll('select');
for (var i in selectors) {
selectors[i].onchange = function() {
// var selectors = document.querySelector('#changelist-search').querySelectorAll('select');

$.fn.search_filters = function () {
$(this).change(function () {
var $field = $(this);
var $option = $field.find('option:selected');
var select_name = $option.data('name');
Expand All @@ -129,12 +130,11 @@ <h4 class="box-title">
// additional = additional.split('=');
// $hidden.attr('name', additional[0]).val(additional[1])
// }
});
$(this).trigger('change');
};

// remove the hidden input of select_name
var input = document.querySelector('#search_group').querySelector('input[name="' + $field.data('name') + '"]');
input.parentNode.removeChild(input)
}
}
$('.search-filter').search_filters();

</script>

Expand Down
13 changes: 8 additions & 5 deletions adminlteui/templates/admin/filter.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{% load i18n %}


<div class="form-group">
<select class="form-control select2 select2-hidden-accessible" style="width: 100%;" tabindex="-1" aria-hidden="true" data-name="{{spec.lookup_kwarg}}">
<select class="form-control select2 select2-hidden-accessible search-filter" style="width: 100%;" tabindex="-1" aria-hidden="true" data-name="{{ field_name }}">
<option value="">{{ title }}</option>
<option value="">------</option>
{% for choice in new_choices %}
<option data-name="{{ choice.name }}" value="{{ choice.value }}" {% if choice.selected %} selected {% endif %}>{{ choice.display }}</option>
<option value="">---------</option>
{% for choice in choices %}
{% if choice.name %}
<option data-name="{{ choice.name }}" value="{{ choice.value }}" {% if choice.selected %} selected {% endif %}>
{{ choice.display }}
</option>
{% endif %}
{% endfor %}
</select>
</div>
3 changes: 2 additions & 1 deletion adminlteui/templates/admin/search_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
{% if show_result_count %}
<span class="small quiet">{% blocktrans count counter=cl.result_count %}{{ counter }} result{% plural %}{{ counter }} results{% endblocktrans %} (<a href="?{% if cl.is_popup %}_popup=1{% endif %}">{% if cl.show_full_result_count %}{% blocktrans with full_result_count=cl.full_result_count %}{{ full_result_count }} total{% endblocktrans %}{% else %}{% trans "Show all" %}{% endif %}</a>)</span>
{% endif %}
{% for pair in cl.params.items %}
{% admin_extra_filters cl as extra_filters %}
{% for pair in extra_filters.items %}
{% if pair.0 != search_var %}<input type="hidden" name="{{ pair.0 }}" value="{{ pair.1 }}">{% endif %}
{% endfor %}
</div>
Expand Down
85 changes: 51 additions & 34 deletions adminlteui/templatetags/adminlte_list.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import itertools
from django.contrib.admin.views.main import (
ALL_VAR, ORDER_VAR, PAGE_VAR, SEARCH_VAR,
)
Expand Down Expand Up @@ -35,48 +36,64 @@ def adminlte_paginator_number(cl, i):
)


def get_filter_id(spec):
try:
return getattr(spec, 'field_path')
except AttributeError:
try:
return getattr(spec, 'parameter_name')
except AttributeError:
pass
return spec.title


@register.simple_tag
def admin_extra_filters(cl):
""" Return the dict of used filters which is not included
in list_filters form """
used_parameters = list(itertools.chain(*(s.used_parameters.keys()
for s in cl.filter_specs)))
return dict(
(k, v) for k, v in cl.params.items() if k not in used_parameters)


@register.simple_tag
def adminlte_admin_list_filter(cl, spec):
tpl = get_template(spec.template)
new_choice = []
choices = list(spec.choices(cl))
field_key = get_filter_id(spec)
matched_key = field_key
for choice in choices:
query_string = choice['query_string'][1:]
query_parts = urllib.parse.parse_qs(query_string)

# print(spec.lookup_kwarg)
# print(list(spec.choices(cl)))
value = ''
matches = {}
for key in query_parts.keys():
if key == field_key:
value = query_parts[key][0]
matched_key = key
elif key.startswith(
field_key + '__') or '__' + field_key + '__' in key:
value = query_parts[key][0]
matched_key = key

for choice in list(spec.choices(cl)):
qs = (urllib.parse.parse_qs(choice.get('query_string')))
# print(qs)
for k, v in qs.items():
if k.strip('?') in cl.params.keys() and k.strip(
'?') != spec.lookup_kwarg:
continue
new_choice.append({'name': k.strip('?'), 'value': v[0],
'display': choice.get('display'),
'selected': choice.get('selected')})
if value:
matches[matched_key] = value

# print(new_choice)
# Iterate matches, use first as actual values, additional for hidden
i = 0
for key, value in matches.items():
if i == 0:
choice['name'] = key
choice['value'] = value
# else:
# choice['additional'] = '%s=%s' % (key, value)
i += 1

return tpl.render({
'field_name': field_key,
'title': spec.title,
'choices': list(spec.choices(cl)),
'new_choices': new_choice,
'choices': choices,
'spec': spec,
})

# def adminlte_search_form(cl):
# """
# Display a search form for searching the list.
# """
# print(cl)
# return {
# 'cl': cl,
# 'show_result_count': cl.result_count != cl.full_result_count,
# 'search_var': SEARCH_VAR
# }
#
#
# @register.tag(name='adminlte_search_form')
# def adminlte_search_form_tag(parser, token):
# return InclusionAdminNode(parser, token, func=adminlte_search_form,
# template_name='search_form.html',
# takes_context=False)

0 comments on commit 42a7d37

Please sign in to comment.