django-unfold 0.41.0__py3-none-any.whl → 0.43.0__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. {django_unfold-0.41.0.dist-info → django_unfold-0.43.0.dist-info}/METADATA +1 -1
  2. {django_unfold-0.41.0.dist-info → django_unfold-0.43.0.dist-info}/RECORD +63 -55
  3. unfold/admin.py +8 -1
  4. unfold/components.py +47 -0
  5. unfold/contrib/filters/admin.py +23 -33
  6. unfold/contrib/guardian/templates/admin/guardian/model/obj_perms_manage.html +1 -1
  7. unfold/contrib/guardian/templates/admin/guardian/model/obj_perms_manage_group.html +1 -1
  8. unfold/contrib/guardian/templates/admin/guardian/model/obj_perms_manage_user.html +1 -1
  9. unfold/contrib/import_export/templates/admin/import_export/export.html +1 -1
  10. unfold/contrib/import_export/templates/admin/import_export/import.html +1 -1
  11. unfold/contrib/import_export/templates/admin/import_export/import_validation.html +26 -21
  12. unfold/contrib/import_export/templates/admin/import_export/resource_fields_list.html +5 -3
  13. unfold/contrib/simple_history/templates/simple_history/object_history_form.html +1 -1
  14. unfold/contrib/simple_history/templates/simple_history/submit_line.html +1 -1
  15. unfold/settings.py +1 -0
  16. unfold/sites.py +25 -5
  17. unfold/static/unfold/css/styles.css +1 -1
  18. unfold/static/unfold/js/app.js +21 -15
  19. unfold/styles.css +14 -1
  20. unfold/templates/admin/base.html +3 -3
  21. unfold/templates/admin/change_form.html +9 -1
  22. unfold/templates/admin/change_list.html +1 -1
  23. unfold/templates/admin/date_hierarchy.html +5 -5
  24. unfold/templates/admin/delete_confirmation.html +1 -1
  25. unfold/templates/admin/delete_selected_confirmation.html +1 -1
  26. unfold/templates/admin/edit_inline/stacked.html +8 -2
  27. unfold/templates/admin/edit_inline/tabular.html +8 -2
  28. unfold/templates/admin/nav_sidebar.html +1 -10
  29. unfold/templates/admin/object_history.html +1 -1
  30. unfold/templates/admin/submit_line.html +2 -2
  31. unfold/templates/unfold/change_list_filter.html +5 -13
  32. unfold/templates/unfold/components/card.html +1 -1
  33. unfold/templates/unfold/components/chart/cohort.html +59 -0
  34. unfold/templates/unfold/components/navigation.html +1 -1
  35. unfold/templates/unfold/components/tracker.html +5 -0
  36. unfold/templates/unfold/helpers/account_links.html +1 -1
  37. unfold/templates/unfold/helpers/actions_row.html +9 -7
  38. unfold/templates/unfold/helpers/field_readonly.html +1 -1
  39. unfold/templates/unfold/helpers/form_label.html +1 -1
  40. unfold/templates/unfold/helpers/header.html +1 -1
  41. unfold/templates/unfold/helpers/label.html +1 -1
  42. unfold/templates/unfold/helpers/language_switch.html +27 -0
  43. unfold/templates/unfold/helpers/messages/debug.html +3 -0
  44. unfold/templates/unfold/helpers/messages/error.html +5 -3
  45. unfold/templates/unfold/helpers/messages/info.html +2 -2
  46. unfold/templates/unfold/helpers/messages/success.html +3 -0
  47. unfold/templates/unfold/helpers/messages/warning.html +3 -0
  48. unfold/templates/unfold/helpers/messages.html +13 -14
  49. unfold/templates/unfold/helpers/tab_list.html +3 -3
  50. unfold/templates/unfold/helpers/theme_switch.html +1 -1
  51. unfold/templates/unfold/helpers/userlinks.html +4 -0
  52. unfold/templates/unfold/helpers/welcomemsg.html +9 -1
  53. unfold/templates/unfold/layouts/base_simple.html +1 -1
  54. unfold/templates/unfold/layouts/skeleton.html +1 -1
  55. unfold/templates/unfold/templatetags/preserve_changelist_filters.html +3 -0
  56. unfold/templates/unfold/widgets/clearable_file_input.html +1 -1
  57. unfold/templates/unfold/widgets/clearable_file_input_small.html +1 -1
  58. unfold/templates/unfold/widgets/split_datetime_vertical.html +1 -1
  59. unfold/templatetags/unfold.py +55 -9
  60. unfold/utils.py +17 -0
  61. unfold/widgets.py +6 -2
  62. {django_unfold-0.41.0.dist-info → django_unfold-0.43.0.dist-info}/LICENSE.md +0 -0
  63. {django_unfold-0.41.0.dist-info → django_unfold-0.43.0.dist-info}/WHEEL +0 -0
unfold/settings.py CHANGED
@@ -12,6 +12,7 @@ CONFIG_DEFAULTS = {
12
12
  "SITE_FAVICONS": [],
13
13
  "SHOW_HISTORY": True,
14
14
  "SHOW_VIEW_ON_SITE": True,
15
+ "SHOW_LANGUAGES": False,
15
16
  "COLORS": {
16
17
  "font": {
17
18
  "subtle-light": "107 114 128", # text-gray-500
unfold/sites.py CHANGED
@@ -1,5 +1,6 @@
1
1
  from http import HTTPStatus
2
2
  from typing import Any, Callable, Dict, List, Optional, Union
3
+ from urllib.parse import parse_qs, urlparse
3
4
 
4
5
  from django.contrib.admin import AdminSite
5
6
  from django.contrib.auth import REDIRECT_FIELD_NAME
@@ -84,6 +85,7 @@ class UnfoldAdminSite(AdminSite):
84
85
  "show_view_on_site": get_config(self.settings_name)[
85
86
  "SHOW_VIEW_ON_SITE"
86
87
  ],
88
+ "show_languages": get_config(self.settings_name)["SHOW_LANGUAGES"],
87
89
  "colors": self._process_colors(
88
90
  get_config(self.settings_name)["COLORS"]
89
91
  ),
@@ -234,6 +236,7 @@ class UnfoldAdminSite(AdminSite):
234
236
 
235
237
  def get_sidebar_list(self, request: HttpRequest) -> List[Dict[str, Any]]:
236
238
  navigation = get_config(self.settings_name)["SIDEBAR"].get("navigation", [])
239
+ tabs = get_config(self.settings_name)["TABS"]
237
240
  results = []
238
241
 
239
242
  for group in navigation:
@@ -245,7 +248,8 @@ class UnfoldAdminSite(AdminSite):
245
248
  request, item.get("link_callback") or item["link"]
246
249
  )
247
250
 
248
- for tab in get_config(self.settings_name)["TABS"]:
251
+ # Checks if any tab item is active and then marks the sidebar link as active
252
+ for tab in tabs:
249
253
  has_primary_link = False
250
254
  has_tab_link_active = False
251
255
 
@@ -302,7 +306,7 @@ class UnfoldAdminSite(AdminSite):
302
306
  item["link_callback"] = lazy(item["link"])(request)
303
307
 
304
308
  item["active"] = self._get_is_active(
305
- request, item.get("link_callback") or item["link"]
309
+ request, item.get("link_callback") or item["link"], True
306
310
  )
307
311
  allowed_items.append(item)
308
312
 
@@ -391,13 +395,29 @@ class UnfoldAdminSite(AdminSite):
391
395
 
392
396
  return colors
393
397
 
394
- def _get_is_active(self, request: HttpRequest, link: str) -> bool:
398
+ def _get_is_active(
399
+ self, request: HttpRequest, link: str, is_tab: bool = False
400
+ ) -> bool:
395
401
  if not isinstance(link, str):
396
402
  link = str(link)
397
403
 
398
- if link in request.path and link != reverse_lazy(f"{self.name}:index"):
404
+ index_path = reverse_lazy(f"{self.name}:index")
405
+ link_path = urlparse(link).path
406
+
407
+ # Dashboard
408
+ if link_path == request.path == index_path:
399
409
  return True
400
- elif link == request.path == reverse_lazy(f"{self.name}:index"):
410
+
411
+ if link_path in request.path and link_path != index_path:
412
+ query_params = parse_qs(urlparse(link).query)
413
+ request_params = parse_qs(request.GET.urlencode())
414
+
415
+ # In case of tabs, we need to check if the query params are the same
416
+ if is_tab and not all(
417
+ request_params.get(k) == v for k, v in query_params.items()
418
+ ):
419
+ return False
420
+
401
421
  return True
402
422
 
403
423
  return False