diff --git a/jazzmin/settings.py b/jazzmin/settings.py index c5f7d65a..bf57f336 100644 --- a/jazzmin/settings.py +++ b/jazzmin/settings.py @@ -1,6 +1,6 @@ import copy import logging -from typing import Dict, Any +from typing import Any, Dict from django.conf import settings from django.templatetags.static import static @@ -61,7 +61,8 @@ "custom_links": {}, # Custom icons for side menu apps/models See the link below # https://fontawesome.com/icons?d=gallery&m=free&v=5.0.0,5.0.1,5.0.10,5.0.11,5.0.12,5.0.13,5.0.2,5.0.3,5.0.4,5.0.5,5.0.6,5.0.7,5.0.8,5.0.9,5.1.0, - # 5.1.1,5.2.0,5.3.0,5.3.1,5.4.0,5.4.1,5.4.2,5.13.0,5.12.0,5.11.2,5.11.1,5.10.0,5.9.0,5.8.2,5.8.1,5.7.2,5.7.1,5.7.0,5.6.3,5.5.0,5.4.2 + # 5.1.1,5.2.0,5.3.0,5.3.1,5.4.0,5.4.1,5.4.2,5.13.0,5.12.0, + # 5.11.2,5.11.1,5.10.0,5.9.0,5.8.2,5.8.1,5.7.2,5.7.1,5.7.0,5.6.3,5.5.0,5.4.2 # for the full list of 5.13.0 free icon classes "icons": {"auth": "fas fa-users-cog", "auth.user": "fas fa-user", "auth.Group": "fas fa-users"}, # Icons that are used when one is not manually specified @@ -229,11 +230,11 @@ def get_settings() -> Dict: jazzmin_settings["search_models_parsed"].append(jazzmin_search_model) # Deal with single strings in hide_apps/hide_models and make sure we lower case 'em - if type(jazzmin_settings["hide_apps"]) == str: + if isinstance(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"]] - if type(jazzmin_settings["hide_models"]) == str: + if isinstance(jazzmin_settings["hide_models"], str): jazzmin_settings["hide_models"] = [jazzmin_settings["hide_models"]] jazzmin_settings["hide_models"] = [x.lower() for x in jazzmin_settings["hide_models"]] diff --git a/jazzmin/templatetags/jazzmin.py b/jazzmin/templatetags/jazzmin.py index d73fd6e8..aa4ff145 100644 --- a/jazzmin/templatetags/jazzmin.py +++ b/jazzmin/templatetags/jazzmin.py @@ -28,7 +28,13 @@ from .. import version from ..settings import CHANGEFORM_TEMPLATES, get_settings, get_ui_tweaks -from ..utils import get_admin_url, get_filter_id, has_fieldsets_check, make_menu, order_with_respect_to +from ..utils import ( + get_admin_url, + get_filter_id, + has_fieldsets_check, + make_menu, + order_with_respect_to, +) User = get_user_model() register = Library() @@ -118,7 +124,13 @@ def get_user_menu(user: AbstractUser, admin_site: str = "admin") -> List[Dict]: Produce the menu for the user dropdown """ options = get_settings() - return make_menu(user, options.get("usermenu_links", []), options, allow_appmenus=False, admin_site=admin_site) + return make_menu( + user, + options.get("usermenu_links", []), + options, + allow_appmenus=False, + admin_site=admin_site, + ) @register.simple_tag @@ -179,7 +191,7 @@ def get_user_avatar(user: AbstractUser) -> str: # If we find the property directly on the user model (imagefield or URLfield) avatar_field = getattr(user, avatar_field_name, None) if avatar_field: - if type(avatar_field) == str: + if isinstance(avatar_field, str): return avatar_field elif hasattr(avatar_field, "url"): return avatar_field.url @@ -208,18 +220,14 @@ def jazzmin_paginator_number(change_list: ChangeList, i: int) -> SafeText: - """.format( - link=link, disabled="disabled" if link == "#" else "" - ) + """.format(link=link, disabled="disabled" if link == "#" else "") if current_page: html_str += """
  • {num}
  • - """.format( - num=i - ) + """.format(num=i) elif spacer: html_str += """
  • @@ -233,9 +241,7 @@ def jazzmin_paginator_number(change_list: ChangeList, i: int) -> SafeText:
  • {num}
  • - """.format( - num=i, query_string=query_string, end=end - ) + """.format(num=i, query_string=query_string, end=end) if end: link = change_list.get_query_string({PAGE_VAR: change_list.page_num + 1}) if change_list.page_num < i else "#" @@ -243,9 +249,7 @@ def jazzmin_paginator_number(change_list: ChangeList, i: int) -> SafeText: - """.format( - link=link, disabled="disabled" if link == "#" else "" - ) + """.format(link=link, disabled="disabled" if link == "#" else "") return format_html(html_str) @@ -256,7 +260,7 @@ def admin_extra_filters(cl: ChangeList) -> Dict: Return the dict of used filters which is not included in list_filters form """ used_parameters = list(itertools.chain(*(s.used_parameters.keys() for s in cl.filter_specs))) - return dict((k, v) for k, v in cl.params.items() if k not in used_parameters) + return {k: v for k, v in cl.params.items() if k not in used_parameters} @register.simple_tag @@ -330,7 +334,7 @@ def get_sections( """ Get and sort all of the sections that need rendering out in a change form """ - fieldsets = [x for x in admin_form] + fieldsets = list(admin_form) # Make inlines behave like formsets for fieldset in inline_admin_formsets: @@ -457,7 +461,7 @@ def app_is_installed(app: str) -> bool: @register.simple_tag -def action_message_to_list(action: LogEntry) -> List[Dict]: +def action_message_to_list(action: LogEntry) -> List[Dict]: # noqa: C901 """ Retrieves a formatted list with all actions taken by a user given a log entry object """ @@ -528,7 +532,7 @@ def style_bold_first_word(message: str) -> SafeText: message_words[0] = "{}".format(message_words[0]) - message = " ".join([word for word in message_words]) + message = " ".join(list(message_words)) return mark_safe(message) diff --git a/jazzmin/utils.py b/jazzmin/utils.py index dd1c0ea1..c1fe8099 100644 --- a/jazzmin/utils.py +++ b/jazzmin/utils.py @@ -1,12 +1,12 @@ import logging -from typing import List, Union, Dict, Set, Callable, Any +from typing import Any, Callable, Dict, List, Set, Union 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, Model +from django.db.models.base import Model, ModelBase from django.db.models.options import Options from django.utils.translation import gettext @@ -40,8 +40,7 @@ def get_admin_url(instance: Any, admin_site: str = "admin", from_app: bool = Fal url = "#" try: - - if type(instance) == str: + if isinstance(instance, str): app_label, model_name = instance.split(".") model_name = model_name.lower() url = reverse( @@ -165,7 +164,6 @@ def make_menu( menu = [] for link in links: - perm_matches = [] for perm in link.get("permissions", []): perm_matches.append(user.has_perm(perm)) diff --git a/tests/test_admin_views.py b/tests/test_admin_views.py index 1eb3a84a..7a7b9e12 100644 --- a/tests/test_admin_views.py +++ b/tests/test_admin_views.py @@ -1,6 +1,8 @@ import re + import django import pytest + from jazzmin.compat import reverse from .test_app.library.books.models import Book diff --git a/tests/test_app/library/books/admin.py b/tests/test_app/library/books/admin.py index e38b9a4d..d3135b54 100644 --- a/tests/test_app/library/books/admin.py +++ b/tests/test_app/library/books/admin.py @@ -4,6 +4,7 @@ from django.contrib.auth.models import User from django.utils.html import format_html from django.utils.timesince import timesince + from jazzmin.utils import attr from ..loans.admin import BookLoanInline diff --git a/tests/test_app/library/books/management/commands/reset.py b/tests/test_app/library/books/management/commands/reset.py index 14dbb91c..4118ad3c 100644 --- a/tests/test_app/library/books/management/commands/reset.py +++ b/tests/test_app/library/books/management/commands/reset.py @@ -1,18 +1,18 @@ from random import choice -from django.contrib.auth.models import User, Group +from django.contrib.auth.models import Group, User from django.core.management import BaseCommand -from ...models import Book, Author, Genre from ....factories import ( - BookLoanFactory, - UserFactory, AuthorFactory, BookFactory, + BookLoanFactory, GroupFactory, LibraryFactory, + UserFactory, ) -from ....loans.models import Library, BookLoan +from ....loans.models import BookLoan, Library +from ...models import Author, Book, Genre class Command(BaseCommand): diff --git a/tests/test_app/library/loans/views.py b/tests/test_app/library/loans/views.py index 794d0699..0fe9b04e 100644 --- a/tests/test_app/library/loans/views.py +++ b/tests/test_app/library/loans/views.py @@ -1,5 +1,5 @@ -from django.views.generic import TemplateView from django.contrib.admin.sites import site +from django.views.generic import TemplateView class CustomView(TemplateView): diff --git a/tests/test_app/library/settings.py b/tests/test_app/library/settings.py index c170c189..6f4897fb 100644 --- a/tests/test_app/library/settings.py +++ b/tests/test_app/library/settings.py @@ -185,7 +185,8 @@ }, # Custom icons for side menu apps/models See the link below # https://fontawesome.com/icons?d=gallery&m=free&v=5.0.0,5.0.1,5.0.10,5.0.11,5.0.12,5.0.13,5.0.2,5.0.3,5.0.4,5.0.5,5.0.6,5.0.7,5.0.8,5.0.9,5.1.0, - # 5.1.1,5.2.0,5.3.0,5.3.1,5.4.0,5.4.1,5.4.2,5.13.0,5.12.0,5.11.2,5.11.1,5.10.0,5.9.0,5.8.2,5.8.1,5.7.2,5.7.1,5.7.0,5.6.3,5.5.0,5.4.2 + # 5.1.1,5.2.0,5.3.0,5.3.1,5.4.0,5.4.1,5.4.2,5.13.0,5.12.0, + # 5.11.2,5.11.1,5.10.0,5.9.0,5.8.2,5.8.1,5.7.2,5.7.1,5.7.0,5.6.3,5.5.0,5.4.2 # for the full list of 5.13.0 free icon classes "icons": { "auth": "fas fa-users-cog", diff --git a/tests/test_customisation.py b/tests/test_customisation.py index add01f98..657c4e04 100644 --- a/tests/test_customisation.py +++ b/tests/test_customisation.py @@ -1,6 +1,7 @@ import pytest from bs4 import BeautifulSoup from django.urls import reverse + from jazzmin.settings import CHANGEFORM_TEMPLATES from jazzmin.templatetags.jazzmin import get_sections @@ -37,7 +38,7 @@ def test_update_login_logo(client, custom_jazzmin_settings): @pytest.mark.django_db -@pytest.mark.parametrize("config_value,template", [(k, v) for k, v in CHANGEFORM_TEMPLATES.items()]) +@pytest.mark.parametrize("config_value,template", list(CHANGEFORM_TEMPLATES.items())) def test_changeform_templates(config_value, template, admin_client, custom_jazzmin_settings): """ All changeform config values use the correct templates diff --git a/tests/test_templatetags.py b/tests/test_templatetags.py index 46947f28..03da7a7b 100644 --- a/tests/test_templatetags.py +++ b/tests/test_templatetags.py @@ -3,6 +3,7 @@ import pytest from django.contrib.admin.models import CHANGE, LogEntry + from jazzmin.templatetags import jazzmin diff --git a/tests/test_utils.py b/tests/test_utils.py index 2861a973..cc237de0 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -1,19 +1,20 @@ -from unittest.mock import patch, MagicMock, Mock +from unittest.mock import MagicMock, Mock, patch import pytest from django.db.models.functions import Upper from django.urls import reverse from jazzmin.utils import ( - order_with_respect_to, get_admin_url, + get_app_admin_urls, get_custom_url, get_model_meta, - get_app_admin_urls, get_view_permissions, + order_with_respect_to, ) -from .test_app.library.factories import BookFactory, UserFactory + from .test_app.library.books.models import Book +from .test_app.library.factories import BookFactory, UserFactory def test_order_with_respect_to():