core/sources(minor): refactor Source's property
This commit is contained in:
@ -152,14 +152,10 @@ class Source(PolicyModel):
|
||||
objects = InheritanceManager()
|
||||
|
||||
@property
|
||||
def is_link(self):
|
||||
"""Return true if Source should get a link on the login page"""
|
||||
return False
|
||||
|
||||
@property
|
||||
def get_login_button(self):
|
||||
"""Return a tuple of URL, Icon name and Name"""
|
||||
raise NotImplementedError
|
||||
def login_button(self):
|
||||
"""Return a tuple of URL, Icon name and Name
|
||||
if Source should get a link on the login page"""
|
||||
return None
|
||||
|
||||
@property
|
||||
def additional_info(self):
|
||||
|
||||
@ -46,9 +46,11 @@ class LoginView(UserPassesTestMixin, FormView):
|
||||
kwargs['show_sign_up_notice'] = CONFIG.y('passbook.sign_up.enabled')
|
||||
kwargs['sources'] = []
|
||||
sources = Source.objects.filter(enabled=True).select_subclasses()
|
||||
if any(source.is_link for source in sources):
|
||||
for source in sources:
|
||||
kwargs['sources'].append(source.get_login_button)
|
||||
for source in sources:
|
||||
login_button = source.login_button
|
||||
if login_button:
|
||||
kwargs['sources'].append(login_button)
|
||||
if kwargs['sources']:
|
||||
self.template_name = 'login/with_sources.html'
|
||||
return super().get_context_data(**kwargs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user