django-smartbase-admin 1.0.8__py3-none-any.whl → 1.0.9__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 (22) hide show
  1. django_smartbase_admin/admin/admin_base.py +0 -3
  2. django_smartbase_admin/admin/widgets.py +28 -20
  3. django_smartbase_admin/engine/dashboard.py +15 -1
  4. django_smartbase_admin/engine/filter_widgets.py +3 -2
  5. django_smartbase_admin/static/sb_admin/dist/chart.js +1 -1
  6. django_smartbase_admin/static/sb_admin/dist/main.js +1 -1
  7. django_smartbase_admin/static/sb_admin/src/js/autocomplete.js +32 -0
  8. django_smartbase_admin/static/sb_admin/src/js/chart.js +4 -3
  9. django_smartbase_admin/static/sb_admin/src/js/main.js +1 -1
  10. django_smartbase_admin/static/sb_admin/src/js/multiselect.js +2 -2
  11. django_smartbase_admin/templates/sb_admin/actions/dashboard.html +1 -1
  12. django_smartbase_admin/templates/sb_admin/dashboard/chart_widget.html +1 -0
  13. django_smartbase_admin/templates/sb_admin/includes/inline_fieldset.html +48 -36
  14. django_smartbase_admin/templates/sb_admin/widgets/date.html +1 -1
  15. django_smartbase_admin/templates/sb_admin/widgets/includes/related_item_buttons.html +23 -18
  16. django_smartbase_admin/templates/sb_admin/widgets/multiwidget.html +1 -1
  17. django_smartbase_admin/templates/sb_admin/widgets/time.html +1 -1
  18. django_smartbase_admin/views/dashboard_view.py +6 -0
  19. {django_smartbase_admin-1.0.8.dist-info → django_smartbase_admin-1.0.9.dist-info}/METADATA +1 -1
  20. {django_smartbase_admin-1.0.8.dist-info → django_smartbase_admin-1.0.9.dist-info}/RECORD +22 -22
  21. {django_smartbase_admin-1.0.8.dist-info → django_smartbase_admin-1.0.9.dist-info}/LICENSE.md +0 -0
  22. {django_smartbase_admin-1.0.8.dist-info → django_smartbase_admin-1.0.9.dist-info}/WHEEL +0 -0
@@ -702,9 +702,6 @@ class SBAdmin(
702
702
  menu_label = None
703
703
  sbadmin_is_generic_model = False
704
704
 
705
- def __init__(self, model, admin_site):
706
- super().__init__(model, admin_site)
707
-
708
705
  def save_formset(self, request, form, formset, change):
709
706
  if not change and hasattr(formset, "inline_instance"):
710
707
  # update inline_instance parent_instance on formset when creating new object
@@ -60,25 +60,29 @@ class SBAdminBaseWidget(ContextMixin):
60
60
  def get_context(self, name, value, attrs):
61
61
  context = super().get_context(name, value, attrs)
62
62
  context["widget"]["form_field"] = self.form_field
63
- opts = (
64
- self.form_field.view.opts
65
- if self.form_field
66
- and hasattr(self.form_field, "view")
67
- and hasattr(self.form_field.view, "opts")
68
- else None
69
- )
70
- modal_prefix = ""
71
- try:
72
- modal_prefix = (
73
- "modal_" if is_modal(SBAdminThreadLocalService.get_request()) else ""
74
- )
75
- except:
76
- pass
63
+ opts = None
64
+
65
+ if self.form_field:
66
+ view = getattr(self.form_field, "view", None)
67
+ if view:
68
+ if hasattr(view, "opts"):
69
+ opts = view.opts
70
+ elif hasattr(view, "view") and hasattr(view.view, "opts"):
71
+ opts = view.view.opts
72
+
77
73
  if opts:
74
+ modal_prefix = ""
75
+ try:
76
+ modal_prefix = (
77
+ "modal_"
78
+ if is_modal(SBAdminThreadLocalService.get_request())
79
+ else ""
80
+ )
81
+ except:
82
+ pass
78
83
  context["widget"]["attrs"][
79
84
  "id"
80
85
  ] = f"{modal_prefix}{opts.app_label}_{opts.model_name}_{context['widget']['attrs']['id']}"
81
-
82
86
  return context
83
87
 
84
88
 
@@ -366,6 +370,7 @@ class SBAdminAutocompleteWidget(
366
370
  self.input_id = (
367
371
  context["widget"]["attrs"]["id"] or f'id_{context["widget"]["name"]}'
368
372
  )
373
+
369
374
  context["widget"]["type"] = "hidden"
370
375
  context["widget"]["attrs"]["id"] = self.input_id
371
376
  context["widget"]["attrs"]["class"] = "js-autocomplete-detail"
@@ -404,11 +409,14 @@ class SBAdminAutocompleteWidget(
404
409
  context["widget"]["value"] = json.dumps(selected_options)
405
410
  context["widget"]["value_list"] = selected_options
406
411
 
407
- if threadsafe_request.request_data.configuration.autocomplete_show_related_buttons(
408
- self.model,
409
- field_name=self.field_name,
410
- current_view=self.view,
411
- request=threadsafe_request,
412
+ if (
413
+ threadsafe_request.request_data.configuration.autocomplete_show_related_buttons(
414
+ self.model,
415
+ field_name=self.field_name,
416
+ current_view=self.view,
417
+ request=threadsafe_request,
418
+ )
419
+ and not self.is_multiselect()
412
420
  ):
413
421
  self.add_related_buttons_urls(parsed_value, context)
414
422
 
@@ -17,7 +17,8 @@ from django_smartbase_admin.engine.const import OBJECT_ID_PLACEHOLDER
17
17
  from django_smartbase_admin.engine.field import SBAdminField
18
18
  from django_smartbase_admin.engine.filter_widgets import (
19
19
  DateFilterWidget,
20
- RadioChoiceFilterWidget, )
20
+ RadioChoiceFilterWidget,
21
+ )
21
22
  from django_smartbase_admin.services.views import SBAdminViewService
22
23
  from django_smartbase_admin.utils import to_list
23
24
 
@@ -82,6 +83,7 @@ class SBAdminDashboardWidget(SBAdminView):
82
83
  def get_widget_context_data(self, request):
83
84
  return {
84
85
  "widget_id": self.get_id(),
86
+ "widget_name": self.name,
85
87
  "ajax_url": self.get_ajax_url,
86
88
  "filters": self.get_filters(),
87
89
  "settings": self.get_settings(),
@@ -92,6 +94,12 @@ class SBAdminDashboardWidget(SBAdminView):
92
94
  def get_sub_widgets(self):
93
95
  return self.sub_widgets
94
96
 
97
+ def get_sub_views(self, configuration):
98
+ for idx, sub_widget_view in enumerate(self.sub_widgets):
99
+ sub_widget_view.widget_id = f"{self.get_id()}_{idx}"
100
+ sub_widget_view.init_widget_static(configuration)
101
+ return self.sub_widgets
102
+
95
103
  def get_template_name(self):
96
104
  return self.template_name
97
105
 
@@ -193,6 +201,12 @@ class SBAdminChartAggregateSubWidget(object):
193
201
  def render(self, request):
194
202
  return render_to_string(self.template_name, self.get_context_data(request))
195
203
 
204
+ def init_widget_static(self, configuration):
205
+ pass
206
+
207
+ def init_view_dynamic(self, request, request_data=None, **kwargs):
208
+ pass
209
+
196
210
 
197
211
  class SBAdminDashboardChartWidget(SBAdminDashboardWidget):
198
212
  template_name = "sb_admin/dashboard/chart_widget.html"
@@ -19,7 +19,8 @@ from django_smartbase_admin.engine.const import (
19
19
  AUTOCOMPLETE_PAGE_SIZE,
20
20
  Action,
21
21
  AUTOCOMPLETE_PAGE_NUM,
22
- AUTOCOMPLETE_FORWARD_NAME, SELECT_ALL_KEYWORD,
22
+ AUTOCOMPLETE_FORWARD_NAME,
23
+ SELECT_ALL_KEYWORD,
23
24
  )
24
25
  from django_smartbase_admin.services.translations import SBAdminTranslationsService
25
26
  from django_smartbase_admin.services.views import SBAdminViewService
@@ -232,7 +233,7 @@ class MultipleChoiceFilterWidget(AutocompleteParseMixin, ChoiceFilterWidget):
232
233
  default_label=None,
233
234
  enable_select_all=False,
234
235
  select_all_keyword=SELECT_ALL_KEYWORD,
235
- select_all_label=_('All'),
236
+ select_all_label=_("All"),
236
237
  **kwargs,
237
238
  ) -> None:
238
239
  super().__init__(