forked from mmmaly/chcemvediet
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2f94d1b
commit d74ab84
Showing
3 changed files
with
77 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
from django.contrib.auth.backends import ModelBackend | ||
from django.core.urlresolvers import resolve | ||
from django.core.urlresolvers import resolve, Resolver404 | ||
|
||
from poleno.utils.http import get_request | ||
|
||
|
||
class AdminLoginAsBackend(ModelBackend): | ||
|
||
def is_admin_path(self, path): | ||
return resolve(path).func.__module__ in [ | ||
u'django.contrib.admin.options', | ||
u'django.contrib.admin.sites', | ||
u'adminplus.sites', | ||
u'chcemvediet.apps.accounts.admin', | ||
] | ||
return resolve(path).namespace == u'admin' | ||
|
||
def get_user(self, user_id): | ||
request = get_request() | ||
admin_login_as = request.session.get(u'admin_login_as') | ||
user = super(AdminLoginAsBackend, self).get_user(user_id) | ||
admin_login_as_user = super(AdminLoginAsBackend, self).get_user(admin_login_as) | ||
if request is None: | ||
return user | ||
try: | ||
resolve(request.path) | ||
except Resolver404: | ||
return user | ||
admin_login_as = request.session.get(u'admin_login_as') | ||
if user and user.is_staff and not self.is_admin_path(request.path) and admin_login_as: | ||
return admin_login_as_user | ||
return super(AdminLoginAsBackend, self).get_user(admin_login_as) or user | ||
return user |
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