This repository has been archived by the owner on Jan 24, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow patching/unpatching admin at any time
- Loading branch information
Showing
7 changed files
with
45 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django.conf import settings | ||
from django.contrib.admin import AdminSite | ||
from django.shortcuts import redirect | ||
|
||
from .utils import monkeypatch_method | ||
|
||
|
||
def patch_admin(): | ||
@monkeypatch_method(AdminSite) | ||
def login(self, request, extra_context=None): | ||
""" | ||
Redirects to the site login for the given HttpRequest | ||
""" | ||
return redirect(str(settings.LOGIN_URL)) | ||
|
||
|
||
def unpatch_admin(): | ||
setattr(AdminSite, 'login', original_login) | ||
|
||
|
||
original_login = AdminSite.login | ||
if getattr(settings, 'FL_PATCH_ADMIN', True): | ||
patch_admin() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
from django.conf import settings | ||
from django.contrib.admin import sites | ||
import warnings | ||
|
||
#monkey-patch admin login | ||
from django.shortcuts import redirect | ||
|
||
|
||
def redirect_admin_login(self, request): | ||
return redirect(settings.LOGIN_URL) | ||
|
||
sites.AdminSite.login = redirect_admin_login | ||
warnings.warn("federeated_login.patch_admin has been deprecated in favor of a " | ||
"setting called FL_PATCH_ADMIN, which is set to auto-patch. " | ||
"Please update your settings accordingly.", DeprecationWarning) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# from http://mail.python.org/pipermail/python-dev/2008-January/076194.html | ||
def monkeypatch_method(cls): | ||
def decorator(func): | ||
setattr(cls, func.__name__, func) | ||
return func | ||
return decorator |