Skip to content

Commit

Permalink
Merge pull request #53 from farridav/farridav/topmenu_links
Browse files Browse the repository at this point in the history
Top menu links
  • Loading branch information
TysonRV authored Jun 12, 2020
2 parents aed2190 + 13d0d49 commit 566df7f
Show file tree
Hide file tree
Showing 20 changed files with 267 additions and 89 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2019 wuyue
Copyright (c) 2020

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/django-jazzmin.svg)](https://pypi.python.org/pypi/django-jazzmin/)
[![Coverage Status](https://coveralls.io/repos/github/farridav/django-jazzmin/badge.svg?branch=master)](https://coveralls.io/github/farridav/django-jazzmin?branch=master)

Drop-in theme for django admin, that utilises AdminLTE 3 & Bootstrap 4 to make yo' admin looky jazzy
Drop-in theme for django admin, that utilises AdminLTE 3 & Bootstrap 4 to make yo' admin look jazzy

## Installation
```
Expand All @@ -21,6 +21,7 @@ See [Documentation](https://django-jazzmin.readthedocs.io/) or [Test App](./test
- Drop-in, configure only if you want to
- Customisable side menu
- Customisable top menu
- Customisable user menu
- Customisable UI (via Live UI changes, or custom CSS/JS)
- Based on the latest [adminlte](https://adminlte.io/) + [bootstrap](https://getbootstrap.com/)

Expand Down
21 changes: 18 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ See https://django-jazzmin.readthedocs.io also see `Test App`_
Features
--------
- Drop-in admin skin, all configuration optional
- Select2 drop-downs
- Bootstrap 4 & AdminLTE UI components
- Customisable `side menu`_
- Customisable `top menu`_
- Customisable `user menu`_
- Search bar for any given model admin
- Customisable UI (via `Live UI changes`_, or `custom CSS/JS`_)
- Responsive
- Based on the latest `adminlte`_ + `bootstrap`_

Screenshots
Expand All @@ -51,10 +56,20 @@ UI Customiser
~~~~~~~~~~~~~
.. image:: https://django-jazzmin.readthedocs.io/img/ui_customiser.png

Mobile/Tablet layouts
~~~~~~~~~~~~~~~~~~~~~
.. image:: https://django-jazzmin.readthedocs.io/img/dashboard_mobile.png
.. image:: https://django-jazzmin.readthedocs.io/img/dashboard_table.png

Admin Docs (if installed)
~~~~~~~~~~~~~~~~~~~~~~~~~
.. image:: https://django-jazzmin.readthedocs.io/img/admin_docs.png

.. _adminlte: https://adminlte.io/
.. _bootstrap: https://getbootstrap.com
.. _Test App: https://github.com/farridav/django-jazzmin/tree/master/tests/test_app
.. _top menu: https://github.com/farridav/django-jazzmin/blob/master/tests/test_app/settings.py#L61
.. _top menu: https://github.com/farridav/django-jazzmin/blob/master/tests/test_app/settings.py#L62
.. _side menu: https://github.com/farridav/django-jazzmin/blob/master/tests/test_app/settings.py#L92
.. _Live UI changes: https://github.com/farridav/django-jazzmin/blob/master/tests/test_app/settings.py#L90
.. _custom CSS/JS: https://github.com/farridav/django-jazzmin/blob/master/tests/test_app/settings.py#L86
.. _user menu: https://github.com/farridav/django-jazzmin/blob/master/tests/test_app/settings.py#L86
.. _Live UI changes: https://github.com/farridav/django-jazzmin/blob/master/tests/test_app/settings.py#L133
.. _custom CSS/JS: https://github.com/farridav/django-jazzmin/blob/master/tests/test_app/settings.py#L129
25 changes: 24 additions & 1 deletion docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ JAZZMIN_SETTINGS = {
# Field name on user model that contains avatar image
'user_avatar': None,

############
# Top Menu #
############

# Links to put along the top menu
'topmenu_links': [

Expand All @@ -43,6 +47,20 @@ JAZZMIN_SETTINGS = {
{'app': 'polls'},
],

#############
# User Menu #
#############

# Additional links to include in the user menu on the top right ('app' url type is not allowed)
'usermenu_links': [
{'name': 'Support', 'url': 'https://github.com/farridav/django-jazzmin/issues', 'new_window': True},
{'model': 'auth.user'}
],

#############
# Side Menu #
#############

# Whether to display the side menu
'show_sidebar': True,

Expand Down Expand Up @@ -85,6 +103,11 @@ You can enable the top menu by specifying `'topmenu_links'` in your `JAZZMIN_SET

The top menu can be styled with the UI Customiser (See below)

## User menu
You can add links to the user menu on the top right of the screen using the `'usermenu_links'` settings key, the format
of these links is the same as with top menu (above), though submenus via 'app' are not currently supported and will not
be rendered.

## Side menu

### How its generated
Expand All @@ -98,7 +121,7 @@ model is like `auth.user`
Ordering of the menu can be done using `order_with_respect_to`, which is a list of apps you want to base the ordering off
of, it can be a partial list

### Adding custom links
### Side menu custom links

Custom links can be added using `custom_links`, this is a dictionary of links, keyed on the app they will live under.
Example:
Expand Down
Binary file added docs/img/admin_docs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/dashboard_mobile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/dashboard_tablet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 15 additions & 19 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
# Jazzmin

## Installation

Install the latest [pypi](https://pypi.org/project/django-jazzmin/) release with `pip install -U django-jazzmin`

Add `jazzmin` to your `INSTALLED_APPS` before `django.contrib.admin`, and voila!

```python
INSTALLED_APPS = [
'jazzmin',

'django.contrib.admin',
[...]
]
```
Welcome to Jazzmin, intended as a drop-in app to jazz up your django admin site, with plenty of things you can easily
customise, including a built-in UI customizer

## Features

- Drop-in, configure only if you want to
- Select2 drop-downs
- Bootstrap 4 & AdminLTE UI components
- Search bar for any given model admin
- Customisable side menu
- Customisable top menu
- Customisable user menu
- Responsive
- Customisable UI (via Live UI changes, or custom CSS/JS)
- Based on the latest [adminlte](https://adminlte.io/) + [bootstrap](https://getbootstrap.com/)

See [configuration](./configuration.md) for optional customisation of the theme

See [development](./development.md) for notes on setting up for development

## Screenshots

### Dashboard
Expand All @@ -42,7 +31,14 @@ See [development](./development.md) for notes on setting up for development
![login](./img/login.png)

### UI Customiser
![login](./img/ui_customiser.png)
![UI Customiser](./img/ui_customiser.png)

### Mobile/Tablet layouts
![Admin docs](./img/dashboard_mobile.png)
![Admin docs](./img/dashboard_tablet.png)

### Admin docs (if installed)
![Admin docs](./img/admin_docs.png)

## Thanks
This was initially a Fork of https://github.com/wuyue92tree/django-adminlte-ui that we refactored so much we thought it
Expand Down
18 changes: 18 additions & 0 deletions docs/installation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Installation

Install the latest [pypi](https://pypi.org/project/django-jazzmin/) release with `pip install -U django-jazzmin`

Add `jazzmin` to your `INSTALLED_APPS` before `django.contrib.admin`, and Voila!

```python
INSTALLED_APPS = [
'jazzmin',

'django.contrib.admin',
[...]
]
```

See [configuration](./configuration.md) for optional customisation of the theme

See [development](./development.md) for notes on setting up for development
44 changes: 23 additions & 21 deletions jazzmin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.conf import settings
from django.contrib.admin import AdminSite

from .utils import get_admin_url, get_custom_url, get_model_meta, get_app_admin_urls
from .utils import get_admin_url, get_model_meta

DEFAULT_SETTINGS = {
# title of the window
Expand Down Expand Up @@ -35,15 +35,11 @@
'topmenu_links': [],

#############
# UI Tweaks #
# User Menu #
#############

# Relative paths to custom CSS/JS scripts (must be present in static files)
'custom_css': None,
'custom_js': None,

# Whether to show the UI customizer on the sidebar
'show_ui_builder': False,
# Additional links to include in the user menu on the top right ('app' url type is not allowed)
'usermenu_links': [],

#############
# Side Menu #
Expand Down Expand Up @@ -71,7 +67,18 @@
# for a list of icon classes
'icons': {
'auth.user': 'fa-user',
}
},

#############
# UI Tweaks #
#############

# Relative paths to custom CSS/JS scripts (must be present in static files)
'custom_css': None,
'custom_js': None,

# Whether to show the UI customizer on the sidebar
'show_ui_builder': False,
}

#######################################
Expand Down Expand Up @@ -133,21 +140,16 @@ def get_settings():
user_settings = {x: y for x, y in getattr(settings, 'JAZZMIN_SETTINGS', {}).items() if y is not None}
jazzmin_settings.update(user_settings)

# Extract search url from search model
if jazzmin_settings['search_model']:
jazzmin_settings['search_url'] = get_admin_url(jazzmin_settings['search_model'].lower())
jazzmin_settings['search_name'] = jazzmin_settings['search_model'].split('.')[-1] + 's'

for link in jazzmin_settings.get('topmenu_links', []):
if 'url' in link:
link['url'] = get_custom_url(link['url'])
elif 'model' in link:
model_meta = get_model_meta(link['model'])
link['name'] = model_meta.verbose_name_plural.title() if model_meta else link['model']
link['url'] = get_admin_url(link['model'])
elif 'app' in link:
link['name'] = link['app'].title()
link['app_children'] = get_app_admin_urls(link['app'])
model_meta = get_model_meta(jazzmin_settings['search_model'])
if model_meta:
jazzmin_settings['search_name'] = model_meta.verbose_name_plural.title()
else:
jazzmin_settings['search_name'] = jazzmin_settings['search_model'].split('.')[-1] + 's'

# Deal with single strings in hide_apps/hide_models and make sure we lower case 'em
if type(jazzmin_settings['hide_apps']) == str:
jazzmin_settings['hide_apps'] = [jazzmin_settings['hide_apps']]
jazzmin_settings['hide_apps'] = [x.lower() for x in jazzmin_settings['hide_apps']]
Expand Down
2 changes: 1 addition & 1 deletion jazzmin/static/jazzmin/css/django.css
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ body.no-sidebar .content-wrapper, body.no-sidebar .main-footer, body.no-sidebar
word-break: break-word;
}

.brand-link {
.navbar-nav .brand-link {
padding-top: 3px;
}

Expand Down
9 changes: 8 additions & 1 deletion jazzmin/templates/admin/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<i class="far fa-user pr-2" aria-hidden="true"></i>
</a>
{% endif %}
<div class="dropdown-menu dropdown-menu-lg dropdown-menu-right">
<div class="dropdown-menu dropdown-menu-lg dropdown-menu-left" id="jazzy-usermenu">
<span class="dropdown-header">{% trans 'Account' %}</span>
<div class="dropdown-divider"></div>
<a href="{% url 'admin:password_change' %}" class="dropdown-item">
Expand All @@ -119,6 +119,13 @@
{% if perms|can_view_self %}
<a href="{{ request.user|jazzy_admin_url }}" class="dropdown-item dropdown-footer">See Profile</a>
{% endif %}
{% get_user_menu user as user_menu %}
{% for link in user_menu %}
<div class="dropdown-divider"></div>
<a href="{{ link.url }}" class="dropdown-item" {% if link.new_window %}target="_blank"{% endif %}>
<i class="fas {% if link.icon %}{{ link.icon }}{% else %}fa-circle{% endif %} mr-2"></i> {% trans link.name %}
</a>
{% endfor %}
</div>
</li>
</ul>
Expand Down
42 changes: 15 additions & 27 deletions jazzmin/templatetags/jazzmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

from .. import version
from ..settings import get_settings, get_ui_tweaks
from ..utils import order_with_respect_to, get_filter_id, get_custom_url, get_admin_url, get_view_permissions
from ..utils import (
order_with_respect_to, get_filter_id, get_custom_url, get_admin_url, get_view_permissions, make_menu
)

User = get_user_model()
register = Library()
Expand Down Expand Up @@ -80,33 +82,20 @@ def get_side_menu(context):

@register.simple_tag
def get_top_menu(user):
if not user:
return []

model_permissions = get_view_permissions(user)
"""
Produce the menu for the top nav bar
"""
options = get_settings()
return make_menu(user, options.get('topmenu_links', []))

menu = []
for item in options.get('topmenu_links', []):

perm_matches = []
for perm in item.get('permissions', []):
perm_matches.append(user.has_perm(perm))

if not all(perm_matches):
continue

if item.get('model') and item.get('model').lower() not in model_permissions:
continue

if item.get('app'):
item['app_children'] = list(filter(lambda x: x['model'] in model_permissions, item['app_children']))
if len(item['app_children']) == 0:
continue

menu.append(item)

return menu
@register.simple_tag
def get_user_menu(user):
"""
Produce the menu for the user dropdown
"""
options = get_settings()
return make_menu(user, options.get('usermenu_links', []), allow_appmenus=False)


@register.simple_tag
Expand Down Expand Up @@ -253,9 +242,8 @@ def sidebar_status(request):
@register.filter
def can_view_self(perms):
view_perm = '{}.view_{}'.format(User._meta.app_label, User._meta.model_name)
change_perm = '{}.change_{}'.format(User._meta.app_label, User._meta.model_name)

return perms[User._meta.app_label][view_perm] or perms[User._meta.app_label][change_perm]
return perms[User._meta.app_label][view_perm]


@register.simple_tag
Expand Down
Loading

0 comments on commit 566df7f

Please sign in to comment.