Skip to content

Commit

Permalink
Merge branch 'release/1.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyue92tree committed Jun 23, 2022
2 parents 2b58b49 + f1c36d8 commit bcc7d3f
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 44 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: main

on: push

jobs:
build-n-publish:
name: Build and publish Python 🐍 distributions 📦 to PyPI
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@master
- name: Set up Python 3.9
uses: actions/setup-python@v1
with:
python-version: 3.9
- name: Install pypa/build
run: >-
python -m
pip install
build
--user
- name: Build a binary wheel and a source tarball
run: >-
python -m
build
--sdist
--wheel
--outdir dist/
.
- name: Publish a Python distribution to PyPI
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/[email protected]
with:
user: __token__
password: ${{ secrets.PYPI }}
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# django-adminlte-ui
[![PyPI Version](https://img.shields.io/pypi/v/django-adminlte-ui.svg)](https://pypi.python.org/pypi/django-adminlte-ui)
[![Download Status](https://img.shields.io/pypi/dm/django-adminlte-ui.svg)](https://pypi.python.org/pypi/django-adminlte-ui)
[![Build Status](https://api.travis-ci.org/wuyue92tree/django-adminlte-ui.svg)](https://travis-ci.org/wuyue92tree/django-adminlte-ui)
[![Build Status](https://github.com/wuyue92tree/django-adminlte-ui/workflows/main/badge.svg)](https://github.com/wuyue92tree/django-adminlte-ui/workflows/main/badge.svg)
[![Documentation Status](https://readthedocs.org/projects/django-adminlte-ui/badge/?version=latest)](https://django-adminlte-ui.readthedocs.io/en/latest/?badge=latest)
[![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)

Expand Down
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.6.1'
version = '1.7.0'
default_app_config = 'adminlteui.apps.AdminlteUIConfig'
27 changes: 27 additions & 0 deletions adminlteui/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,33 @@ def get_image_box():
option_name='site_logo') else ''


class ModelAdmin(admin.ModelAdmin):
select2_list_filter = ()
search_field_placeholder = ''

class Media:
css = {
"all": ("admin/components/select2/dist/css/select2.min.css",)
}
js = (
"admin/components/select2/dist/js/select2.min.js",
)

def changelist_view(self, request, extra_context=None):
view = super().changelist_view(request, extra_context)
cl = view.context_data.get('cl')
cl.search_field_placeholder = self.search_field_placeholder
filter_specs = cl.filter_specs

for index, filter_spec in enumerate(filter_specs):
if filter_spec.field_path in self.select2_list_filter:
# flag to use select2
filter_spec.display_select2 = True
cl.filter_specs[index] = filter_spec
view.context_data['cl'] = cl
return view


class GeneralOptionForm(forms.Form):
site_title = forms.CharField(label=_('Site Title'),
widget=widgets.AdminTextInputWidget(),
Expand Down
26 changes: 20 additions & 6 deletions adminlteui/templates/admin/filter.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
{% load i18n %}

<div class="form-group" style="margin-bottom: 5px;">
<select class="form-control select2 select2-hidden-accessible search-filter" style="width: 100%;" tabindex="-1" aria-hidden="true" data-name="{{ field_name }}">
<select id="id_filter_{{ field_name }}" class="form-control search-filter" style="width: 100%;" tabindex="-1" aria-hidden="true">
<option value="">{{ title }}</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 %}
{% if choice.name %}
<option data-name="{{ choice.name }}" value="{{ choice.value }}" {% if choice.selected %} selected {% endif %}>
{{ choice.display }}
</option>
{% endif %}
{% endfor %}
</select>
{% if spec.display_select2 %}
<script>
django.jQuery('#id_filter_{{ field_name }}').select2({
width: django.jQuery('#id_filter_{{ field_name }}').width() + 26
})
django.jQuery('#id_filter_{{ field_name }}').on('select2:select', function (e) {
if (e.params.data.id !=='') {
django.jQuery('#id_filter_{{ field_name }}').attr('name', e.params.data.element.dataset.name)
} else {
django.jQuery('#id_filter_{{ field_name }}').removeAttr('name')
}
});
</script>
{% endif %}
</div>
55 changes: 41 additions & 14 deletions adminlteui/templates/admin/pagination.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,48 @@
id="example2_paginate">
<ul class="pagination">
{% if pagination_required %}
<li class="paginate_button previous disabled"
id="example2_previous">
<a href="#" aria-controls="example2" data-dt-idx="0"
tabindex="0">{% trans 'Previous' %}</a></li>
{% for i in page_range %}
{% adminlte_paginator_number cl i %}
{% endfor %}
<li class="paginate_button next disabled" id="example2_next">
<a href="#"
aria-controls="example2"
data-dt-idx="7"
tabindex="0">{% trans 'Next' %}</a>
</li>
<li class="paginate_button previous disabled"
id="example2_previous">
<a href="#" aria-controls="example2" data-dt-idx="0"
tabindex="0">{% trans 'Previous' %}</a></li>
{% for i in page_range %}
{% adminlte_paginator_number cl i %}
{% endfor %}
<li class="paginate_button next disabled" id="example2_next">
<a href="#"
aria-controls="example2"
data-dt-idx="7"
tabindex="0">{% trans 'Next' %}</a>
</li>
<script type="text/javascript">
let pageRange = []
{% for p in page_range %}
pageRange.push('{{ p }}')
{% endfor %}
// console.log(pageRange)
let currentPage = document.querySelector("#example2_paginate > ul > li.active > a").innerText
let previous = document.querySelector("#example2_previous > a")
let next = document.querySelector("#example2_next > a")
let target_href = window.location.search.replace(/\?p=\d+/g, '').replace(/&p=\d+/g, '')
// previous button
if ((Number(pageRange[0]) + 1).toString() !== currentPage) {
previous.parentElement.setAttribute('class', 'paginate_button previous')
previous.setAttribute('href', target_href? target_href + `&p=${Number(currentPage) -2}`: target_href + `?p=${Number(currentPage) -2}`)
} else {
previous.parentElement.setAttribute('class', 'paginate_button previous disabled')
previous.setAttribute('href', 'javascript:void(0);')
}
// next button
if ((Number(pageRange[pageRange.length-1]) + 1).toString() !== currentPage) {
next.parentElement.setAttribute('class', 'paginate_button next')
next.setAttribute('href', target_href? target_href + `&p=${currentPage}`: target_href + `?p=${currentPage}`)
} else {
next.parentElement.setAttribute('class', 'paginate_button next disabled')
next.setAttribute('href', 'javascript:void(0);')
}
</script>
{% endif %}
</ul>
</div>
</div>
</div>
</div>
2 changes: 1 addition & 1 deletion adminlteui/templates/admin/search_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
{% if cl.search_fields %}
<!-- DIV needed for valid HTML -->
<div class="form-group" style="margin-bottom: 5px;">
<input class="form-control" type="text" size="40" name="{{ search_var }}" value="{{ cl.query }}" id="searchbar" autofocus>
<input class="form-control" type="text" size="40" placeholder="{{ cl.search_field_placeholder }}" name="{{ search_var }}" value="{{ cl.query }}" id="searchbar" autofocus>
</div>
{% endif %}
{% if cl.has_filters or cl.search_fields %}
Expand Down
6 changes: 6 additions & 0 deletions docs/about.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ChangeLog

## [v1.7.0](https://github.com/wuyue92tree/django-adminlte-ui/releases/tag/1.7.0)
- make previous & next button effective on change_list.html
- use select2 make admin filter searchable
- add search_field_placeholder for search_fields
- use `github actions` replace `travis`

## [v1.6.1](https://github.com/wuyue92tree/django-adminlte-ui/releases/tag/1.6.1)
- fix app in ADMINLTE_SETTINGS but current_user has not perm
- fix model in ADMINLTE_SETTINGS but current_user has not perm
Expand Down
33 changes: 33 additions & 0 deletions docs/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,39 @@ before custom option, you should known what adminlte has used.
- avatar_field
- show_avatar

## ModelAdmin
- make change_list filter support select2
- custom placeholder for search_fields

```python
# adminlte/admin.py
class ModelAdmin(admin.ModelAdmin):
select2_list_filter = ()
search_field_placeholder = ''

class Media:
css = {
"all": ("admin/components/select2/dist/css/select2.min.css",)
}
js = (
"admin/components/select2/dist/js/select2.min.js",
)

def changelist_view(self, request, extra_context=None):
view = super().changelist_view(request, extra_context)
cl = view.context_data.get('cl')
cl.search_field_placeholder = self.search_field_placeholder
filter_specs = cl.filter_specs

for index, filter_spec in enumerate(filter_specs):
if filter_spec.field_path in self.select2_list_filter:
# flag to use select2
filter_spec.display_select2 = True
cl.filter_specs[index] = filter_spec
view.context_data['cl'] = cl
return view
```

## Widgets

### AdminlteSelect
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![PyPI Version](https://img.shields.io/pypi/v/django-adminlte-ui.svg)](https://pypi.python.org/pypi/django-adminlte-ui)
[![Download Status](https://img.shields.io/pypi/dm/django-adminlte-ui.svg)](https://pypi.python.org/pypi/django-adminlte-ui)
[![Build Status](https://api.travis-ci.org/wuyue92tree/django-adminlte-ui.svg)](https://travis-ci.org/wuyue92tree/django-adminlte-ui)
[![Build Status](https://github.com/wuyue92tree/django-adminlte-ui/workflows/main/badge.svg)](https://github.com/wuyue92tree/django-adminlte-ui/workflows/main/badge.svg)
[![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)


Expand Down

0 comments on commit bcc7d3f

Please sign in to comment.