django-smartbase-admin 1.0.5__py3-none-any.whl → 1.0.6b1__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.
- django_smartbase_admin/admin/admin_base.py +142 -35
- django_smartbase_admin/admin/widgets.py +81 -23
- django_smartbase_admin/engine/admin_base_view.py +30 -21
- django_smartbase_admin/engine/configuration.py +30 -21
- django_smartbase_admin/static/sb_admin/dist/main.js +1 -1
- django_smartbase_admin/static/sb_admin/dist/main_style.css +1 -1
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Caution.svg +3 -0
- django_smartbase_admin/static/sb_admin/src/css/components/_input.css +19 -15
- django_smartbase_admin/static/sb_admin/src/js/autocomplete.js +18 -0
- django_smartbase_admin/static/sb_admin/src/js/choices.js +8 -0
- django_smartbase_admin/static/sb_admin/src/js/datepicker.js +7 -5
- django_smartbase_admin/static/sb_admin/src/js/main.js +64 -26
- django_smartbase_admin/static/sb_admin/src/js/range.js +3 -2
- django_smartbase_admin/templates/sb_admin/actions/change_form.html +75 -36
- django_smartbase_admin/templates/sb_admin/inlines/table_inline.html +49 -33
- django_smartbase_admin/templates/sb_admin/sprites/sb_admin.svg +1 -1
- django_smartbase_admin/templates/sb_admin/widgets/autocomplete.html +13 -2
- django_smartbase_admin/templates/sb_admin/widgets/date.html +1 -1
- django_smartbase_admin/templates/sb_admin/widgets/includes/related_item_buttons.html +31 -0
- django_smartbase_admin/templates/sb_admin/widgets/time.html +1 -1
- django_smartbase_admin/utils.py +5 -0
- {django_smartbase_admin-1.0.5.dist-info → django_smartbase_admin-1.0.6b1.dist-info}/METADATA +2 -2
- {django_smartbase_admin-1.0.5.dist-info → django_smartbase_admin-1.0.6b1.dist-info}/RECORD +25 -23
- {django_smartbase_admin-1.0.5.dist-info → django_smartbase_admin-1.0.6b1.dist-info}/LICENSE.md +0 -0
- {django_smartbase_admin-1.0.5.dist-info → django_smartbase_admin-1.0.6b1.dist-info}/WHEEL +0 -0
|
@@ -41,7 +41,13 @@ from django_smartbase_admin.services.xlsx_export import (
|
|
|
41
41
|
SBAdminXLSXOptions,
|
|
42
42
|
SBAdminXLSXFormat,
|
|
43
43
|
)
|
|
44
|
-
from django_smartbase_admin.utils import is_htmx_request, render_notifications
|
|
44
|
+
from django_smartbase_admin.utils import is_htmx_request, render_notifications, is_modal
|
|
45
|
+
|
|
46
|
+
SBADMIN_IS_MODAL_VAR = "sbadmin_is_modal"
|
|
47
|
+
SBADMIN_PARENT_INSTANCE_FIELD_NAME_VAR = "sbadmin_parent_instance_field"
|
|
48
|
+
SBADMIN_PARENT_INSTANCE_PK_VAR = "sbadmin_parent_instance_pk"
|
|
49
|
+
SBADMIN_PARENT_INSTANCE_LABEL_VAR = "sbadmin_parent_instance_label"
|
|
50
|
+
SBADMIN_RELOAD_ON_SAVE_VAR = "sbadmin_reload_on_save"
|
|
45
51
|
|
|
46
52
|
|
|
47
53
|
class SBAdminBaseView(object):
|
|
@@ -96,7 +102,7 @@ class SBAdminBaseView(object):
|
|
|
96
102
|
return inner_view
|
|
97
103
|
|
|
98
104
|
def process_actions(
|
|
99
|
-
|
|
105
|
+
self, request, actions: list[SBAdminCustomAction]
|
|
100
106
|
) -> list[SBAdminCustomAction]:
|
|
101
107
|
processed_actions = self.process_actions_permissions(request, actions)
|
|
102
108
|
for processed_action in processed_actions:
|
|
@@ -113,7 +119,7 @@ class SBAdminBaseView(object):
|
|
|
113
119
|
return processed_actions
|
|
114
120
|
|
|
115
121
|
def process_actions_permissions(
|
|
116
|
-
|
|
122
|
+
self, request, actions: list[SBAdminCustomAction]
|
|
117
123
|
) -> list[SBAdminCustomAction]:
|
|
118
124
|
result = []
|
|
119
125
|
for action in actions:
|
|
@@ -192,12 +198,12 @@ class SBAdminBaseView(object):
|
|
|
192
198
|
}
|
|
193
199
|
|
|
194
200
|
def get_sbadmin_detail_actions(
|
|
195
|
-
|
|
201
|
+
self, request, object_id: int | str | None = None
|
|
196
202
|
) -> Iterable[SBAdminCustomAction] | None:
|
|
197
203
|
return self.sbadmin_detail_actions
|
|
198
204
|
|
|
199
205
|
def get_global_context(
|
|
200
|
-
|
|
206
|
+
self, request, object_id: int | str | None = None
|
|
201
207
|
) -> dict[str, Any]:
|
|
202
208
|
return {
|
|
203
209
|
"view_id": self.get_id(),
|
|
@@ -207,6 +213,9 @@ class SBAdminBaseView(object):
|
|
|
207
213
|
"OVERRIDE_CONTENT_OF_NOTIFICATION": OVERRIDE_CONTENT_OF_NOTIFICATION,
|
|
208
214
|
"username_data": self.get_username_data(request),
|
|
209
215
|
"detail_actions": self.get_sbadmin_detail_actions(request, object_id),
|
|
216
|
+
SBADMIN_IS_MODAL_VAR: is_modal(request),
|
|
217
|
+
SBADMIN_RELOAD_ON_SAVE_VAR: SBADMIN_RELOAD_ON_SAVE_VAR in request.GET
|
|
218
|
+
or SBADMIN_RELOAD_ON_SAVE_VAR in request.POST,
|
|
210
219
|
"const": json.dumps(
|
|
211
220
|
{
|
|
212
221
|
"MULTISELECT_FILTER_MAX_CHOICES_SHOWN": MULTISELECT_FILTER_MAX_CHOICES_SHOWN,
|
|
@@ -287,8 +296,8 @@ class SBAdminBaseListView(SBAdminBaseView):
|
|
|
287
296
|
|
|
288
297
|
def is_reorder_active(self, request) -> bool:
|
|
289
298
|
return (
|
|
290
|
-
|
|
291
|
-
|
|
299
|
+
self.is_reorder_available(request)
|
|
300
|
+
and getattr(request, "reorder_active", False) == True
|
|
292
301
|
)
|
|
293
302
|
|
|
294
303
|
def is_reorder_available(self, request) -> str | None:
|
|
@@ -323,7 +332,7 @@ class SBAdminBaseListView(SBAdminBaseView):
|
|
|
323
332
|
qs.filter(**{f"{pk_field}__in": item_ids}).update(
|
|
324
333
|
**{
|
|
325
334
|
self.sbadmin_list_reorder_field: F(self.sbadmin_list_reorder_field)
|
|
326
|
-
|
|
335
|
+
+ int(diff)
|
|
327
336
|
}
|
|
328
337
|
)
|
|
329
338
|
return JsonResponse({"message": request.POST})
|
|
@@ -502,7 +511,7 @@ class SBAdminBaseListView(SBAdminBaseView):
|
|
|
502
511
|
return self.sbadmin_list_selection_actions
|
|
503
512
|
|
|
504
513
|
def get_sbadmin_list_selection_actions_grouped(
|
|
505
|
-
|
|
514
|
+
self, request
|
|
506
515
|
) -> dict[str, list[SBAdminCustomAction]]:
|
|
507
516
|
result = {}
|
|
508
517
|
list_selection_actions = self.process_actions(
|
|
@@ -534,8 +543,8 @@ class SBAdminBaseListView(SBAdminBaseView):
|
|
|
534
543
|
def action_bulk_delete(self, request, modifier):
|
|
535
544
|
action = self.sbadmin_list_action_class(self, request)
|
|
536
545
|
if (
|
|
537
|
-
|
|
538
|
-
|
|
546
|
+
request.request_data.request_method == "POST"
|
|
547
|
+
and request.headers.get("X-TabulatorRequest", None) == "true"
|
|
539
548
|
):
|
|
540
549
|
return redirect(
|
|
541
550
|
self.get_action_url("action_bulk_delete")
|
|
@@ -613,13 +622,13 @@ class SBAdminBaseListView(SBAdminBaseView):
|
|
|
613
622
|
return redirect_to
|
|
614
623
|
|
|
615
624
|
def action_list(
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
625
|
+
self,
|
|
626
|
+
request,
|
|
627
|
+
page_size=None,
|
|
628
|
+
tabulator_definition=None,
|
|
629
|
+
extra_context=None,
|
|
630
|
+
list_actions=None,
|
|
631
|
+
template=None,
|
|
623
632
|
):
|
|
624
633
|
action = self.sbadmin_list_action_class(
|
|
625
634
|
self,
|
|
@@ -672,8 +681,8 @@ class SBAdminBaseListView(SBAdminBaseView):
|
|
|
672
681
|
getattr(field, "filter_field", field): ""
|
|
673
682
|
for field in list_fields
|
|
674
683
|
if field in list_filter
|
|
675
|
-
|
|
676
|
-
|
|
684
|
+
or getattr(field, "name", None) in list_filter
|
|
685
|
+
or getattr(field, "filter_field", None) in list_filter
|
|
677
686
|
}
|
|
678
687
|
url_params = None
|
|
679
688
|
if base_filter:
|
|
@@ -748,7 +757,7 @@ class SBAdminBaseListView(SBAdminBaseView):
|
|
|
748
757
|
|
|
749
758
|
def get_filters_version(self, request) -> FilterVersions:
|
|
750
759
|
return (
|
|
751
|
-
|
|
760
|
+
self.filters_version or request.request_data.configuration.filters_version
|
|
752
761
|
)
|
|
753
762
|
|
|
754
763
|
def get_filters_template_name(self, request) -> str:
|
|
@@ -8,7 +8,7 @@ from django_smartbase_admin.engine.const import (
|
|
|
8
8
|
FilterVersions,
|
|
9
9
|
Action,
|
|
10
10
|
)
|
|
11
|
-
from django_smartbase_admin.utils import to_list
|
|
11
|
+
from django_smartbase_admin.utils import to_list, is_modal
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
class SBAdminConfigurationBase(object):
|
|
@@ -41,12 +41,12 @@ class SBAdminRoleConfiguration(metaclass=Singleton):
|
|
|
41
41
|
filters_version = FilterVersions.FILTERS_VERSION_1
|
|
42
42
|
|
|
43
43
|
def __init__(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
self,
|
|
45
|
+
default_view=None,
|
|
46
|
+
registered_views=None,
|
|
47
|
+
menu_items=None,
|
|
48
|
+
global_filter_form=None,
|
|
49
|
+
filters_version=None,
|
|
50
50
|
) -> None:
|
|
51
51
|
super().__init__()
|
|
52
52
|
self.default_view = default_view or self.default_view or []
|
|
@@ -134,13 +134,13 @@ class SBAdminRoleConfiguration(metaclass=Singleton):
|
|
|
134
134
|
self.autocomplete_map[view.get_id()] = view
|
|
135
135
|
|
|
136
136
|
def restrict_queryset(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
137
|
+
self,
|
|
138
|
+
qs,
|
|
139
|
+
model,
|
|
140
|
+
request,
|
|
141
|
+
request_data,
|
|
142
|
+
global_filter=True,
|
|
143
|
+
global_filter_data_map=None,
|
|
144
144
|
):
|
|
145
145
|
return qs
|
|
146
146
|
|
|
@@ -154,7 +154,7 @@ class SBAdminRoleConfiguration(metaclass=Singleton):
|
|
|
154
154
|
return request.user.is_staff
|
|
155
155
|
|
|
156
156
|
def has_permission(
|
|
157
|
-
|
|
157
|
+
self, request, request_data, view, model=None, obj=None, permission=None
|
|
158
158
|
):
|
|
159
159
|
if isinstance(permission, SBAdminCustomAction):
|
|
160
160
|
return self.has_action_permission(
|
|
@@ -174,7 +174,7 @@ class SBAdminRoleConfiguration(metaclass=Singleton):
|
|
|
174
174
|
return request.user.is_staff
|
|
175
175
|
|
|
176
176
|
def get_autocomplete_widget(
|
|
177
|
-
|
|
177
|
+
self, view, request, form_field, db_field, model, multiselect=False
|
|
178
178
|
):
|
|
179
179
|
from django_smartbase_admin.admin.widgets import SBAdminAutocompleteWidget
|
|
180
180
|
|
|
@@ -186,12 +186,12 @@ class SBAdminRoleConfiguration(metaclass=Singleton):
|
|
|
186
186
|
return default_widget
|
|
187
187
|
|
|
188
188
|
def get_form_field_widget_class(
|
|
189
|
-
|
|
189
|
+
self, view, request, form_field, db_field, default_widget_class
|
|
190
190
|
):
|
|
191
191
|
return default_widget_class
|
|
192
192
|
|
|
193
193
|
def apply_global_filter_to_queryset(
|
|
194
|
-
|
|
194
|
+
self, qs, request, request_data, global_filter_data_map
|
|
195
195
|
):
|
|
196
196
|
global_filter_data_map = global_filter_data_map or {}
|
|
197
197
|
global_filter_data_map = {
|
|
@@ -211,9 +211,9 @@ class SBAdminRoleConfiguration(metaclass=Singleton):
|
|
|
211
211
|
except:
|
|
212
212
|
pass
|
|
213
213
|
if (
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
214
|
+
include_all_values_for_empty_fields
|
|
215
|
+
and field.name in include_all_values_for_empty_fields
|
|
216
|
+
and not field_value
|
|
217
217
|
):
|
|
218
218
|
continue
|
|
219
219
|
field_value = to_list(field_value)
|
|
@@ -226,3 +226,12 @@ class SBAdminRoleConfiguration(metaclass=Singleton):
|
|
|
226
226
|
|
|
227
227
|
def process_global_filter_response(self, response, request):
|
|
228
228
|
return response
|
|
229
|
+
|
|
230
|
+
def autocomplete_show_related_buttons(
|
|
231
|
+
self,
|
|
232
|
+
related_model,
|
|
233
|
+
field_name,
|
|
234
|
+
current_view,
|
|
235
|
+
request,
|
|
236
|
+
) -> bool:
|
|
237
|
+
return not is_modal(request)
|