Skip to content

Commit bcc7d3f

Browse files
committed
Merge branch 'release/1.7.0'
2 parents 2b58b49 + f1c36d8 commit bcc7d3f

File tree

11 files changed

+166
-44
lines changed

11 files changed

+166
-44
lines changed

.github/workflows/main.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: main
2+
3+
on: push
4+
5+
jobs:
6+
build-n-publish:
7+
name: Build and publish Python 🐍 distributions 📦 to PyPI
8+
runs-on: ubuntu-18.04
9+
10+
steps:
11+
- uses: actions/checkout@master
12+
- name: Set up Python 3.9
13+
uses: actions/setup-python@v1
14+
with:
15+
python-version: 3.9
16+
- name: Install pypa/build
17+
run: >-
18+
python -m
19+
pip install
20+
build
21+
--user
22+
- name: Build a binary wheel and a source tarball
23+
run: >-
24+
python -m
25+
build
26+
--sdist
27+
--wheel
28+
--outdir dist/
29+
.
30+
- name: Publish a Python distribution to PyPI
31+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
32+
uses: pypa/gh-action-pypi-publish@v1.5.0
33+
with:
34+
user: __token__
35+
password: ${{ secrets.PYPI }}

.travis.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# django-adminlte-ui
88
[![PyPI Version](https://img.shields.io/pypi/v/django-adminlte-ui.svg)](https://pypi.python.org/pypi/django-adminlte-ui)
99
[![Download Status](https://img.shields.io/pypi/dm/django-adminlte-ui.svg)](https://pypi.python.org/pypi/django-adminlte-ui)
10-
[![Build Status](https://api.travis-ci.org/wuyue92tree/django-adminlte-ui.svg)](https://travis-ci.org/wuyue92tree/django-adminlte-ui)
10+
[![Build Status](https://github.com/wuyue92tree/django-adminlte-ui/workflows/main/badge.svg)](https://github.com/wuyue92tree/django-adminlte-ui/workflows/main/badge.svg)
1111
[![Documentation Status](https://readthedocs.org/projects/django-adminlte-ui/badge/?version=latest)](https://django-adminlte-ui.readthedocs.io/en/latest/?badge=latest)
1212
[![Gitter](https://badges.gitter.im/django-adminlte-ui/community.svg)](https://gitter.im/django-adminlte-ui/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
1313

adminlteui/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
version = '1.6.1'
1+
version = '1.7.0'
22
default_app_config = 'adminlteui.apps.AdminlteUIConfig'

adminlteui/admin.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,33 @@ def get_image_box():
4848
option_name='site_logo') else ''
4949

5050

51+
class ModelAdmin(admin.ModelAdmin):
52+
select2_list_filter = ()
53+
search_field_placeholder = ''
54+
55+
class Media:
56+
css = {
57+
"all": ("admin/components/select2/dist/css/select2.min.css",)
58+
}
59+
js = (
60+
"admin/components/select2/dist/js/select2.min.js",
61+
)
62+
63+
def changelist_view(self, request, extra_context=None):
64+
view = super().changelist_view(request, extra_context)
65+
cl = view.context_data.get('cl')
66+
cl.search_field_placeholder = self.search_field_placeholder
67+
filter_specs = cl.filter_specs
68+
69+
for index, filter_spec in enumerate(filter_specs):
70+
if filter_spec.field_path in self.select2_list_filter:
71+
# flag to use select2
72+
filter_spec.display_select2 = True
73+
cl.filter_specs[index] = filter_spec
74+
view.context_data['cl'] = cl
75+
return view
76+
77+
5178
class GeneralOptionForm(forms.Form):
5279
site_title = forms.CharField(label=_('Site Title'),
5380
widget=widgets.AdminTextInputWidget(),
Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
{% load i18n %}
22

33
<div class="form-group" style="margin-bottom: 5px;">
4-
<select class="form-control select2 select2-hidden-accessible search-filter" style="width: 100%;" tabindex="-1" aria-hidden="true" data-name="{{ field_name }}">
4+
<select id="id_filter_{{ field_name }}" class="form-control search-filter" style="width: 100%;" tabindex="-1" aria-hidden="true">
55
<option value="">{{ title }}</option>
66
<option value="">---------</option>
77
{% for choice in choices %}
8-
{% if choice.name %}
9-
<option data-name="{{ choice.name }}" value="{{ choice.value }}" {% if choice.selected %} selected {% endif %}>
10-
{{ choice.display }}
11-
</option>
12-
{% endif %}
8+
{% if choice.name %}
9+
<option data-name="{{ choice.name }}" value="{{ choice.value }}" {% if choice.selected %} selected {% endif %}>
10+
{{ choice.display }}
11+
</option>
12+
{% endif %}
1313
{% endfor %}
1414
</select>
15+
{% if spec.display_select2 %}
16+
<script>
17+
django.jQuery('#id_filter_{{ field_name }}').select2({
18+
width: django.jQuery('#id_filter_{{ field_name }}').width() + 26
19+
})
20+
django.jQuery('#id_filter_{{ field_name }}').on('select2:select', function (e) {
21+
if (e.params.data.id !=='') {
22+
django.jQuery('#id_filter_{{ field_name }}').attr('name', e.params.data.element.dataset.name)
23+
} else {
24+
django.jQuery('#id_filter_{{ field_name }}').removeAttr('name')
25+
}
26+
});
27+
</script>
28+
{% endif %}
1529
</div>

adminlteui/templates/admin/pagination.html

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,48 @@
2424
id="example2_paginate">
2525
<ul class="pagination">
2626
{% if pagination_required %}
27-
<li class="paginate_button previous disabled"
28-
id="example2_previous">
29-
<a href="#" aria-controls="example2" data-dt-idx="0"
30-
tabindex="0">{% trans 'Previous' %}</a></li>
31-
{% for i in page_range %}
32-
{% adminlte_paginator_number cl i %}
33-
{% endfor %}
34-
<li class="paginate_button next disabled" id="example2_next">
35-
<a href="#"
36-
aria-controls="example2"
37-
data-dt-idx="7"
38-
tabindex="0">{% trans 'Next' %}</a>
39-
</li>
27+
<li class="paginate_button previous disabled"
28+
id="example2_previous">
29+
<a href="#" aria-controls="example2" data-dt-idx="0"
30+
tabindex="0">{% trans 'Previous' %}</a></li>
31+
{% for i in page_range %}
32+
{% adminlte_paginator_number cl i %}
33+
{% endfor %}
34+
<li class="paginate_button next disabled" id="example2_next">
35+
<a href="#"
36+
aria-controls="example2"
37+
data-dt-idx="7"
38+
tabindex="0">{% trans 'Next' %}</a>
39+
</li>
40+
<script type="text/javascript">
41+
let pageRange = []
42+
{% for p in page_range %}
43+
pageRange.push('{{ p }}')
44+
{% endfor %}
45+
// console.log(pageRange)
46+
let currentPage = document.querySelector("#example2_paginate > ul > li.active > a").innerText
47+
let previous = document.querySelector("#example2_previous > a")
48+
let next = document.querySelector("#example2_next > a")
49+
let target_href = window.location.search.replace(/\?p=\d+/g, '').replace(/&p=\d+/g, '')
50+
// previous button
51+
if ((Number(pageRange[0]) + 1).toString() !== currentPage) {
52+
previous.parentElement.setAttribute('class', 'paginate_button previous')
53+
previous.setAttribute('href', target_href? target_href + `&p=${Number(currentPage) -2}`: target_href + `?p=${Number(currentPage) -2}`)
54+
} else {
55+
previous.parentElement.setAttribute('class', 'paginate_button previous disabled')
56+
previous.setAttribute('href', 'javascript:void(0);')
57+
}
58+
// next button
59+
if ((Number(pageRange[pageRange.length-1]) + 1).toString() !== currentPage) {
60+
next.parentElement.setAttribute('class', 'paginate_button next')
61+
next.setAttribute('href', target_href? target_href + `&p=${currentPage}`: target_href + `?p=${currentPage}`)
62+
} else {
63+
next.parentElement.setAttribute('class', 'paginate_button next disabled')
64+
next.setAttribute('href', 'javascript:void(0);')
65+
}
66+
</script>
4067
{% endif %}
4168
</ul>
4269
</div>
4370
</div>
44-
</div>
71+
</div>

adminlteui/templates/admin/search_form.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
{% if cl.search_fields %}
1313
<!-- DIV needed for valid HTML -->
1414
<div class="form-group" style="margin-bottom: 5px;">
15-
<input class="form-control" type="text" size="40" name="{{ search_var }}" value="{{ cl.query }}" id="searchbar" autofocus>
15+
<input class="form-control" type="text" size="40" placeholder="{{ cl.search_field_placeholder }}" name="{{ search_var }}" value="{{ cl.query }}" id="searchbar" autofocus>
1616
</div>
1717
{% endif %}
1818
{% if cl.has_filters or cl.search_fields %}

docs/about.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# ChangeLog
22

3+
## [v1.7.0](https://github.com/wuyue92tree/django-adminlte-ui/releases/tag/1.7.0)
4+
- make previous & next button effective on change_list.html
5+
- use select2 make admin filter searchable
6+
- add search_field_placeholder for search_fields
7+
- use `github actions` replace `travis`
8+
39
## [v1.6.1](https://github.com/wuyue92tree/django-adminlte-ui/releases/tag/1.6.1)
410
- fix app in ADMINLTE_SETTINGS but current_user has not perm
511
- fix model in ADMINLTE_SETTINGS but current_user has not perm

docs/guide.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,39 @@ before custom option, you should known what adminlte has used.
5050
- avatar_field
5151
- show_avatar
5252

53+
## ModelAdmin
54+
- make change_list filter support select2
55+
- custom placeholder for search_fields
56+
57+
```python
58+
# adminlte/admin.py
59+
class ModelAdmin(admin.ModelAdmin):
60+
select2_list_filter = ()
61+
search_field_placeholder = ''
62+
63+
class Media:
64+
css = {
65+
"all": ("admin/components/select2/dist/css/select2.min.css",)
66+
}
67+
js = (
68+
"admin/components/select2/dist/js/select2.min.js",
69+
)
70+
71+
def changelist_view(self, request, extra_context=None):
72+
view = super().changelist_view(request, extra_context)
73+
cl = view.context_data.get('cl')
74+
cl.search_field_placeholder = self.search_field_placeholder
75+
filter_specs = cl.filter_specs
76+
77+
for index, filter_spec in enumerate(filter_specs):
78+
if filter_spec.field_path in self.select2_list_filter:
79+
# flag to use select2
80+
filter_spec.display_select2 = True
81+
cl.filter_specs[index] = filter_spec
82+
view.context_data['cl'] = cl
83+
return view
84+
```
85+
5386
## Widgets
5487

5588
### AdminlteSelect

0 commit comments

Comments
 (0)