From 72bac75fbdae836005b3652868d2c91231f3e9c3 Mon Sep 17 00:00:00 2001 From: Alexandre Iooss Date: Mon, 21 Sep 2020 12:15:40 +0200 Subject: [PATCH] Add Django OAuth toolkit admin --- note_kfet/admin.py | 8 ++++++++ note_kfet/settings/base.py | 4 +++- note_kfet/urls.py | 8 +++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/note_kfet/admin.py b/note_kfet/admin.py index 1fa228fe..fa192b57 100644 --- a/note_kfet/admin.py +++ b/note_kfet/admin.py @@ -26,6 +26,14 @@ admin_site = StrongAdminSite() admin_site.register(Site, SiteAdmin) # Add external apps model +if "oauth2_provider" in settings.INSTALLED_APPS: + from oauth2_provider.admin import Application, ApplicationAdmin, Grant, \ + GrantAdmin, AccessToken, AccessTokenAdmin, RefreshToken, RefreshTokenAdmin + admin_site.register(Application, ApplicationAdmin) + admin_site.register(Grant, GrantAdmin) + admin_site.register(AccessToken, AccessTokenAdmin) + admin_site.register(RefreshToken, RefreshTokenAdmin) + if "django_htcpcp_tea" in settings.INSTALLED_APPS: from django_htcpcp_tea.admin import * from django_htcpcp_tea.models import * diff --git a/note_kfet/settings/base.py b/note_kfet/settings/base.py index 3c2cd4f9..f393cab1 100644 --- a/note_kfet/settings/base.py +++ b/note_kfet/settings/base.py @@ -38,7 +38,9 @@ INSTALLED_APPS = [ 'oauth2_provider', # Django contrib - 'django.contrib.admin', + # We do not import Django Admin directly to disable autodiscover. + # Autodiscover does not work with custom admin sites. + 'django.contrib.admin.apps.SimpleAdminConfig', 'django.contrib.admindocs', 'django.contrib.auth', 'django.contrib.contenttypes', diff --git a/note_kfet/urls.py b/note_kfet/urls.py index 6049bfde..d9e51b63 100644 --- a/note_kfet/urls.py +++ b/note_kfet/urls.py @@ -32,9 +32,6 @@ urlpatterns = [ path('api/', include('api.urls')), path('permission/', include('permission.urls')), - # OAuth2 provider - path('o/', include('oauth2_provider.urls', namespace='oauth2_provider')), - # Make coffee path('coffee/', include('django_htcpcp_tea.urls')), ] @@ -43,6 +40,11 @@ urlpatterns = [ if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) +if "oauth2_provider" in settings.INSTALLED_APPS: + # OAuth2 provider + urlpatterns.append( + path('o/', include('oauth2_provider.urls', namespace='oauth2_provider')) + ) if "debug_toolbar" in settings.INSTALLED_APPS: import debug_toolbar