# django-admin-global-sidebar
## Description
Provides a configurable left navigation bar for Django's admin site.
## Features
- Configurable left navigation bar.
- Support two-level menus.
- Support navigation bar folding.
- Support menu item permission control.
- Expand the primary menu and highligh the secondary menu automatically according to the current page path.
- CSS-style icon display for menu items.
## Previews
### Two-level navigation
![Two-level navigation preview](https://gitee.com/rRR0VrFP/django-admin-global-sidebar/raw/master/doc/images/preview.en.01.png)
### Folded navigation
![Folded navigation preview](https://gitee.com/rRR0VrFP/django-admin-global-sidebar/raw/master/doc/images/preview.en.02.png)
## Install
```shell
pip install django-admin-global-sidebar
```
## Usage
- Using `django-admin-global-sidebar` will disable Django's default left navigation bar, which shipped with version 3.x.
- Add dependency packages to `INSTALLED_APPS` in file `pro/settings.py`.
- Define `DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS` in file `pro/settings.py`. If `DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS` is not defined, no navigation bar will be displayed.
**pro/settings.py**
```python
INSTALLED_APPS = [
...
'django_static_fontawesome',
'django_static_jquery3',
'django_admin_global_sidebar',
...
]
DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS = [
{
"title": "Home",
"icon": "fa fa-home",
"url": "/admin/",
},{
"title": "Manage Books",
"icon": "fa fa-book",
"children": [
{
"title": "Manage Categories",
"icon": "fas fa-list",
"model": "django_admin_global_sidebar_example.category",
"permissions": ["django_admin_global_sidebar_example.view_category"],
},{
"title": "Manage Books",
"icon": "fas fa-book",
"model": "django_admin_global_sidebar_example.book",
"permissions": ["django_admin_global_sidebar_example.view_book"],
}
]
},{
"title": "Authenticate",
"icon": "fa fa-cogs",
"children": [
{
"title": "Manage Users",
"icon": "fas fa-user",
"model": "auth.user",
"permissions": ["auth.view_user",],
},
{
"title": "Manage Groups",
"icon": "fas fa-users",
"model": "auth.group",
"permissions": ["auth.view_group",],
}
]
},
]
```
## DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS
- Two-level menus supported.
- Menu item config options:
- `title` is the display title.
- `icon` is fontawesome class.
- `children` is sub-menu list settings.
- `url`, `model` or `view` will be used to calc the menu link. Only one option will be applied.
- `url` means a fixed link.
- `model` means model's changelist view.
- `view` means django's view name and the result link is calced with: revered(`view`).
- `permissions` is the permission array.
- Using `or` logic for permission elements.
- A permission element can be a permission-tag or permission-tags.
- Using `and` logic for permission-tags.
- `active_patterns` used to determine the active status of the menu item.
- Pattern will be used to test against the request.path.
- It can be a pattern string or pattern string list.
- Use `or` logic for patterns.
## Advanced Usage
### Define a navigation loading function and bind it to `DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS`
You can set the `DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS` variable in file 'pro/settings.py' as a fixed menu list, you can also set the 'DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS' variable as the import path of the Menus-Loading-Function. For example, set `DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS="app.menus.get_ menus_ by_ user"`. Here the string "app. menus.get_menus_by_user" is the import path of the function, which can be loading through 'magic_import.import_from_string'. The menu loading function accepts the unique parameter 'request' and returns the menu list. The format of the returned menu list is the same as fixed menu list that assgined to the variable 'DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS'. For example, define the following functions in 'app/menus.py':
```
def get_menus_by_user(request):
user_type = get_user_type(request.user)
if user_type == MANAGER:
return [{
"title": "System Manage",
...
"children": [{
"title": "Account Manage",
...
},{
"title": "Permission Manage",
...
}]
}]
elif user_type == READER:
return [{
"title": "Reader Center",
...
"children": [{
"title": "Card Manage",
...
}]
}]
else:
return []
```
The code above will display different menus according to current user type. If current user is a site administrator, then it will show Manager's menu list. If current user is a reader, then it will show Reader's menu list.
### Load navigation from database
The Menus-Loading-Function is called in the admin site rendering. At that time the database engine is already loaded, so you can access the database to fetch menus dynamiclly.
### Navigation with i18n support
When loading `pro/settings.py`, the i18n service is not ready, so that you can not use `ugettext_xxx` functions. If you want to add i18n support for menu items, you can set `DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS` to a Menus-Loading-Function importing path, in the loading function you you can use `ugettext_xxx` functions freely.
## Releases
### v0.1.0
- First release.
### v0.1.1
- Fix popup problem.
### v0.1.2
- Depends on django-static-jquery3>=5.0.0.
### v0.1.3
- Add django_app_requires support.
### v0.1.4
- Force to disable nav-sidebar for Django3.2.
- Fix global sidebar height in long page.
### v0.2.0
- Fix problem that the page will scroll when clicking on primary menu items.
- You can set `DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS` to Menus-Loading-Function importing path.
### v0.2.1
- Fix sidebar height.
### v0.2.2
- Doc update.
### v0.2.3
- 修正1级菜单children字段缺失导致的大量DEBUG异常输出问题。
Raw data
{
"_id": null,
"home_page": null,
"name": "django-admin-global-sidebar",
"maintainer": "Li HaoRan",
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "django admin extentions, django admin global admin",
"author": "Li HaoRan",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/d8/43/3f38e4178ac1833e7dad4a47dd00f35a072d73d631903946979363b0a0c8/django-admin-global-sidebar-0.2.3.tar.gz",
"platform": null,
"description": "# django-admin-global-sidebar\n\n## Description\n\nProvides a configurable left navigation bar for Django's admin site.\n\n## Features\n\n- Configurable left navigation bar.\n- Support two-level menus.\n- Support navigation bar folding.\n- Support menu item permission control.\n- Expand the primary menu and highligh the secondary menu automatically according to the current page path.\n- CSS-style icon display for menu items.\n\n## Previews\n\n### Two-level navigation\n\n![Two-level navigation preview](https://gitee.com/rRR0VrFP/django-admin-global-sidebar/raw/master/doc/images/preview.en.01.png)\n\n\n### Folded navigation\n\n![Folded navigation preview](https://gitee.com/rRR0VrFP/django-admin-global-sidebar/raw/master/doc/images/preview.en.02.png)\n\n\n## Install\n\n```shell\npip install django-admin-global-sidebar\n```\n\n## Usage\n\n- Using `django-admin-global-sidebar` will disable Django's default left navigation bar, which shipped with version 3.x.\n- Add dependency packages to `INSTALLED_APPS` in file `pro/settings.py`.\n- Define `DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS` in file `pro/settings.py`. If `DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS` is not defined, no navigation bar will be displayed.\n\n**pro/settings.py**\n\n```python\nINSTALLED_APPS = [\n ...\n 'django_static_fontawesome',\n 'django_static_jquery3',\n 'django_admin_global_sidebar',\n ...\n]\n\nDJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS = [\n {\n \"title\": \"Home\",\n \"icon\": \"fa fa-home\",\n \"url\": \"/admin/\",\n },{\n \"title\": \"Manage Books\",\n \"icon\": \"fa fa-book\",\n \"children\": [\n {\n \"title\": \"Manage Categories\",\n \"icon\": \"fas fa-list\",\n \"model\": \"django_admin_global_sidebar_example.category\",\n \"permissions\": [\"django_admin_global_sidebar_example.view_category\"],\n },{\n \"title\": \"Manage Books\",\n \"icon\": \"fas fa-book\",\n \"model\": \"django_admin_global_sidebar_example.book\",\n \"permissions\": [\"django_admin_global_sidebar_example.view_book\"],\n }\n ]\n },{\n \"title\": \"Authenticate\",\n \"icon\": \"fa fa-cogs\",\n \"children\": [\n {\n \"title\": \"Manage Users\",\n \"icon\": \"fas fa-user\",\n \"model\": \"auth.user\",\n \"permissions\": [\"auth.view_user\",],\n },\n {\n \"title\": \"Manage Groups\",\n \"icon\": \"fas fa-users\",\n \"model\": \"auth.group\",\n \"permissions\": [\"auth.view_group\",],\n }\n ]\n },\n]\n\n```\n\n## DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS\n\n- Two-level menus supported.\n- Menu item config options:\n - `title` is the display title.\n - `icon` is fontawesome class.\n - `children` is sub-menu list settings.\n - `url`, `model` or `view` will be used to calc the menu link. Only one option will be applied.\n - `url` means a fixed link.\n - `model` means model's changelist view.\n - `view` means django's view name and the result link is calced with: revered(`view`).\n - `permissions` is the permission array.\n - Using `or` logic for permission elements.\n - A permission element can be a permission-tag or permission-tags.\n - Using `and` logic for permission-tags.\n - `active_patterns` used to determine the active status of the menu item.\n - Pattern will be used to test against the request.path.\n - It can be a pattern string or pattern string list.\n - Use `or` logic for patterns.\n\n\n## Advanced Usage\n\n### Define a navigation loading function and bind it to `DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS`\n\nYou can set the `DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS` variable in file 'pro/settings.py' as a fixed menu list, you can also set the 'DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS' variable as the import path of the Menus-Loading-Function. For example, set `DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS=\"app.menus.get_ menus_ by_ user\"`. Here the string \"app. menus.get_menus_by_user\" is the import path of the function, which can be loading through 'magic_import.import_from_string'. The menu loading function accepts the unique parameter 'request' and returns the menu list. The format of the returned menu list is the same as fixed menu list that assgined to the variable 'DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS'. For example, define the following functions in 'app/menus.py':\n\n```\ndef get_menus_by_user(request):\n user_type = get_user_type(request.user)\n if user_type == MANAGER:\n return [{\n \"title\": \"System Manage\",\n ...\n \"children\": [{\n \"title\": \"Account Manage\",\n ...\n },{\n \"title\": \"Permission Manage\",\n ...\n }]\n }]\n elif user_type == READER:\n return [{\n \"title\": \"Reader Center\",\n ...\n \"children\": [{\n \"title\": \"Card Manage\",\n ...\n }]\n }]\n else:\n return []\n\n```\n\nThe code above will display different menus according to current user type. If current user is a site administrator, then it will show Manager's menu list. If current user is a reader, then it will show Reader's menu list.\n\n### Load navigation from database\n\nThe Menus-Loading-Function is called in the admin site rendering. At that time the database engine is already loaded, so you can access the database to fetch menus dynamiclly.\n\n### Navigation with i18n support\n\nWhen loading `pro/settings.py`, the i18n service is not ready, so that you can not use `ugettext_xxx` functions. If you want to add i18n support for menu items, you can set `DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS` to a Menus-Loading-Function importing path, in the loading function you you can use `ugettext_xxx` functions freely.\n\n## Releases\n\n\n### v0.1.0\n\n- First release.\n\n### v0.1.1\n\n- Fix popup problem.\n\n### v0.1.2\n\n- Depends on django-static-jquery3>=5.0.0.\n\n### v0.1.3\n\n- Add django_app_requires support.\n\n### v0.1.4\n\n- Force to disable nav-sidebar for Django3.2.\n- Fix global sidebar height in long page.\n\n### v0.2.0\n\n- Fix problem that the page will scroll when clicking on primary menu items.\n- You can set `DJANGO_ADMIN_GLOBAL_SIDEBAR_MENUS` to Menus-Loading-Function importing path.\n\n### v0.2.1\n\n- Fix sidebar height.\n\n### v0.2.2\n\n- Doc update.\n\n### v0.2.3\n\n- \u4fee\u6b631\u7ea7\u83dc\u5355children\u5b57\u6bb5\u7f3a\u5931\u5bfc\u81f4\u7684\u5927\u91cfDEBUG\u5f02\u5e38\u8f93\u51fa\u95ee\u9898\u3002\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Provides a configurable left navigation bar for Django's admin site.",
"version": "0.2.3",
"project_urls": null,
"split_keywords": [
"django admin extentions",
" django admin global admin"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "474257e92d11d20f5c50ad9d093c701c992c2d3530fa9fd7b18c82e78d120ce5",
"md5": "97c3d40f40d3f9cefb7a4e1027f1ad4d",
"sha256": "181af783c95c379902c1d0613f4d45db2fdb45fd3fbbf48e6e0465d7ea940de0"
},
"downloads": -1,
"filename": "django_admin_global_sidebar-0.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "97c3d40f40d3f9cefb7a4e1027f1ad4d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 12863,
"upload_time": "2024-05-27T08:38:58",
"upload_time_iso_8601": "2024-05-27T08:38:58.288007Z",
"url": "https://files.pythonhosted.org/packages/47/42/57e92d11d20f5c50ad9d093c701c992c2d3530fa9fd7b18c82e78d120ce5/django_admin_global_sidebar-0.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d8433f38e4178ac1833e7dad4a47dd00f35a072d73d631903946979363b0a0c8",
"md5": "90d70b808190fa3a7accfe10aa04f36e",
"sha256": "ea4aefe42f13e820b086a593f4cac949dbcbe8ba5009ba4a1ea82d4102f9c6d2"
},
"downloads": -1,
"filename": "django-admin-global-sidebar-0.2.3.tar.gz",
"has_sig": false,
"md5_digest": "90d70b808190fa3a7accfe10aa04f36e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 11901,
"upload_time": "2024-05-27T08:39:03",
"upload_time_iso_8601": "2024-05-27T08:39:03.866645Z",
"url": "https://files.pythonhosted.org/packages/d8/43/3f38e4178ac1833e7dad4a47dd00f35a072d73d631903946979363b0a0c8/django-admin-global-sidebar-0.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-27 08:39:03",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "django-admin-global-sidebar"
}