diff --git a/adminlteui/__init__.py b/adminlteui/__init__.py index 68e9e47..6d45486 100644 --- a/adminlteui/__init__.py +++ b/adminlteui/__init__.py @@ -1,2 +1,2 @@ -version = '2.1.0' +version = '2.1.1' default_app_config = 'adminlteui.apps.AdminlteUIConfig' diff --git a/adminlteui/core.py b/adminlteui/core.py index b86ba54..a51e1c4 100644 --- a/adminlteui/core.py +++ b/adminlteui/core.py @@ -37,12 +37,17 @@ def make(self, request, models=None, deep=1, deep_limit=0): if not self.name: menu_item['name'] = model.get('name') menu_item['url'] = model.get('admin_url') + # show menu active when access child url, add/change... page + if menu_item['url'] in request.path: + menu_item['active'] = True elif self.menu_type == 'link': menu_item['url'] = self.url # check permissions when permissions are not None if self.permissions: if request.user.has_perms(self.permissions) is False: return None + if menu_item['url'] == request.path: + menu_item['active'] = True else: # menu_type: group and child is empty will hide the menu if not self.child: @@ -55,10 +60,6 @@ def make(self, request, models=None, deep=1, deep_limit=0): menu_item['target_blank'] = self.target_blank menu_item['menu_type'] = self.menu_type or 'group' - if menu_item['menu_type'] != 'group': - if menu_item['url'] == request.path: - menu_item['active'] = True - if self.child: if deep_limit == 0 or deep <= deep_limit: child_list = [] diff --git a/adminlteui/templates/adminlte/date_range_filter.html b/adminlteui/templates/adminlte/date_range_filter.html index 841b442..86ffc18 100644 --- a/adminlteui/templates/adminlte/date_range_filter.html +++ b/adminlteui/templates/adminlte/date_range_filter.html @@ -51,8 +51,13 @@ }); $drp_input.on('cancel.daterangepicker', function(ev, picker) { $drp_input.val('{{ title }}') - $('#id_filter_{{ field_name }}__gte').attr('name', '').val(''); - $('#id_filter_{{ field_name }}__lte').attr('name', '').val(''); + $('#id_filter_{{ field_name }}__gte').removeAttr('name').val(''); + $('#id_filter_{{ field_name }}__lte').removeAttr('name').val(''); + }); + $drp_input.on('change', function(ev) { + $drp_input.val('{{ title }}') + $('#id_filter_{{ field_name }}__gte').removeAttr('name').val(''); + $('#id_filter_{{ field_name }}__lte').removeAttr('name').val(''); }); // set initial value var range = "{{ choices.0.value }}"; diff --git a/docs/assets/images/adminlte_date_range_filter.png b/docs/assets/images/adminlte_date_range_filter.png new file mode 100644 index 0000000..39a614f Binary files /dev/null and b/docs/assets/images/adminlte_date_range_filter.png differ diff --git a/docs/en/changelog.md b/docs/en/changelog.md index 953b587..835c4c2 100644 --- a/docs/en/changelog.md +++ b/docs/en/changelog.md @@ -1,5 +1,12 @@ # ChangeLog +## [v2.1.0](https://github.com/wuyue92tree/django-adminlte-ui/releases/tag/2.1.0) +- add date range filter base on daterangepicker +- add min-width for all filter +- change object-tools position +- update locale +- calculate menu active status from server + ## [v2.0.0](https://github.com/wuyue92tree/django-adminlte-ui/releases/tag/2.0.0) - remove `django-treebeard` deps, fix #28, #29, #30 - remove all adminlte models, make simple diff --git a/docs/en/guide.md b/docs/en/guide.md index f875c9c..b729e21 100644 --- a/docs/en/guide.md +++ b/docs/en/guide.md @@ -87,7 +87,7 @@ top menu,default is `[]`,will show nothing > Tips: Top menu will not show icon,only support secondary menu max ## ModelAdmin -external ModelAdmin in django +### external ModelAdmin in django - make table filter support `select2` in `change_list` page - custom search field placeholder for `change_list` page @@ -109,6 +109,24 @@ effect ![modeladmin](../assets/images/modeladmin.png) +### Custom Filters +#### DateRangeFilter + +example: +```python title='rap/admin.py' +from adminlteui.admin import ModelAdmin +from adminlteui.filters import DateRangeFilter + +class AutomationTaskRecordAdmin(CommonAdmin, ModelAdmin): + list_display = ('id', 'automation', 'account', 'status', 'start_time', + 'end_time', 'update_time') + list_filter = ('automation__project', 'automation__source', + 'status', ('start_time', DateRangeFilter), ('end_time', DateRangeFilter)) + +``` +effect: +![adminlte_date_range_filter](../assets/images/adminlte_date_range_filter.png) + ## Widgets ### AdminlteSelect @@ -146,4 +164,4 @@ class CollectorAdmin(admin.ModelAdmin): ``` effect: -![adminlte_select](../assets/images/adminlte_select_multiple.png) +![adminlte_select_multiple](../assets/images/adminlte_select_multiple.png) diff --git a/docs/en/index.md b/docs/en/index.md index 3fec882..5f7ca3e 100644 --- a/docs/en/index.md +++ b/docs/en/index.md @@ -53,6 +53,7 @@ INSTALLED_APPS = [ ## Features - [Custom General Option](/django-adminlte-ui/2.x/guide/#basic-info) +- [ModelAdmin](/django-adminlte-ui/2.x/guide/#modeladmin) - [Widgets](/django-adminlte-ui/2.x/guide/#widgets) - [Custom Menu](/django-adminlte-ui/2.x/guide/#menu) diff --git a/docs/zh/changelog.md b/docs/zh/changelog.md index 8344c66..352c834 100644 --- a/docs/zh/changelog.md +++ b/docs/zh/changelog.md @@ -1,5 +1,13 @@ # 更新说明 + +## [v2.1.0](https://github.com/wuyue92tree/django-adminlte-ui/releases/tag/2.1.0) +- 新增基于daterangepicker的时间过滤器 +- 为所有的filter新增min-width样式 +- 调整change_list视图object-tools的位置,与actions处于同一行 +- 更新locale +- 在服务器端计算菜单的活跃状态,原来通过js在浏览器实现 + ## [v2.0.0](https://github.com/wuyue92tree/django-adminlte-ui/releases/tag/2.0.0) - 移除 `django-treebeard` 依赖包, 同时修复 #28, #29, #30 - 移除了所有models,不再通过数据库的方式管理自定义菜单及其他选项 diff --git a/docs/zh/guide.md b/docs/zh/guide.md index 6b45534..14c9177 100644 --- a/docs/zh/guide.md +++ b/docs/zh/guide.md @@ -87,7 +87,7 @@ class MyAdminlteConfig(AdminlteConfig): > Tips: 顶部菜单将不显示Icon,并且最多显示二级菜单,多余的将被隐藏 ## ModelAdmin -扩展django的ModelAdmin +### 扩展django的ModelAdmin - 让`change_list`页面的table过滤器支持`select2` - 自定义`change_list`页面搜索框的placeholder提示 @@ -109,6 +109,26 @@ class CollectorModelAdmin(ModelAdmin): ![modeladmin](../assets/images/modeladmin.png) +### Filters过滤器 +#### DateRangeFilter + +基于datarangepicker的时间范围过滤器 + +示例: +```python title='rap/admin.py' +from adminlteui.admin import ModelAdmin +from adminlteui.filters import DateRangeFilter + +class AutomationTaskRecordAdmin(CommonAdmin, ModelAdmin): + list_display = ('id', 'automation', 'account', 'status', 'start_time', + 'end_time', 'update_time') + list_filter = ('automation__project', 'automation__source', + 'status', ('start_time', DateRangeFilter), ('end_time', DateRangeFilter)) + +``` +效果图: +![adminlte_date_range_filter](../assets/images/adminlte_date_range_filter.png) + ## Widgets组件 ### AdminlteSelect @@ -146,4 +166,4 @@ class CollectorAdmin(admin.ModelAdmin): ``` 效果图: -![adminlte_select](../assets/images/adminlte_select_multiple.png) +![adminlte_select_multiple](../assets/images/adminlte_select_multiple.png) diff --git a/docs/zh/index.md b/docs/zh/index.md index a3d1b6e..e121406 100644 --- a/docs/zh/index.md +++ b/docs/zh/index.md @@ -53,6 +53,7 @@ INSTALLED_APPS = [ ## 功能 - [自定义属性](/django-adminlte-ui/2.x/zh/guide/#_4) +- [ModelAdmin扩展](/django-adminlte-ui/2.x/zh/guide/#modeladmin) - [Widget组件](/django-adminlte-ui/2.x/zh/guide/#widgets) - [自定义菜单](/django-adminlte-ui/2.x/zh/guide/#_5)