django-smartbase-admin 0.2.54__py3-none-any.whl → 1.0.42__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/actions/admin_action_list.py +79 -38
- django_smartbase_admin/actions/advanced_filters.py +24 -1
- django_smartbase_admin/admin/admin_base.py +402 -97
- django_smartbase_admin/admin/site.py +93 -35
- django_smartbase_admin/admin/widgets.py +636 -26
- django_smartbase_admin/apps.py +2 -0
- django_smartbase_admin/engine/actions.py +34 -16
- django_smartbase_admin/engine/admin_base_view.py +252 -115
- django_smartbase_admin/engine/configuration.py +186 -4
- django_smartbase_admin/engine/const.py +6 -0
- django_smartbase_admin/engine/dashboard.py +49 -24
- django_smartbase_admin/engine/fake_inline.py +15 -11
- django_smartbase_admin/engine/field.py +42 -12
- django_smartbase_admin/engine/field_formatter.py +38 -14
- django_smartbase_admin/engine/filter_widgets.py +348 -24
- django_smartbase_admin/engine/menu_item.py +8 -5
- django_smartbase_admin/engine/modal_view.py +12 -7
- django_smartbase_admin/engine/request.py +2 -0
- django_smartbase_admin/integration/__init__.py +0 -0
- django_smartbase_admin/integration/django_cms.py +43 -0
- django_smartbase_admin/locale/sk/LC_MESSAGES/django.mo +0 -0
- django_smartbase_admin/locale/sk/LC_MESSAGES/django.po +268 -37
- django_smartbase_admin/migrations/0005_sbadminuserconfiguration.py +26 -0
- django_smartbase_admin/migrations/0006_alter_sbadminuserconfiguration_color_scheme.py +18 -0
- django_smartbase_admin/models.py +22 -0
- django_smartbase_admin/monkeypatch/admin_readonly_field_monkeypatch.py +96 -0
- django_smartbase_admin/monkeypatch/fake_inline_monkeypatch.py +1 -1
- django_smartbase_admin/querysets.py +3 -0
- django_smartbase_admin/services/configuration.py +30 -0
- django_smartbase_admin/services/thread_local.py +6 -19
- django_smartbase_admin/services/views.py +80 -13
- django_smartbase_admin/services/xlsx_export.py +6 -0
- django_smartbase_admin/static/sb_admin/build/tailwind.config.js +1 -0
- django_smartbase_admin/static/sb_admin/build/tailwind_config_partials/colors.js +4 -0
- django_smartbase_admin/static/sb_admin/build/tailwind_config_partials/spacing.js +1 -0
- django_smartbase_admin/static/sb_admin/build/webpack.common.js +11 -8
- django_smartbase_admin/static/sb_admin/css/ckeditor/ckeditor_content_dark.css +208 -0
- django_smartbase_admin/static/sb_admin/css/coloris/coloris.min.css +1 -0
- django_smartbase_admin/static/sb_admin/dist/calendar.js +1 -0
- django_smartbase_admin/static/sb_admin/dist/calendar_style.css +1 -0
- django_smartbase_admin/static/sb_admin/dist/calendar_style.js +0 -0
- django_smartbase_admin/static/sb_admin/dist/chart.js +1 -1
- 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/dist/table.js +1 -1
- django_smartbase_admin/static/sb_admin/dist/tree_widget.js +1 -0
- django_smartbase_admin/static/sb_admin/dist/tree_widget_style.css +1 -0
- django_smartbase_admin/static/sb_admin/dist/tree_widget_style.js +0 -0
- django_smartbase_admin/static/sb_admin/fancytree/jquery.fancytree-all-deps.min.js +1 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-csv.svg +11 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-doc.svg +11 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-docx.svg +11 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-other.svg +13 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-pdf.svg +11 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-ppt.svg +11 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-xls.svg +11 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-xlsx.svg +11 -0
- django_smartbase_admin/static/sb_admin/images/file_types/file-zip.svg +18 -0
- django_smartbase_admin/static/sb_admin/images/flags/de-at.png +0 -0
- django_smartbase_admin/static/sb_admin/images/flags/de-ch.png +0 -0
- django_smartbase_admin/static/sb_admin/images/logo_light.svg +21 -0
- django_smartbase_admin/static/sb_admin/js/coloris/coloris.min.js +6 -0
- django_smartbase_admin/static/sb_admin/js/fullcalendar.min.js +14804 -0
- django_smartbase_admin/static/sb_admin/js/sbadmin_prepopulated_fields_init.js +25 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Bolt-one.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Calendar.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Caution.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Electric-drill.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Fire-extinguisher.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Gas.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Lightning-fill.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Moon.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Phone-telephone.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Printer.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Pull.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Sun-one.svg +3 -0
- django_smartbase_admin/static/sb_admin/sprites/sb_admin/Time.svg +3 -0
- django_smartbase_admin/static/sb_admin/src/css/_base.css +5 -1
- django_smartbase_admin/static/sb_admin/src/css/_colors.css +257 -82
- django_smartbase_admin/static/sb_admin/src/css/_components.css +61 -13
- django_smartbase_admin/static/sb_admin/src/css/_datepicker.css +8 -1
- django_smartbase_admin/static/sb_admin/src/css/_filer.css +60 -0
- django_smartbase_admin/static/sb_admin/src/css/_inlines.css +51 -10
- django_smartbase_admin/static/sb_admin/src/css/_tabulator.css +8 -2
- django_smartbase_admin/static/sb_admin/src/css/calendar.css +162 -0
- django_smartbase_admin/static/sb_admin/src/css/components/_button.css +41 -1
- django_smartbase_admin/static/sb_admin/src/css/components/_dropdown.css +31 -7
- django_smartbase_admin/static/sb_admin/src/css/components/_input.css +62 -20
- django_smartbase_admin/static/sb_admin/src/css/components/_modal.css +1 -1
- django_smartbase_admin/static/sb_admin/src/css/components/_query-builder.css +21 -2
- django_smartbase_admin/static/sb_admin/src/css/components/_toggle.css +12 -1
- django_smartbase_admin/static/sb_admin/src/css/components/_tooltip.css +8 -22
- django_smartbase_admin/static/sb_admin/src/css/style.css +17 -0
- django_smartbase_admin/static/sb_admin/src/css/tree_widget.css +411 -0
- django_smartbase_admin/static/sb_admin/src/js/autocomplete.js +69 -11
- django_smartbase_admin/static/sb_admin/src/js/calendar.js +56 -0
- django_smartbase_admin/static/sb_admin/src/js/chart.js +8 -22
- django_smartbase_admin/static/sb_admin/src/js/choices.js +18 -8
- django_smartbase_admin/static/sb_admin/src/js/datepicker.js +97 -336
- django_smartbase_admin/static/sb_admin/src/js/datepicker_plugins.js +357 -0
- django_smartbase_admin/static/sb_admin/src/js/main.js +306 -31
- django_smartbase_admin/static/sb_admin/src/js/multiselect.js +50 -41
- django_smartbase_admin/static/sb_admin/src/js/radio.js +31 -0
- django_smartbase_admin/static/sb_admin/src/js/range.js +3 -2
- django_smartbase_admin/static/sb_admin/src/js/table.js +34 -5
- django_smartbase_admin/static/sb_admin/src/js/table_modules/advanced_filter_module.js +43 -20
- django_smartbase_admin/static/sb_admin/src/js/table_modules/data_edit_module.js +8 -10
- django_smartbase_admin/static/sb_admin/src/js/table_modules/detail_view_module.js +50 -1
- django_smartbase_admin/static/sb_admin/src/js/table_modules/filter_module.js +10 -3
- django_smartbase_admin/static/sb_admin/src/js/table_modules/header_tabs_module.js +11 -11
- django_smartbase_admin/static/sb_admin/src/js/table_modules/selection_module.js +28 -8
- django_smartbase_admin/static/sb_admin/src/js/table_modules/table_params_module.js +6 -0
- django_smartbase_admin/static/sb_admin/src/js/table_modules/views_module.js +6 -0
- django_smartbase_admin/static/sb_admin/src/js/tree_widget.js +406 -0
- django_smartbase_admin/static/sb_admin/src/js/utils.js +56 -21
- django_smartbase_admin/templates/sb_admin/actions/change_form.html +176 -116
- django_smartbase_admin/templates/sb_admin/actions/dashboard.html +2 -2
- django_smartbase_admin/templates/sb_admin/actions/list.html +79 -39
- django_smartbase_admin/templates/sb_admin/actions/partials/action_link.html +14 -0
- django_smartbase_admin/templates/sb_admin/actions/partials/tabulator_header_v2.html +2 -2
- django_smartbase_admin/templates/sb_admin/actions/tree_list.html +63 -0
- django_smartbase_admin/templates/sb_admin/authentification/login_base.html +5 -1
- django_smartbase_admin/templates/sb_admin/components/columns.html +1 -1
- django_smartbase_admin/templates/sb_admin/components/filters.html +1 -0
- django_smartbase_admin/templates/sb_admin/components/filters_v2.html +99 -85
- django_smartbase_admin/templates/sb_admin/dashboard/calendar_widget.html +69 -0
- django_smartbase_admin/templates/sb_admin/dashboard/chart_widget.html +21 -2
- django_smartbase_admin/templates/sb_admin/dashboard/list_widget.html +6 -0
- django_smartbase_admin/templates/sb_admin/dashboard/widget_base.html +1 -1
- django_smartbase_admin/templates/sb_admin/filter_widgets/advanced_filters/date_field.html +18 -8
- django_smartbase_admin/templates/sb_admin/filter_widgets/advanced_filters/multiple_choice_field.html +1 -1
- django_smartbase_admin/templates/sb_admin/filter_widgets/advanced_filters/tree_select_filter.html +2 -0
- django_smartbase_admin/templates/sb_admin/filter_widgets/boolean_field.html +1 -14
- django_smartbase_admin/templates/sb_admin/filter_widgets/date_field.html +18 -4
- django_smartbase_admin/templates/sb_admin/filter_widgets/multiple_choice_field.html +14 -0
- django_smartbase_admin/templates/sb_admin/filter_widgets/partials/clear.html +12 -6
- django_smartbase_admin/templates/sb_admin/filter_widgets/radio_choice_field.html +5 -3
- django_smartbase_admin/templates/sb_admin/filter_widgets/tree_select_filter.html +16 -0
- django_smartbase_admin/templates/sb_admin/includes/change_form_title.html +3 -1
- django_smartbase_admin/templates/sb_admin/includes/inline_fieldset.html +48 -39
- django_smartbase_admin/templates/sb_admin/includes/notifications.html +2 -1
- django_smartbase_admin/templates/sb_admin/includes/readonly_boolean_field.html +9 -0
- django_smartbase_admin/templates/sb_admin/includes/readonly_field.html +12 -0
- django_smartbase_admin/templates/sb_admin/includes/table_inline_delete_button.html +4 -5
- django_smartbase_admin/templates/sb_admin/inlines/stacked_inline.html +68 -40
- django_smartbase_admin/templates/sb_admin/inlines/table_inline.html +76 -34
- django_smartbase_admin/templates/sb_admin/integrations/filer/folder_list.html +18 -0
- django_smartbase_admin/templates/sb_admin/navigation.html +166 -158
- django_smartbase_admin/templates/sb_admin/partials/modal/modal_content.html +2 -6
- django_smartbase_admin/templates/sb_admin/sb_admin_base.html +49 -4
- django_smartbase_admin/templates/sb_admin/sb_admin_base_no_sidebar.html +27 -11
- django_smartbase_admin/templates/sb_admin/sb_admin_js_trans.html +3 -0
- django_smartbase_admin/templates/sb_admin/sprites/sb_admin.svg +1 -1
- django_smartbase_admin/templates/sb_admin/tailwind_whitelist.html +6 -3
- django_smartbase_admin/templates/sb_admin/widgets/array.html +0 -1
- django_smartbase_admin/templates/sb_admin/widgets/attributes.html +68 -0
- django_smartbase_admin/templates/sb_admin/widgets/autocomplete.html +13 -2
- django_smartbase_admin/templates/sb_admin/widgets/{checkbox_select.html → checkbox_dropdown.html} +2 -2
- django_smartbase_admin/templates/sb_admin/widgets/clearable_file_input.html +2 -2
- django_smartbase_admin/templates/sb_admin/widgets/color_field.html +30 -0
- django_smartbase_admin/templates/sb_admin/widgets/date.html +8 -1
- django_smartbase_admin/templates/sb_admin/widgets/filer_file.html +84 -0
- django_smartbase_admin/templates/sb_admin/widgets/includes/related_item_buttons.html +38 -0
- django_smartbase_admin/templates/sb_admin/widgets/multiwidget.html +1 -1
- django_smartbase_admin/templates/sb_admin/widgets/radio.html +3 -2
- django_smartbase_admin/templates/sb_admin/widgets/radio_dropdown.html +30 -0
- django_smartbase_admin/templates/sb_admin/widgets/read_only_password_hash.html +3 -0
- django_smartbase_admin/templates/sb_admin/widgets/time.html +8 -1
- django_smartbase_admin/templates/sb_admin/widgets/toggle.html +1 -1
- django_smartbase_admin/templates/sb_admin/widgets/tree_base.html +59 -0
- django_smartbase_admin/templates/sb_admin/widgets/tree_select.html +24 -0
- django_smartbase_admin/templates/sb_admin/widgets/tree_select_inline.html +12 -0
- django_smartbase_admin/templatetags/sb_admin_tags.py +115 -4
- django_smartbase_admin/utils.py +22 -3
- django_smartbase_admin/views/dashboard_view.py +6 -0
- django_smartbase_admin/views/global_filter_view.py +8 -2
- django_smartbase_admin/views/translations_view.py +12 -5
- django_smartbase_admin/views/user_config_view.py +52 -0
- django_smartbase_admin-1.0.42.dist-info/METADATA +166 -0
- {django_smartbase_admin-0.2.54.dist-info → django_smartbase_admin-1.0.42.dist-info}/RECORD +182 -118
- {django_smartbase_admin-0.2.54.dist-info → django_smartbase_admin-1.0.42.dist-info}/WHEEL +1 -1
- django_smartbase_admin/templates/sb_admin/integrations/sorting/change_list.html +0 -401
- django_smartbase_admin-0.2.54.dist-info/METADATA +0 -25
- {django_smartbase_admin-0.2.54.dist-info → django_smartbase_admin-1.0.42.dist-info}/LICENSE.md +0 -0
|
@@ -1,8 +1,17 @@
|
|
|
1
|
+
from collections.abc import Callable
|
|
1
2
|
from functools import update_wrapper
|
|
3
|
+
from typing import Any
|
|
2
4
|
|
|
3
5
|
from django.conf import settings
|
|
4
6
|
from django.contrib import admin
|
|
5
|
-
from django.
|
|
7
|
+
from django.contrib.auth import REDIRECT_FIELD_NAME
|
|
8
|
+
from django.contrib.auth.decorators import login_not_required
|
|
9
|
+
from django.http import HttpRequest, HttpResponse, HttpResponseRedirect
|
|
10
|
+
from django.urls import path, reverse_lazy, URLPattern, URLResolver, reverse
|
|
11
|
+
from django.utils.decorators import method_decorator
|
|
12
|
+
from django.utils.translation import gettext_lazy as _
|
|
13
|
+
from django.views.decorators.cache import never_cache
|
|
14
|
+
from django.views.decorators.csrf import csrf_protect
|
|
6
15
|
from django.views.generic import TemplateView
|
|
7
16
|
|
|
8
17
|
from django_smartbase_admin.engine.admin_entrypoint_view import SBAdminEntrypointView
|
|
@@ -20,56 +29,69 @@ class SBAdminSite(admin.AdminSite):
|
|
|
20
29
|
"sb_admin/authentification/password_change_done.html"
|
|
21
30
|
)
|
|
22
31
|
|
|
23
|
-
def initialize_admin_view(
|
|
32
|
+
def initialize_admin_view(
|
|
33
|
+
self, view_func: Callable[..., HttpResponse], request: HttpRequest, **kwargs
|
|
34
|
+
) -> None:
|
|
24
35
|
request.current_app = "sb_admin"
|
|
25
36
|
selected_view = None
|
|
26
37
|
try:
|
|
27
|
-
selected_view =
|
|
38
|
+
selected_view = view_func.__self__
|
|
28
39
|
from django_smartbase_admin.admin.admin_base import SBAdminBaseView
|
|
29
40
|
|
|
30
41
|
if not isinstance(selected_view, SBAdminBaseView):
|
|
31
42
|
selected_view = None
|
|
32
|
-
except:
|
|
43
|
+
except Exception:
|
|
33
44
|
pass
|
|
34
45
|
request.sbadmin_selected_view = selected_view
|
|
35
46
|
kwargs["view"] = selected_view.get_id() if selected_view else None
|
|
47
|
+
SBAdminThreadLocalService.set_request(request)
|
|
36
48
|
request_data = SBAdminViewRequestData.from_request_and_kwargs(request, **kwargs)
|
|
37
|
-
SBAdminThreadLocalService.set_data("request", request)
|
|
38
49
|
if selected_view:
|
|
39
50
|
# Initialize SBAdmin, ModelAdmin instances, class-based SBAdminEntrypointView are initialized with request_data
|
|
40
51
|
selected_view.init_view_dynamic(
|
|
41
52
|
request, request_data=request_data, **kwargs
|
|
42
53
|
)
|
|
43
54
|
|
|
44
|
-
def admin_view_response_wrapper(
|
|
55
|
+
def admin_view_response_wrapper(
|
|
56
|
+
self, response: HttpResponse, request: HttpRequest, *args, **kwargs
|
|
57
|
+
) -> HttpResponse:
|
|
45
58
|
from django_smartbase_admin.admin.admin_base import SBAdminThirdParty
|
|
46
59
|
|
|
47
60
|
if isinstance(request.sbadmin_selected_view, SBAdminThirdParty):
|
|
48
61
|
response = SBAdminViewService.replace_legacy_admin_access_in_response(
|
|
49
62
|
response
|
|
50
63
|
)
|
|
51
|
-
|
|
52
|
-
SBAdminThreadLocalService.clear_data()
|
|
53
64
|
return response
|
|
54
65
|
|
|
55
|
-
def admin_view(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
def admin_view(
|
|
67
|
+
self,
|
|
68
|
+
view_func: Callable[..., HttpResponse],
|
|
69
|
+
cacheable: bool = False,
|
|
70
|
+
*,
|
|
71
|
+
public: bool = False
|
|
72
|
+
) -> Callable[[HttpRequest, ...], HttpResponse]:
|
|
73
|
+
def inner(request: HttpRequest, *args, **kwargs):
|
|
74
|
+
self.initialize_admin_view(view_func, request, **kwargs)
|
|
75
|
+
response = view_func(request, *args, **kwargs)
|
|
76
|
+
return self.admin_view_response_wrapper(response, request, *args, **kwargs)
|
|
77
|
+
|
|
78
|
+
if not public:
|
|
79
|
+
return super().admin_view(update_wrapper(inner, view_func), cacheable)
|
|
80
|
+
# standard Django admin behaviour, expect it skips staff/permission checks
|
|
81
|
+
if not cacheable:
|
|
82
|
+
inner = never_cache(inner)
|
|
83
|
+
if not getattr(view_func, "csrf_exempt", False):
|
|
84
|
+
inner = csrf_protect(inner)
|
|
85
|
+
inner = login_not_required(inner)
|
|
86
|
+
return update_wrapper(inner, view_func)
|
|
87
|
+
|
|
88
|
+
def each_context(self, request: HttpRequest) -> dict[str, Any]:
|
|
67
89
|
try:
|
|
68
90
|
return request.sbadmin_selected_view.get_global_context(request)
|
|
69
|
-
except:
|
|
91
|
+
except Exception:
|
|
70
92
|
return {}
|
|
71
93
|
|
|
72
|
-
def get_urls(self):
|
|
94
|
+
def get_urls(self) -> list[URLPattern | URLResolver]:
|
|
73
95
|
from django.contrib.auth.views import (
|
|
74
96
|
PasswordResetView,
|
|
75
97
|
PasswordResetDoneView,
|
|
@@ -78,8 +100,11 @@ class SBAdminSite(admin.AdminSite):
|
|
|
78
100
|
PasswordChangeView,
|
|
79
101
|
PasswordChangeDoneView,
|
|
80
102
|
)
|
|
103
|
+
from django_smartbase_admin.views.user_config_view import ColorSchemeView
|
|
81
104
|
|
|
82
105
|
urls = [
|
|
106
|
+
path("login/", self.admin_view(self.login, public=True), name="login"),
|
|
107
|
+
path("logout/", self.admin_view(self.logout), name="logout"),
|
|
83
108
|
path(
|
|
84
109
|
"password_change/",
|
|
85
110
|
self.admin_view(
|
|
@@ -141,19 +166,6 @@ class SBAdminSite(admin.AdminSite):
|
|
|
141
166
|
name="components",
|
|
142
167
|
)
|
|
143
168
|
)
|
|
144
|
-
for model, model_admin in self._registry.items():
|
|
145
|
-
action_view = getattr(model_admin, "action_view", None)
|
|
146
|
-
if not action_view:
|
|
147
|
-
continue
|
|
148
|
-
urls += [
|
|
149
|
-
path(
|
|
150
|
-
"%s/%s/<str:action>/<str:modifier>"
|
|
151
|
-
% (model._meta.app_label, model._meta.model_name),
|
|
152
|
-
self.admin_view(action_view),
|
|
153
|
-
name="%s_%s_action"
|
|
154
|
-
% (model._meta.app_label, model._meta.model_name),
|
|
155
|
-
),
|
|
156
|
-
]
|
|
157
169
|
urls.extend(
|
|
158
170
|
[
|
|
159
171
|
path(
|
|
@@ -166,6 +178,11 @@ class SBAdminSite(admin.AdminSite):
|
|
|
166
178
|
self.admin_view(GlobalFilterView.as_view()),
|
|
167
179
|
name="global_filter",
|
|
168
180
|
),
|
|
181
|
+
path(
|
|
182
|
+
"color-scheme",
|
|
183
|
+
self.admin_view(ColorSchemeView.as_view()),
|
|
184
|
+
name="color_scheme",
|
|
185
|
+
),
|
|
169
186
|
path(
|
|
170
187
|
"<str:view>/<str:action>/<str:modifier>",
|
|
171
188
|
self.admin_view(SBAdminEntrypointView.as_view()),
|
|
@@ -181,5 +198,46 @@ class SBAdminSite(admin.AdminSite):
|
|
|
181
198
|
urls.extend(super().get_urls())
|
|
182
199
|
return urls
|
|
183
200
|
|
|
201
|
+
@method_decorator(never_cache)
|
|
202
|
+
@login_not_required
|
|
203
|
+
def login(self, request: HttpRequest, extra_context: dict[str, Any] | None = None):
|
|
204
|
+
"""
|
|
205
|
+
Same as Django's built-in AdminSite.login view, except it allows the
|
|
206
|
+
login view class to be overridden via configuration.
|
|
207
|
+
"""
|
|
208
|
+
if request.method == "GET" and self.has_permission(request):
|
|
209
|
+
# Already logged-in, redirect to admin index
|
|
210
|
+
index_path = reverse("admin:index", current_app=self.name)
|
|
211
|
+
return HttpResponseRedirect(index_path)
|
|
212
|
+
|
|
213
|
+
# Since this module gets imported in the application's root package,
|
|
214
|
+
# it cannot import models from other applications at the module level,
|
|
215
|
+
# and django.contrib.admin.forms eventually imports User.
|
|
216
|
+
from django.contrib.admin.forms import AdminAuthenticationForm
|
|
217
|
+
|
|
218
|
+
context = {
|
|
219
|
+
**self.each_context(request),
|
|
220
|
+
"title": _("Log in"),
|
|
221
|
+
"subtitle": None,
|
|
222
|
+
"app_path": request.get_full_path(),
|
|
223
|
+
"username": request.user.get_username(),
|
|
224
|
+
}
|
|
225
|
+
if (
|
|
226
|
+
REDIRECT_FIELD_NAME not in request.GET
|
|
227
|
+
and REDIRECT_FIELD_NAME not in request.POST
|
|
228
|
+
):
|
|
229
|
+
context[REDIRECT_FIELD_NAME] = reverse("admin:index", current_app=self.name)
|
|
230
|
+
context.update(extra_context or {})
|
|
231
|
+
|
|
232
|
+
defaults = {
|
|
233
|
+
"extra_context": context,
|
|
234
|
+
"authentication_form": self.login_form or AdminAuthenticationForm,
|
|
235
|
+
"template_name": self.login_template or "admin/login.html",
|
|
236
|
+
}
|
|
237
|
+
request.current_app = self.name
|
|
238
|
+
return request.request_data.configuration.login_view_class.as_view(**defaults)(
|
|
239
|
+
request
|
|
240
|
+
)
|
|
241
|
+
|
|
184
242
|
|
|
185
243
|
sb_admin_site = SBAdminSite(name="sb_admin")
|