django-allauth-cas/allauth_cas/urls.py

50 lines
1.6 KiB
Python
Raw Permalink Normal View History

from django.urls import include, path, re_path
2017-12-29 18:19:01 +01:00
from django.utils.module_loading import import_string
2017-07-25 18:31:42 +02:00
def default_urlpatterns(provider):
package = provider.get_package()
2017-12-29 18:19:01 +01:00
try:
login_view = import_string(package + ".views.login")
2017-12-29 18:19:01 +01:00
except ImportError:
raise ImportError(
"The login view for the '{id}' provider is lacking from the "
"'views' module of its app.\n"
"You may want to add:\n"
"from allauth_cas.views import CASLoginView\n\n"
"login = CASLoginView.adapter_view(<LocalCASAdapter>)".format(
id=provider.id
)
2017-12-29 18:19:01 +01:00
)
try:
callback_view = import_string(package + ".views.callback")
2017-12-29 18:19:01 +01:00
except ImportError:
raise ImportError(
"The callback view for the '{id}' provider is lacking from the "
"'views' module of its app.\n"
"You may want to add:\n"
"from allauth_cas.views import CASCallbackView\n\n"
"callback = CASCallbackView.adapter_view(<LocalCASAdapter>)".format(
id=provider.id
)
2017-12-29 18:19:01 +01:00
)
try:
logout_view = import_string(package + ".views.logout")
2017-12-29 18:19:01 +01:00
except ImportError:
logout_view = None
2017-07-25 18:31:42 +02:00
urlpatterns = [
path("login/", login_view, name=provider.id + "_login"),
path("login/callback/", callback_view, name=provider.id + "_callback"),
2017-07-25 18:31:42 +02:00
]
2017-12-29 18:19:01 +01:00
if logout_view is not None:
urlpatterns += [
path("logout/", logout_view, name=provider.id + "_logout"),
2017-12-29 18:19:01 +01:00
]
return [re_path("^" + provider.get_slug() + "/", include(urlpatterns))]