Skip to content

Commit

Permalink
Adds support for topmenu icons
Browse files Browse the repository at this point in the history
  • Loading branch information
David Farrington committed Dec 31, 2020
1 parent fd1d294 commit 208642a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 27 deletions.
10 changes: 7 additions & 3 deletions jazzmin/templates/admin/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,19 @@
<li class="nav-item d-none d-sm-inline-block{% if link.children %} dropdown{% endif %}">
{% if link.children %}
<a class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
{{ link.name }}
{% if jazzmin_settings.topmenu_icons and link.icon %}<i class="fa-sm {{ link.icon }}">&nbsp;</i> {% endif %}{{ link.name }}
</a>
<div class="dropdown-menu">
{% for child in link.children %}
<a class="dropdown-item" href="{{ child.url }}" {% if link.new_window %}target="_blank"{% endif %}>{{ child.name }}</a>
<a class="dropdown-item" href="{{ child.url }}" {% if link.new_window %}target="_blank"{% endif %}>
{% if jazzmin_settings.topmenu_icons and child.icon %}<i class="fa-sm {{ child.icon }}">&nbsp;</i> {% endif %}{{ child.name }}
</a>
{% endfor %}
</div>
{% else %}
<a href="{{ link.url }}" class="nav-link" {% if link.new_window %}target="_blank"{% endif %}>{{ link.name }}</a>
<a href="{{ link.url }}" class="nav-link" {% if link.new_window %}target="_blank"{% endif %}>
{% if jazzmin_settings.topmenu_icons and link.icon %}<i class="fa-sm {{ link.icon }}">&nbsp;</i> {% endif %}{{ link.name }}
</a>
{% endif %}
</li>
{% endfor %}
Expand Down
7 changes: 4 additions & 3 deletions jazzmin/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def make_menu(
"url": get_custom_url(link["url"], admin_site=admin_site),
"children": None,
"new_window": link.get("new_window", False),
"icon": link.get("icon", options["default_icon_children"]),
"icon": link.get("icon"),
}
)

Expand All @@ -210,7 +210,7 @@ def make_menu(
"url": get_admin_url(link["model"], admin_site=admin_site),
"children": [],
"new_window": link.get("new_window", False),
"icon": options["icons"].get(link["model"], options["default_icon_children"]),
"icon": options["icons"].get(link["model"].lower()),
}
)

Expand All @@ -224,6 +224,7 @@ def make_menu(
"name": child.get("verbose_name", child["name"]),
"url": child["url"],
"children": None,
"icon": options["icons"].get(child["model"].lower()),
}
>>>>>>> 3ec6d11 (test)
for child in get_app_admin_urls(link["app"], admin_site=admin_site)
Expand All @@ -237,7 +238,7 @@ def make_menu(
"name": getattr(apps.app_configs[link["app"]], "verbose_name", link["app"]).title(),
"url": "#",
"children": children,
"icon": options["icons"].get(link["app"], options["default_icon_children"]),
"icon": options["icons"].get(link["app"].lower()),
}
)

Expand Down
32 changes: 11 additions & 21 deletions tests/test_app/library/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,25 +71,15 @@

DATABASES = {
"default": dj_database_url.config(
env="DATABASE_URL",
conn_max_age=500,
default="sqlite:///{}".format(os.path.join(BASE_DIR, "db.sqlite3")),
env="DATABASE_URL", conn_max_age=500, default="sqlite:///{}".format(os.path.join(BASE_DIR, "db.sqlite3")),
)
}

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
{"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",},
{"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",},
{"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",},
{"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",},
]

LANGUAGE_CODE = "en"
Expand Down Expand Up @@ -142,29 +132,27 @@
# Links to put along the top menu
"topmenu_links": [
# Url that gets reversed (Permissions can be added)
{"name": "Home", "url": "admin:index", "permissions": ["auth.view_user"]},
{"name": "Home", "url": "admin:index", "permissions": ["auth.view_user"], "icon": "fas fa-home"},
# external url that opens in a new window (Permissions can be added)
{
"name": "Support",
"url": "https://github.com/farridav/django-jazzmin/issues",
"new_window": True,
"icon": "fas fa-cog",
},
# model admin to link to (Permissions checked against model)
{"model": "auth.User"},
# App with dropdown menu to all its models pages (Permissions checked against models)
{"app": "books"},
{"app": "loans"},
],
"topmenu_icons": True,
#############
# 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,
},
{"name": "Support", "url": "https://github.com/farridav/django-jazzmin/issues", "new_window": True},
{"model": "auth.user"},
],
#############
Expand Down Expand Up @@ -200,9 +188,11 @@
"auth.user": "fas fa-user",
"auth.Group": "fas fa-users",
"admin.LogEntry": "fas fa-file",
"books": "fas fa-book",
"books.Author": "fas fa-user",
"books.Book": "fas fa-book",
"books.Genre": "fas fa-photo-video",
"loans": "fas fa-book-open",
"loans.BookLoan": "fas fa-book-open",
"loans.Library": "fas fa-book-reader",
},
Expand Down

0 comments on commit 208642a

Please sign in to comment.