Skip to content

Commit

Permalink
customize user regex for switch_user feature
Browse files Browse the repository at this point in the history
  • Loading branch information
votetoB committed Jun 21, 2022
1 parent a5c6b56 commit 2689b38
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions grappelli/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
# SWITCH_USER_ORIGINAL: Defines if a user is a valid target.
# Gets a user object and returns True/False.
SWITCH_USER_TARGET = getattr(settings, "GRAPPELLI_SWITCH_USER_TARGET", lambda original_user, user: user.is_staff and not user.is_superuser)
SWITCH_USER_REGEX = getattr(settings, "GRAPPELLI_SWITCH_USER_REGEX", "\d+")

# CLEAN INPUT TYPES
# Replaces input types: search, email, url, tel, number, range, date
Expand Down
5 changes: 3 additions & 2 deletions grappelli/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

from .views.related import AutocompleteLookup, M2MLookup, RelatedLookup
from .views.switch import switch_user
from .settings import SWITCH_USER_REGEX


urlpatterns = [

Expand All @@ -13,6 +15,5 @@
re_path(r'^lookup/autocomplete/$', AutocompleteLookup.as_view(), name="grp_autocomplete_lookup"),

# SWITCH USER
re_path(r'^switch/user/(?P<object_id>\d+)/$', switch_user, name="grp_switch_user"),

re_path(r'^switch/user/(?P<object_id>{})/$'.format(SWITCH_USER_REGEX), switch_user, name="grp_switch_user"),
]

0 comments on commit 2689b38

Please sign in to comment.