Source code for superdjango.contrib.accounts.views.viewsets

# Imports

from superdjango.conf import SUPERDJANGO
from superdjango.views import ViewSet

# Exports

__all__ = (
    "AccountsViewSet",
)

# Views


[docs]class AccountsViewSet(ViewSet): """This utility class dynamically brings the various account views together. .. code-block:: python # main/urls.py from accounts.views import AccountsViewSet accounts = AccountsViewSet(passwords=True, profiles=True) auth = AccountsViewSet(auth=True) urlpatterns = [ # ... url(r'^accounts/', include(accounts.urls)), url(r'', include(auth.urls)), # ... ] """
[docs] def __init__(self, app_name=None, namespace=None, **kwargs): """Initialize the view set. :param app_name: The app name. :type app_name: str :param namespace: The namespace in which the app will operate. :type namespace: str Remaining kwargs may include a true/false value to enable or disable the URLs for a specific accounts app. No apps are enabled by default, which will produce no URLs. The valid keywords are: - auth - badges - impersonation - invitations - locked - multisso - passwords - profiles - registrations - sso """ super().__init__(app_name=app_name, namespace=namespace) self.include_auth = kwargs.pop('auth', False) self.include_badges = kwargs.pop("badges", False) self.include_impersonation = kwargs.pop('impersonation', False) self.include_invitations = kwargs.pop('invitations', False) self.include_locked = kwargs.pop('locked', False) self.include_multisso = kwargs.pop('multisso', False) self.include_passwords = kwargs.pop('passwords', False) self.include_profiles = kwargs.pop('profiles', False) self.include_registrations = kwargs.pop('registrations', False) self.include_shared = kwargs.pop('shared', False) self.include_sso = kwargs.pop('sso', False)
[docs] def get_views(self): """Get the views enabled for this instance of the viewset. :rtype: list """ a = list() if self.include_auth: from ..auth.views import Login, LoginRedirect, Logout a += [Login, LoginRedirect, Logout] if self.include_badges: from ..badges.views import BadgesViewSet a += BadgesViewSet.views if self.include_impersonation: from ..impersonation.views import ImpersonationViewSet a += ImpersonationViewSet.views if self.include_invitations: raise NotImplementedError() # from ..invitations.views import InvitationsViewSet # # a += InvitationsViewSet.views if self.include_locked: from ..locked.views import LockedViewSet a += LockedViewSet.views if self.include_multisso: raise NotImplementedError() if self.include_passwords: from ..passwords.views import PasswordsViewSet a += PasswordsViewSet.views if self.include_profiles: from ..profiles.views import ProfileViewSet a += ProfileViewSet.views if self.include_registrations: if SUPERDJANGO.REGISTRATION_APPROVAL_REQUIRED: from ..registrations.views.approval import RegistrationViewSet elif SUPERDJANGO.REGISTRATION_CONFIRMATION_REQUIRED: from ..registrations.views.confirmation import RegistrationViewSet else: from .registrations.views.simple import RegistrationViewSet a += RegistrationViewSet.views if self.include_sso: raise NotImplementedError() # from .sso.views import SSOLogin, SSOPrompt # # a += [SSOLogin, SSOPrompt] return a