Hide keyboard shortcuts

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 

2 

3from superdjango.conf import SUPERDJANGO 

4from superdjango.views import ViewSet 

5 

6# Exports 

7 

8__all__ = ( 

9 "AccountsViewSet", 

10) 

11 

12# Views 

13 

14 

15class AccountsViewSet(ViewSet): 

16 """This utility class dynamically brings the various account views together. 

17 

18 .. code-block:: python 

19 

20 # main/urls.py 

21 from accounts.views import AccountsViewSet 

22 

23 accounts = AccountsViewSet(passwords=True, profiles=True) 

24 auth = AccountsViewSet(auth=True) 

25 

26 urlpatterns = [ 

27 # ... 

28 url(r'^accounts/', include(accounts.urls)), 

29 url(r'', include(auth.urls)), 

30 # ... 

31 ] 

32 

33 """ 

34 

35 def __init__(self, app_name=None, namespace=None, **kwargs): 

36 """Initialize the view set. 

37 

38 :param app_name: The app name. 

39 :type app_name: str 

40 

41 :param namespace: The namespace in which the app will operate. 

42 :type namespace: str 

43 

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: 

46 

47 - auth 

48 - badges 

49 - impersonation 

50 - invitations 

51 - locked 

52 - multisso 

53 - passwords 

54 - profiles 

55 - registrations 

56 - sso 

57 

58 """ 

59 super().__init__(app_name=app_name, namespace=namespace) 

60 

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) 

72 

73 def get_views(self): 

74 """Get the views enabled for this instance of the viewset. 

75 

76 :rtype: list 

77 

78 """ 

79 a = list() 

80 

81 if self.include_auth: 

82 from ..auth.views import Login, LoginRedirect, Logout 

83 

84 a += [Login, LoginRedirect, Logout] 

85 

86 if self.include_badges: 

87 from ..badges.views import BadgesViewSet 

88 a += BadgesViewSet.views 

89 

90 if self.include_impersonation: 

91 from ..impersonation.views import ImpersonationViewSet 

92 

93 a += ImpersonationViewSet.views 

94 

95 if self.include_invitations: 

96 raise NotImplementedError() 

97 # from ..invitations.views import InvitationsViewSet 

98 # 

99 # a += InvitationsViewSet.views 

100 

101 if self.include_locked: 

102 from ..locked.views import LockedViewSet 

103 

104 a += LockedViewSet.views 

105 

106 if self.include_multisso: 

107 raise NotImplementedError() 

108 

109 if self.include_passwords: 

110 from ..passwords.views import PasswordsViewSet 

111 

112 a += PasswordsViewSet.views 

113 

114 if self.include_profiles: 

115 from ..profiles.views import ProfileViewSet 

116 

117 a += ProfileViewSet.views 

118 

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 

126 

127 a += RegistrationViewSet.views 

128 

129 if self.include_sso: 

130 raise NotImplementedError() 

131 # from .sso.views import SSOLogin, SSOPrompt 

132 # 

133 # a += [SSOLogin, SSOPrompt] 

134 

135 return a