django-unfold 0.51.0__py3-none-any.whl → 0.52.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.
unfold/styles.css CHANGED
@@ -4,6 +4,11 @@
4
4
 
5
5
  @tailwind utilities;
6
6
 
7
+ @layer utilities {
8
+ .field-sizing-content {
9
+ field-sizing: content;
10
+ }
11
+ }
7
12
 
8
13
  /*******************************************************
9
14
  Classes
@@ -310,7 +315,7 @@ h3 span:nth-child(3) {
310
315
  .select2-container.select2-container--admin-autocomplete
311
316
  .select2-selection--single
312
317
  .select2-selection__rendered {
313
- @apply font-medium h-9 px-3 py-2 text-base-500 text-sm dark:text-base-300;
318
+ @apply font-medium h-9 px-3 py-2 text-font-default-light text-sm dark:text-font-default-dark;
314
319
  }
315
320
 
316
321
  .select2-container.select2-container--admin-autocomplete
@@ -361,7 +366,7 @@ h3 span:nth-child(3) {
361
366
  .select2-container.select2-container--admin-autocomplete
362
367
  .select2-search--dropdown
363
368
  .select2-search__field {
364
- @apply bg-base-50 border border-base-200 border-solid flex-grow font-medium mx-0 outline-none px-3 py-2 rounded shadow-sm text-base-500 text-sm w-full dark:bg-base-800 dark:border-base-800 dark:text-base-300;
369
+ @apply bg-base-50 border border-base-200 border-solid flex-grow font-medium mx-0 outline-none px-3 py-2 rounded shadow-sm text-font-default-light text-sm w-full dark:bg-base-800 dark:border-base-800 dark:text-font-default-dark;
365
370
  }
366
371
 
367
372
  .select2-container.select2-container--admin-autocomplete.select2-container--open.select2-container--above {
@@ -386,12 +391,17 @@ h3 span:nth-child(3) {
386
391
 
387
392
  .select2-container.select2-container--admin-autocomplete
388
393
  .select2-results__option {
389
- @apply block px-3 py-2 text-base-500 text-sm transition-all dark:text-base-300;
394
+ @apply block px-3 py-2 text-font-default-light text-sm transition-all dark:text-font-default-dark;
390
395
  }
391
396
 
392
397
  .select2-container.select2-container--admin-autocomplete
393
- .select2-results__option--highlighted[aria-selected] {
394
- @apply text-primary-500;
398
+ .select2-results__option[aria-selected="true"] {
399
+ @apply text-primary-600 dark:text-primary-500;
400
+ }
401
+
402
+ .select2-container.select2-container--admin-autocomplete
403
+ .select2-results__option--highlighted[aria-selected="true"] {
404
+ @apply text-primary-600 dark:text-primary-500;
395
405
  }
396
406
 
397
407
  .select2-container.select2-container--admin-autocomplete
@@ -58,7 +58,7 @@
58
58
  {% endblock %}
59
59
 
60
60
  {% block content %}
61
- <div id="content-main">
61
+ <div id="content-main" x-data="{ changeFormWidth: 0 }" x-resize="changeFormWidth = $width">
62
62
  {% block form_before %}{% endblock %}
63
63
 
64
64
  {% if adminform.model_admin.change_form_outer_before_template %}
@@ -3,7 +3,7 @@
3
3
  <div {% if not is_popup %}id="submit-row"{% endif %} class="relative {% if not is_popup %}lg:mt-16{% endif %} z-20">
4
4
  <div class="{% if not is_popup %}max-w-full lg:bottom-0 lg:fixed lg:left-0 lg:right-0{% endif %}" {% if not is_popup %}x-bind:class="{'xl:left-0': !sidebarDesktopOpen, 'xl:left-72': sidebarDesktopOpen}" x-bind:style="'width: ' + mainWidth + 'px'"{% endif %}>
5
5
  <div class="backdrop-blur-sm bg-white/80 pb-4 dark:bg-base-900/80 {% if not is_popup %}lg:border-t lg:border-base-200 lg:py-4 relative lg:scrollable-top lg:px-8 dark:border-base-800{% endif %}">
6
- <div class="flex flex-col-reverse gap-3 items-center mx-auto lg:flex-row-reverse">
6
+ <div class="flex flex-col-reverse gap-3 items-center mx-auto lg:flex-row-reverse" x-bind:style="'width: ' + changeFormWidth + 'px'">
7
7
  {% block submit-row %}
8
8
  {% if show_save %}
9
9
  <button type="submit" name="_save" class="bg-primary-600 block border border-transparent font-medium px-3 py-2 rounded text-white w-full lg:w-auto">
@@ -12,9 +12,9 @@
12
12
  <table class="block border-spacing-none border-separate w-full lg:table">
13
13
  {% if table.headers %}
14
14
  <thead class="text-base-900 dark:text-base-100 {% if height %}sticky top-0{% endif %}">
15
- <tr class="bg-base-50 dark:bg-white/[.02]">
15
+ <tr class="bg-base-50 dark:bg-base-900">
16
16
  {% for header in table.headers %}
17
- <th class="align-middle border-b border-base-200 font-semibold py-2 text-left text-sm whitespace-nowrap sortable column-description hidden px-3 lg:table-cell dark:border-base-800 {% if card_included == 1 %}first:pl-6 last:pr-6{% endif %}">
17
+ <th class="align-middle border-b border-base-200 font-semibold py-2 text-left text-sm whitespace-nowrap sortable column-description hidden px-3 lg:table-cell dark:border-base-800 dark:bg-white/[.02] {% if card_included == 1 %}first:pl-6 last:pr-6{% endif %}">
18
18
  {{ header|capfirst }}
19
19
  </th>
20
20
  {% endfor %}
@@ -0,0 +1,33 @@
1
+ {% with dropdown_id=instance.pk|cut:"-"|add:field_name %}
2
+ {% with total=value.items|length %}
3
+ <div x-data="{ openDropdownId{{ dropdown_id }}: false }">
4
+ <div class="flex flex-row gap-1.5 items-center {% if total > 0 or value.content %}cursor-pointer{% endif %}" {% if total > 0 or value.content %}x-ref="rowDropdown{{ dropdown_id }}" x-on:click="openDropdownId{{ dropdown_id }} = !openDropdownId{{ dropdown_id }}"{% endif %}>
5
+ {% if total > 0 or value.content %}
6
+ <span class="material-symbols-outlined">unfold_more</span>
7
+ {% endif %}
8
+
9
+ <span>
10
+ {{ value.title }}
11
+ </span>
12
+ </div>
13
+
14
+ {% if total > 0 or value.content %}
15
+ <template x-teleport="body">
16
+ {% if value.content %}
17
+ <div class="bg-white border overflow-y-auto overflow-x-hidden p-3 rounded shadow-lg text-sm top-7 z-50 w-48 dark:bg-base-800 dark:border-base-700" data-simplebar x-cloak x-transition x-anchor.bottom-start.offset.4="$refs.rowDropdown{{ dropdown_id }}" x-show="openDropdownId{{ dropdown_id }}"x-on:click.outside="openDropdownId{{ dropdown_id }} = false" {% if value.width or value.height %}style="{% if value.width %}width: {{ value.width }}px;{% endif %}{% if value.height %}height: {{ value.height }}px;{% endif %}"{% endif %}>
18
+ {{ value.content }}
19
+ </div>
20
+ {% else %}
21
+ <nav class="bg-white border overflow-y-auto overflow-x-hidden flex flex-col py-1 rounded shadow-lg text-sm top-7 z-50 w-48 dark:bg-base-800 dark:border-base-700" data-simplebar x-cloak x-transition x-anchor.bottom-start.offset.4="$refs.rowDropdown{{ dropdown_id }}" x-show="openDropdownId{{ dropdown_id }}"x-on:click.outside="openDropdownId{{ dropdown_id }} = false" {% if value.width or value.height %}style="{% if value.width %}width: {{ value.width }}px;{% endif %}{% if value.height %}height: {{ value.height }}px;{% endif %}"{% endif %}>
22
+ {% for item in value.items %}
23
+ <{% if item.link %}a{% else %}span{% endif %} {% if item.link %}href="{{ item.link }}"{% endif %} class="flex items-center gap-2 mx-1 px-3 py-2 max-h-[30px] rounded hover:bg-base-100 dark:hover:bg-base-700 dark:hover:text-base-200 {% if value.striped %}{% cycle '' 'bg-base-50 dark:bg-white/[.04]' %}{% endif %}">
24
+ <span class="grow truncate">{{ item.title }}</span>
25
+ </{% if item.link %}a{% else %}span{% endif %}>
26
+ {% endfor %}
27
+ </nav>
28
+ {% endif %}
29
+ </template>
30
+ {% endif %}
31
+ </div>
32
+ {% endwith %}
33
+ {% endwith %}
@@ -1,6 +1,6 @@
1
1
  {% if adminform.model_admin.compressed_fields %}
2
2
  <div class="flex flex-col gap-4 py-2 lg:flex-row">
3
- <div class="font-medium flex items-start -ml-2 min-w-32 w-32 lg:min-w-48 lg:w-48">
3
+ <div class="font-medium flex items-start -ml-2 min-w-32 w-32 lg:min-w-56 lg:w-56">
4
4
  {{ field.label_tag }}
5
5
  </div>
6
6
 
@@ -1,4 +1,4 @@
1
- <div class="{% if adminform.model_admin.compressed_fields %}lg:min-w-48 lg:mt-2 lg:w-48{% endif %}">
1
+ <div class="{% if adminform.model_admin.compressed_fields %}lg:min-w-56 lg:mt-2 lg:w-56{% endif %}">
2
2
  {{ field.label_tag }}
3
3
  </div>
4
4
 
@@ -1,3 +1,3 @@
1
- <p class="mb-3 px-3 py-3 rounded text-sm last:mb-8 bg-base-100 text-base-700 dark:bg-base-500/20 dark:text-base-400">
1
+ <div class="mb-3 px-3 py-3 rounded text-sm last:mb-8 bg-base-100 text-base-700 dark:bg-base-500/20 dark:text-base-400">
2
2
  {{ message }}
3
- </p>
3
+ </div>
@@ -1,3 +1,3 @@
1
- <p class="mb-3 px-3 py-3 rounded text-sm last:mb-8 bg-blue-100 text-blue-700 dark:bg-blue-500/20 dark:text-blue-400">
1
+ <div class="mb-3 px-3 py-3 rounded text-sm last:mb-8 bg-blue-100 text-blue-700 dark:bg-blue-500/20 dark:text-blue-400">
2
2
  {{ message }}
3
- </p>
3
+ </div>
@@ -1,3 +1,3 @@
1
- <p class="mb-3 px-3 py-3 rounded text-sm last:mb-8 bg-green-100 text-green-700 dark:bg-green-500/20 dark:text-green-400">
1
+ <div class="mb-3 px-3 py-3 rounded text-sm last:mb-8 bg-green-100 text-green-700 dark:bg-green-500/20 dark:text-green-400">
2
2
  {{ message }}
3
- </p>
3
+ </div>
@@ -1,3 +1,3 @@
1
- <p class="mb-3 px-3 py-3 rounded text-sm last:mb-8 bg-orange-100 text-orange-700 dark:bg-orange-500/20 dark:text-orange-400">
1
+ <div class="mb-3 px-3 py-3 rounded text-sm last:mb-8 bg-orange-100 text-orange-700 dark:bg-orange-500/20 dark:text-orange-400">
2
2
  {{ message }}
3
- </p>
3
+ </div>
@@ -1,3 +1,3 @@
1
- <div class="flex flex-col max-w-2xl min-w-48 relative w-full">
1
+ <div class="flex flex-col max-w-2xl min-w-56 relative w-full">
2
2
  {% include "django/forms/widgets/input.html" %}
3
3
  </div>
@@ -1,9 +1,5 @@
1
1
  <div class="datetime flex flex-col gap-2 max-w-2xl lg:flex-row lg:group-[.field-row]:flex-row lg:group-[.field-row]:items-center lg:group-[.field-tabular]:flex-row lg:group-[.field-tabular]:items-center">
2
2
  <div class="basis-1/2 flex flex-col lg:group-[.field-row]:flex-row group-[.field-row]:gap-2 lg:group-[.field-tabular]:flex-row group-[.field-tabular]:gap-2">
3
- <div class="font-medium mb-2 group-[.field-row]:mb-0 group-[.field-row]:flex group-[.field-row]:items-center group-[.field-tabular]:mb-0 group-[.field-tabular]:flex group-[.field-tabular]:items-center">
4
- {{ date_label }}
5
- </div>
6
-
7
3
  {% with widget=widget.subwidgets.0 %}
8
4
  <div class="flex flex-col min-w-52 relative group-[.field-row]:flex-grow group-[.field-tabular]:flex-grow">
9
5
  {% include widget.template_name %}
@@ -12,10 +8,6 @@
12
8
  </div>
13
9
 
14
10
  <div class="basis-1/2 flex flex-col lg:ml-auto md:mt-0 lg:group-[.field-row]:flex-row group-[.field-row]:gap-2 lg:group-[.field-tabular]:flex-row group-[.field-tabular]:gap-2">
15
- <div class="font-medium mb-2 group-[.field-row]:mb-0 group-[.field-row]:flex group-[.field-row]:items-center group-[.field-tabular]:mb-0 group-[.field-tabular]:flex group-[.field-tabular]:items-center">
16
- {{ time_label }}
17
- </div>
18
-
19
11
  {% with widget=widget.subwidgets.1 %}
20
12
  <div class="flex flex-col min-w-52 relative group-[.field-row]:flex-grow group-[.field-tabular]:flex-grow">
21
13
  {% include widget.template_name %}
@@ -1,3 +1,3 @@
1
- <div class="flex flex-col max-w-2xl min-w-48 relative w-full">
1
+ <div class="flex flex-col max-w-2xl min-w-56 relative w-full">
2
2
  {% include "django/forms/widgets/input.html" %}
3
3
  </div>
@@ -369,6 +369,7 @@ def fieldset_row_classes(context: Context) -> str:
369
369
  [
370
370
  "lg:border-b",
371
371
  "lg:border-base-200",
372
+ "lg:border-dashed",
372
373
  "dark:lg:border-base-800",
373
374
  "last:lg:border-b-0",
374
375
  ]
@@ -397,7 +398,8 @@ def fieldset_line_classes(context: Context) -> str:
397
398
  "flex-col",
398
399
  "flex-grow",
399
400
  "group/line",
400
- "p-3",
401
+ "px-3",
402
+ "py-2.5",
401
403
  ]
402
404
  field = context.get("field")
403
405
  adminform = context.get("adminform")
@@ -417,6 +419,7 @@ def fieldset_line_classes(context: Context) -> str:
417
419
  [
418
420
  "border-b",
419
421
  "border-base-200",
422
+ "border-dashed",
420
423
  "group-[.last]/row:border-b-0",
421
424
  "lg:border-b-0",
422
425
  "lg:border-l",
@@ -1,4 +1,5 @@
1
1
  import datetime
2
+ from collections.abc import Generator
2
3
  from typing import Any, Optional, Union
3
4
 
4
5
  from django.contrib.admin.templatetags.admin_list import (
@@ -18,7 +19,6 @@ from django.core.exceptions import ObjectDoesNotExist
18
19
  from django.db import models
19
20
  from django.db.models import Model
20
21
  from django.forms import Form
21
- from django.http import HttpRequest
22
22
  from django.template import Library
23
23
  from django.template.base import Parser, Token
24
24
  from django.template.loader import render_to_string
@@ -28,6 +28,7 @@ from django.utils.safestring import SafeText, mark_safe
28
28
  from django.utils.translation import gettext_lazy as _
29
29
 
30
30
  from unfold.utils import (
31
+ display_for_dropdown,
31
32
  display_for_field,
32
33
  display_for_header,
33
34
  display_for_label,
@@ -189,11 +190,9 @@ def result_headers(cl):
189
190
  }
190
191
 
191
192
 
192
- def items_for_result(cl: ChangeList, result: HttpRequest, form) -> SafeText:
193
- """
194
- Generate the actual list of data.
195
- """
196
-
193
+ def items_for_result(
194
+ cl: ChangeList, result: Model, form
195
+ ) -> Generator[SafeText, None, None]:
197
196
  def link_in_col(is_first: bool, field_name: str, cl: ChangeList) -> bool:
198
197
  if cl.list_display_links is None:
199
198
  return False
@@ -226,9 +225,14 @@ def items_for_result(cl: ChangeList, result: HttpRequest, form) -> SafeText:
226
225
  boolean = getattr(attr, "boolean", False)
227
226
  label = getattr(attr, "label", False)
228
227
  header = getattr(attr, "header", False)
228
+ dropdown = getattr(attr, "dropdown", False)
229
229
 
230
230
  if label:
231
231
  result_repr = display_for_label(value, empty_value_display, label)
232
+ elif dropdown:
233
+ result_repr = display_for_dropdown(
234
+ result, field_name, value, empty_value_display
235
+ )
232
236
  elif header:
233
237
  result_repr = display_for_header(value, empty_value_display)
234
238
  else:
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
@@ -33,6 +34,19 @@ def display_for_header(value: Iterable, empty_value_display: str) -> SafeText:
33
34
  )
34
35
 
35
36
 
37
+ def display_for_dropdown(
38
+ result: Model, field_name: str, value: Iterable, empty_value_display: str
39
+ ) -> SafeText:
40
+ return render_to_string(
41
+ "unfold/helpers/display_dropdown.html",
42
+ {
43
+ "instance": result,
44
+ "field_name": field_name,
45
+ "value": value,
46
+ },
47
+ )
48
+
49
+
36
50
  def display_for_label(value: Any, empty_value_display: str, label: Any) -> SafeText:
37
51
  label_type = None
38
52
  multiple = False
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>