Skip to content

Commit 4b57c3d

Browse files
committed
customise view authentication handler
1 parent 632fa25 commit 4b57c3d

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

CHANGES

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
1.5.3
2+
-----
3+
* bug fixing
4+
* add ability to customise view authentication handler
5+
6+
17
1.5.2
28
-----
39
* bug fixing

src/admin_extra_buttons/buttons.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ def enabled(self):
7676
try:
7777
return self._enabled(self)
7878
except Exception: # pragma: no cover
79-
raise
8079
return False
8180

8281
return self._enabled

src/admin_extra_buttons/handlers.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,25 @@ def __call__(self, model_admin, request, *args, **kwargs):
5555

5656

5757
class ViewHandler(BaseExtraHandler):
58-
def __init__(self, func, login_required=True, http_basic_auth=False, **kwargs):
58+
def __init__(self, func, login_required=True, http_basic_auth=False, http_auth_handler=None, **kwargs):
5959
self.login_required = login_required
60-
self.http_basic_auth = http_basic_auth
60+
if http_auth_handler:
61+
if http_basic_auth:
62+
raise ValueError("'http_basic_auth' and 'http_auth_handler' are mutually exclusive")
63+
self.http_auth_handler = http_auth_handler
64+
else:
65+
self.http_basic_auth = http_basic_auth
66+
self.http_auth_handler = handle_basic_auth
6167
super().__init__(func,
68+
http_auth_handler=http_auth_handler,
6269
http_basic_auth=http_basic_auth,
6370
login_required=login_required,
6471
**kwargs)
6572

6673
def __call__(self, model_admin, request, *args, **kwargs):
6774
self.model_admin = model_admin
6875
if self.login_required and self.http_basic_auth and not request.user.is_authenticated:
69-
handle_basic_auth(request)
76+
self.http_auth_handler(request)
7077
return super().__call__(model_admin, request, *args, **kwargs)
7178

7279
@cached_property

0 commit comments

Comments
 (0)