Skip to content

Commit

Permalink
Control use of icons
Browse files Browse the repository at this point in the history
  • Loading branch information
David Farrington committed Dec 31, 2020
1 parent 571bea2 commit 6a8f400
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 25 deletions.
6 changes: 3 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ Add a template for your model on your main template directory,
e.g [app/templates/admin/app_name/model_name/submit_line.html](https://github.com/farridav/django-jazzmin/tree/master/tests/test_app/library/books/templates/admin/loans/bookloan/submit_line.html)

```djangotemplate
{# extends "admin/submit_line.html" #}
{#% extends "admin/submit_line.html" %#}
{% block extra-actions %}
{#% block extra-actions %#}
{# For a simple link #}
<div class="form-group">
Expand All @@ -302,7 +302,7 @@ e.g [app/templates/admin/app_name/model_name/submit_line.html](https://github.co
<div class="form-group">
<input type="submit" class="btn btn-outline-info form-control" value="SomeAction" name="_your_action">
</div>
{% endblock %}
{#% endblock %#}
```

If you are adding a button that needs processing with the form, e.g (Save and send) you will need to add the
Expand Down
2 changes: 2 additions & 0 deletions jazzmin/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
############
# Links to put along the nav bar
"topmenu_links": [],
# Whether or not we use icons on the top menu
"topmenu_icons": False,
#############
# User Menu #
#############
Expand Down
6 changes: 3 additions & 3 deletions jazzmin/templatetags/jazzmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
get_admin_url,
make_menu,
has_fieldsets_check,
regroup_available_apps,
regroup_apps,
)

User = get_user_model()
Expand Down Expand Up @@ -65,7 +65,7 @@ def get_side_menu(context: Context, using: str = "available_apps") -> List[Dict]

# If we are using custom grouping, overwrite available_apps based on our grouping
if options.get("custom_menu") and options["custom_menu"]:
available_apps = regroup_available_apps(available_apps, options["custom_menu"])
available_apps = regroup_apps(available_apps, options["custom_menu"])

for app in available_apps:
app_label = app["app_label"].lower()
Expand Down Expand Up @@ -463,7 +463,7 @@ def style_bold_first_word(message: str) -> SafeText:
message_words = escape(message).split()

if not len(message_words):
return ""
return mark_safe("")

message_words[0] = "<strong>{}</strong>".format(message_words[0])

Expand Down
18 changes: 5 additions & 13 deletions jazzmin/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import logging
from typing import List, Union, Dict, Set, Callable
from typing import List, Union, Dict, Set, Callable, Any
from urllib.parse import urlencode

from django.apps import apps
from django.contrib.admin import ListFilter
from django.contrib.admin.helpers import AdminForm
from django.contrib.auth.models import AbstractUser
from django.db.models.base import ModelBase
from django.db.models.base import ModelBase, Model
from django.db.models.options import Options
from django.utils.translation import gettext

Expand All @@ -33,16 +33,13 @@ def order_with_respect_to(original: List, reference: List, getter: Callable = la
return [y for x, y in sorted(zip(ranking, original), key=lambda x: x[0])]


def get_admin_url(
instance: Union[str, ModelBase], admin_site: str = "admin", from_app: bool = False, **kwargs: str
) -> str:
def get_admin_url(instance: Any, admin_site: str = "admin", from_app: bool = False, **kwargs: str) -> str:
"""
Return the admin URL for the given instance, model class or <app>.<model> string
"""
url = "#"

try:

if type(instance) == str:
app_label, model_name = instance.split(".")
model_name = model_name.lower()
Expand Down Expand Up @@ -172,12 +169,7 @@ def make_menu(

menu = []
for link in links:

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

if not all(perm_matches):
if not all([user.has_perm(perm) for perm in link.get("permissions", [])]):
continue

# Url links
Expand Down Expand Up @@ -244,7 +236,7 @@ def has_fieldsets_check(adminform: AdminForm) -> bool:
return True


def regroup_available_apps(available_apps: List[Dict], grouping: Dict[str, List[str]]) -> List[Dict]:
def regroup_apps(available_apps: List[Dict], grouping: Dict[str, List[str]]) -> List[Dict]:
# Make a list of all apps, and all models, keyed on app name or model name
all_models, all_apps = {}, {}
for app in available_apps:
Expand Down
23 changes: 17 additions & 6 deletions tests/test_app/library/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,25 @@

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 @@ -146,6 +156,7 @@
{"app": "books"},
{"app": "loans"},
],
# Whether or not we use icons on the top menu
"topmenu_icons": True,
#############
# User Menu #
Expand Down Expand Up @@ -179,7 +190,7 @@
}
]
},
# Dont generate a menu based off installed apps, instead, craft one using this app/arbitrary name -> model mapping
# Dont generate a side menu from installed apps, instead, craft one using this app/arbitrary name -> model mapping
"custom_menu": {},
# Custom icons for side menu apps/models See https://fontawesome.com/icons?d=gallery&m=free
# for a list of icon classes
Expand Down

0 comments on commit 6a8f400

Please sign in to comment.