Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Imports
3from superdjango.conf import SUPERDJANGO
4from superdjango.views import ViewSet
6# Exports
8__all__ = (
9 "AccountsViewSet",
10)
12# Views
15class AccountsViewSet(ViewSet):
16 """This utility class dynamically brings the various account views together.
18 .. code-block:: python
20 # main/urls.py
21 from accounts.views import AccountsViewSet
23 accounts = AccountsViewSet(passwords=True, profiles=True)
24 auth = AccountsViewSet(auth=True)
26 urlpatterns = [
27 # ...
28 url(r'^accounts/', include(accounts.urls)),
29 url(r'', include(auth.urls)),
30 # ...
31 ]
33 """
35 def __init__(self, app_name=None, namespace=None, **kwargs):
36 """Initialize the view set.
38 :param app_name: The app name.
39 :type app_name: str
41 :param namespace: The namespace in which the app will operate.
42 :type namespace: str
44 Remaining kwargs may include a true/false value to enable or disable the URLs for a specific accounts app.
45 No apps are enabled by default, which will produce no URLs. The valid keywords are:
47 - auth
48 - badges
49 - impersonation
50 - invitations
51 - locked
52 - multisso
53 - passwords
54 - profiles
55 - registrations
56 - sso
58 """
59 super().__init__(app_name=app_name, namespace=namespace)
61 self.include_auth = kwargs.pop('auth', False)
62 self.include_badges = kwargs.pop("badges", False)
63 self.include_impersonation = kwargs.pop('impersonation', False)
64 self.include_invitations = kwargs.pop('invitations', False)
65 self.include_locked = kwargs.pop('locked', False)
66 self.include_multisso = kwargs.pop('multisso', False)
67 self.include_passwords = kwargs.pop('passwords', False)
68 self.include_profiles = kwargs.pop('profiles', False)
69 self.include_registrations = kwargs.pop('registrations', False)
70 self.include_shared = kwargs.pop('shared', False)
71 self.include_sso = kwargs.pop('sso', False)
73 def get_views(self):
74 """Get the views enabled for this instance of the viewset.
76 :rtype: list
78 """
79 a = list()
81 if self.include_auth:
82 from ..auth.views import Login, LoginRedirect, Logout
84 a += [Login, LoginRedirect, Logout]
86 if self.include_badges:
87 from ..badges.views import BadgesViewSet
88 a += BadgesViewSet.views
90 if self.include_impersonation:
91 from ..impersonation.views import ImpersonationViewSet
93 a += ImpersonationViewSet.views
95 if self.include_invitations:
96 raise NotImplementedError()
97 # from ..invitations.views import InvitationsViewSet
98 #
99 # a += InvitationsViewSet.views
101 if self.include_locked:
102 from ..locked.views import LockedViewSet
104 a += LockedViewSet.views
106 if self.include_multisso:
107 raise NotImplementedError()
109 if self.include_passwords:
110 from ..passwords.views import PasswordsViewSet
112 a += PasswordsViewSet.views
114 if self.include_profiles:
115 from ..profiles.views import ProfileViewSet
117 a += ProfileViewSet.views
119 if self.include_registrations:
120 if SUPERDJANGO.REGISTRATION_APPROVAL_REQUIRED:
121 from ..registrations.views.approval import RegistrationViewSet
122 elif SUPERDJANGO.REGISTRATION_CONFIRMATION_REQUIRED:
123 from ..registrations.views.confirmation import RegistrationViewSet
124 else:
125 from .registrations.views.simple import RegistrationViewSet
127 a += RegistrationViewSet.views
129 if self.include_sso:
130 raise NotImplementedError()
131 # from .sso.views import SSOLogin, SSOPrompt
132 #
133 # a += [SSOLogin, SSOPrompt]
135 return a