django-unfold 0.51.0__py3-none-any.whl → 0.53.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. {django_unfold-0.51.0.dist-info → django_unfold-0.53.0.dist-info}/METADATA +1 -1
  2. {django_unfold-0.51.0.dist-info → django_unfold-0.53.0.dist-info}/RECORD +40 -37
  3. unfold/contrib/filters/admin/dropdown_filters.py +3 -3
  4. unfold/contrib/filters/admin/mixins.py +1 -1
  5. unfold/contrib/filters/admin/text_filters.py +2 -2
  6. unfold/contrib/filters/templates/unfold/filters/filters_numeric_slider.html +1 -1
  7. unfold/contrib/simple_history/templates/simple_history/object_history.html +2 -2
  8. unfold/decorators.py +13 -4
  9. unfold/forms.py +2 -1
  10. unfold/paginator.py +10 -0
  11. unfold/sites.py +8 -6
  12. unfold/static/unfold/css/styles.css +1 -1
  13. unfold/styles.css +15 -5
  14. unfold/templates/admin/auth/user/add_form.html +1 -1
  15. unfold/templates/admin/change_form.html +10 -9
  16. unfold/templates/admin/pagination.html +4 -20
  17. unfold/templates/admin/submit_line.html +1 -1
  18. unfold/templates/unfold/components/table.html +2 -2
  19. unfold/templates/unfold/helpers/display_dropdown.html +33 -0
  20. unfold/templates/unfold/helpers/fieldset_row.html +19 -7
  21. unfold/templates/unfold/helpers/fieldset_row_checkbox.html +1 -1
  22. unfold/templates/unfold/helpers/fieldset_row_field.html +1 -1
  23. unfold/templates/unfold/helpers/messages/debug.html +2 -2
  24. unfold/templates/unfold/helpers/messages/info.html +2 -2
  25. unfold/templates/unfold/helpers/messages/success.html +2 -2
  26. unfold/templates/unfold/helpers/messages/warning.html +2 -2
  27. unfold/templates/unfold/helpers/pagination_default.html +23 -0
  28. unfold/templates/unfold/helpers/pagination_infinite.html +11 -0
  29. unfold/templates/unfold/helpers/site_icon.html +14 -14
  30. unfold/templates/unfold/helpers/tab_action.html +1 -1
  31. unfold/templates/unfold/helpers/welcomemsg.html +2 -2
  32. unfold/templates/unfold/widgets/date.html +1 -1
  33. unfold/templates/unfold/widgets/split_datetime.html +0 -8
  34. unfold/templates/unfold/widgets/time.html +1 -1
  35. unfold/templatetags/unfold.py +58 -24
  36. unfold/templatetags/unfold_list.py +10 -6
  37. unfold/utils.py +25 -0
  38. unfold/widgets.py +8 -10
  39. unfold/templates/unfold/widgets/textarea_expandable.html +0 -7
  40. {django_unfold-0.51.0.dist-info → django_unfold-0.53.0.dist-info}/LICENSE.md +0 -0
  41. {django_unfold-0.51.0.dist-info → django_unfold-0.53.0.dist-info}/WHEEL +0 -0
unfold/utils.py CHANGED
@@ -6,6 +6,7 @@ from typing import Any, Optional
6
6
 
7
7
  from django.conf import settings
8
8
  from django.db import models
9
+ from django.db.models import Model
9
10
  from django.template.loader import render_to_string
10
11
  from django.utils import formats, timezone
11
12
  from django.utils.hashable import make_hashable
@@ -14,6 +15,13 @@ from django.utils.safestring import SafeText, mark_safe
14
15
 
15
16
  from .exceptions import UnfoldException
16
17
 
18
+ try:
19
+ from djmoney.models.fields import MoneyField
20
+ from djmoney.money import Money
21
+ except ImportError:
22
+ MoneyField = None
23
+ Money = None
24
+
17
25
 
18
26
  def _boolean_icon(field_val: Any) -> str:
19
27
  return render_to_string("unfold/helpers/boolean.html", {"value": field_val})
@@ -33,6 +41,19 @@ def display_for_header(value: Iterable, empty_value_display: str) -> SafeText:
33
41
  )
34
42
 
35
43
 
44
+ def display_for_dropdown(
45
+ result: Model, field_name: str, value: Iterable, empty_value_display: str
46
+ ) -> SafeText:
47
+ return render_to_string(
48
+ "unfold/helpers/display_dropdown.html",
49
+ {
50
+ "instance": result,
51
+ "field_name": field_name,
52
+ "value": value,
53
+ },
54
+ )
55
+
56
+
36
57
  def display_for_label(value: Any, empty_value_display: str, label: Any) -> SafeText:
37
58
  label_type = None
38
59
  multiple = False
@@ -75,6 +96,8 @@ def display_for_value(
75
96
  return formats.localize(timezone.template_localtime(value))
76
97
  elif isinstance(value, (datetime.date, datetime.time)):
77
98
  return formats.localize(value)
99
+ elif Money is not None and isinstance(value, Money):
100
+ return str(value)
78
101
  elif isinstance(value, (int, decimal.Decimal, float)):
79
102
  return formats.number_format(value)
80
103
  elif isinstance(value, (list, tuple)):
@@ -100,6 +123,8 @@ def display_for_field(value: Any, field: Any, empty_value_display: str) -> str:
100
123
  return formats.localize(timezone.template_localtime(value))
101
124
  elif isinstance(field, (models.DateField, models.TimeField)):
102
125
  return formats.localize(value)
126
+ elif MoneyField is not None and isinstance(field, MoneyField):
127
+ return str(value)
103
128
  elif isinstance(field, models.DecimalField):
104
129
  return formats.number_format(value, field.decimal_places)
105
130
  elif isinstance(field, (models.IntegerField, models.FloatField)):
unfold/widgets.py CHANGED
@@ -104,12 +104,9 @@ TEXTAREA_CLASSES = [
104
104
  ]
105
105
 
106
106
  TEXTAREA_EXPANDABLE_CLASSES = [
107
- "absolute",
108
- "bottom-0",
109
- "left-0",
110
- "right-0",
111
- "top-0",
112
- "h-full",
107
+ "block",
108
+ "field-sizing-content",
109
+ "!max-w-2xl",
113
110
  ]
114
111
 
115
112
  SELECT_CLASSES = [
@@ -472,9 +469,7 @@ class UnfoldAdminTextareaWidget(AdminTextareaWidget):
472
469
  )
473
470
 
474
471
 
475
- class UnfoldAdminExpandableTextareaWidget(AdminTextareaWidget):
476
- template_name = "unfold/widgets/textarea_expandable.html"
477
-
472
+ class UnfoldAdminExpandableTextareaWidget(UnfoldAdminTextareaWidget):
478
473
  def __init__(self, attrs: Optional[dict[str, Any]] = None) -> None:
479
474
  attrs = attrs or {}
480
475
 
@@ -499,7 +494,10 @@ class UnfoldAdminSplitDateTimeWidget(AdminSplitDateTime):
499
494
  template_name = "unfold/widgets/split_datetime.html"
500
495
 
501
496
  def __init__(self, attrs: Optional[dict[str, Any]] = None) -> None:
502
- widgets = [UnfoldAdminDateWidget, UnfoldAdminTimeWidget]
497
+ widgets = [
498
+ UnfoldAdminDateWidget(attrs={"placeholder": _("Date")}),
499
+ UnfoldAdminTimeWidget(attrs={"placeholder": _("Time")}),
500
+ ]
503
501
  MultiWidget.__init__(self, widgets, attrs)
504
502
 
505
503
 
@@ -1,7 +0,0 @@
1
- <div class="relative">
2
- <div class="border border-base-200 break-words font-medium invisible max-w-4xl px-3 py-2 text-sm" style="min-height: 64px">
3
- {% if widget.value %}{{ widget.value|linebreaks }}{% endif %}
4
- </div>
5
-
6
- <textarea onInput="this.previousElementSibling.innerText = this.value + String.fromCharCode(10)" name="{{ widget.name }}"{% include "django/forms/widgets/attrs.html" %}>{% if widget.value %}{{ widget.value }}{% endif %}</textarea>
7
- </div>