Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LOGIN page functionality #28

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/dj_tracker/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def _set_dj_tracker_settings():
"APPS_TO_EXCLUDE": (),
"IGNORE_MODULES": (),
"IGNORE_PATHS": (),
"LOGIN": False,
}
DJ_TRACKER_SETTINGS.update(getattr(settings, "DJ_TRACKER", {}))

Expand Down
17 changes: 17 additions & 0 deletions src/dj_tracker/urlpatterns.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from functools import update_wrapper


def decorate_urlpatterns(urlpatterns, decorator):
"""Decorate all the views in the passed urlpatterns list with the given decorator"""
for pattern in urlpatterns:
if hasattr(pattern, "url_patterns"):
# this is an included RegexURLResolver; recursively decorate the views
# contained in it
decorate_urlpatterns(pattern.url_patterns, decorator)

if getattr(pattern, "callback", None):
pattern.callback = update_wrapper(
decorator(pattern.callback), pattern.callback
)

return urlpatterns
5 changes: 5 additions & 0 deletions src/dj_tracker/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django.contrib.admin.views.decorators import staff_member_required
from django.urls import path, register_converter

from dj_tracker import views
from dj_tracker.constants import DJ_TRACKER_SETTINGS
from dj_tracker.urlpatterns import decorate_urlpatterns


class CacheKeyConverter:
Expand Down Expand Up @@ -36,3 +39,5 @@ def to_url(self, value):
name="query-group",
),
]
if DJ_TRACKER_SETTINGS["LOGIN"]:
url_patterns = decorate_urlpatterns(urlpatterns, staff_member_required)
Loading