django-smartbase-admin 1.0.29__py3-none-any.whl → 1.0.30__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/site.py +86 -20
- django_smartbase_admin/engine/configuration.py +4 -0
- django_smartbase_admin/static/sb_admin/dist/main_style.css +1 -1
- django_smartbase_admin/static/sb_admin/dist/tree_widget.js +1 -1
- django_smartbase_admin/static/sb_admin/src/js/tree_widget.js +7 -4
- django_smartbase_admin/templates/sb_admin/authentification/login_base.html +5 -2
- django_smartbase_admin/templates/sb_admin/includes/notifications.html +2 -1
- django_smartbase_admin/templates/sb_admin/inlines/table_inline.html +8 -6
- {django_smartbase_admin-1.0.29.dist-info → django_smartbase_admin-1.0.30.dist-info}/METADATA +14 -14
- {django_smartbase_admin-1.0.29.dist-info → django_smartbase_admin-1.0.30.dist-info}/RECORD +12 -12
- {django_smartbase_admin-1.0.29.dist-info → django_smartbase_admin-1.0.30.dist-info}/LICENSE.md +0 -0
- {django_smartbase_admin-1.0.29.dist-info → django_smartbase_admin-1.0.30.dist-info}/WHEEL +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,16 +29,18 @@ 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
|
|
@@ -41,34 +52,46 @@ class SBAdminSite(admin.AdminSite):
|
|
|
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
64
|
return response
|
|
53
65
|
|
|
54
|
-
def admin_view(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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]:
|
|
66
89
|
try:
|
|
67
90
|
return request.sbadmin_selected_view.get_global_context(request)
|
|
68
|
-
except:
|
|
91
|
+
except Exception:
|
|
69
92
|
return {}
|
|
70
93
|
|
|
71
|
-
def get_urls(self):
|
|
94
|
+
def get_urls(self) -> list[URLPattern | URLResolver]:
|
|
72
95
|
from django.contrib.auth.views import (
|
|
73
96
|
PasswordResetView,
|
|
74
97
|
PasswordResetDoneView,
|
|
@@ -80,6 +103,8 @@ class SBAdminSite(admin.AdminSite):
|
|
|
80
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(
|
|
@@ -173,5 +198,46 @@ class SBAdminSite(admin.AdminSite):
|
|
|
173
198
|
urls.extend(super().get_urls())
|
|
174
199
|
return urls
|
|
175
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
|
+
|
|
176
242
|
|
|
177
243
|
sb_admin_site = SBAdminSite(name="sb_admin")
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from django.contrib.auth import get_permission_codename
|
|
2
|
+
from django.contrib.auth.views import LoginView
|
|
2
3
|
from django.db.models import Q
|
|
3
4
|
|
|
4
5
|
from django_smartbase_admin.admin.site import sb_admin_site
|
|
@@ -41,6 +42,7 @@ class SBAdminRoleConfiguration(metaclass=Singleton):
|
|
|
41
42
|
global_filter_form = None
|
|
42
43
|
filters_version = FilterVersions.FILTERS_VERSION_1
|
|
43
44
|
default_color_scheme = ColorScheme.AUTO
|
|
45
|
+
login_view_class = LoginView
|
|
44
46
|
|
|
45
47
|
def __init__(
|
|
46
48
|
self,
|
|
@@ -50,6 +52,7 @@ class SBAdminRoleConfiguration(metaclass=Singleton):
|
|
|
50
52
|
global_filter_form=None,
|
|
51
53
|
filters_version=None,
|
|
52
54
|
default_color_scheme=None,
|
|
55
|
+
login_view_class=None,
|
|
53
56
|
) -> None:
|
|
54
57
|
super().__init__()
|
|
55
58
|
self.default_view = default_view or self.default_view or []
|
|
@@ -60,6 +63,7 @@ class SBAdminRoleConfiguration(metaclass=Singleton):
|
|
|
60
63
|
self.autocomplete_map = {}
|
|
61
64
|
self.filters_version = filters_version or self.filters_version
|
|
62
65
|
self.default_color_scheme = default_color_scheme or self.default_color_scheme
|
|
66
|
+
self.login_view_class = login_view_class or self.login_view_class
|
|
63
67
|
|
|
64
68
|
def init_registered_views(self):
|
|
65
69
|
registered_views = []
|