core/sources(minor): refactor Source's property

This commit is contained in:
Langhammer, Jens 2019-10-13 16:47:05 +02:00
parent 1cb6b5e984
commit 2ff1635696
4 changed files with 16 additions and 18 deletions

View file

@ -152,14 +152,10 @@ class Source(PolicyModel):
objects = InheritanceManager() objects = InheritanceManager()
@property @property
def is_link(self): def login_button(self):
"""Return true if Source should get a link on the login page""" """Return a tuple of URL, Icon name and Name
return False if Source should get a link on the login page"""
return None
@property
def get_login_button(self):
"""Return a tuple of URL, Icon name and Name"""
raise NotImplementedError
@property @property
def additional_info(self): def additional_info(self):

View file

@ -46,9 +46,11 @@ class LoginView(UserPassesTestMixin, FormView):
kwargs['show_sign_up_notice'] = CONFIG.y('passbook.sign_up.enabled') kwargs['show_sign_up_notice'] = CONFIG.y('passbook.sign_up.enabled')
kwargs['sources'] = [] kwargs['sources'] = []
sources = Source.objects.filter(enabled=True).select_subclasses() sources = Source.objects.filter(enabled=True).select_subclasses()
if any(source.is_link for source in sources): for source in sources:
for source in sources: login_button = source.login_button
kwargs['sources'].append(source.get_login_button) if login_button:
kwargs['sources'].append(login_button)
if kwargs['sources']:
self.template_name = 'login/with_sources.html' self.template_name = 'login/with_sources.html'
return super().get_context_data(**kwargs) return super().get_context_data(**kwargs)

View file

@ -32,11 +32,15 @@ class LDAPSource(Source):
sync_parent_group = models.ForeignKey(Group, blank=True, null=True, sync_parent_group = models.ForeignKey(Group, blank=True, null=True,
default=None, on_delete=models.SET_DEFAULT) default=None, on_delete=models.SET_DEFAULT)
# This field is written to by the sync_* tasks
# displayed by additional_info
status = models.TextField(default="")
form = 'passbook.sources.ldap.forms.LDAPSourceForm' form = 'passbook.sources.ldap.forms.LDAPSourceForm'
@property @property
def get_login_button(self): def additional_info(self):
raise NotImplementedError() return self.status
class Meta: class Meta:

View file

@ -22,11 +22,7 @@ class OAuthSource(Source):
form = 'passbook.sources.oauth.forms.OAuthSourceForm' form = 'passbook.sources.oauth.forms.OAuthSourceForm'
@property @property
def is_link(self): def login_button(self):
return True
@property
def get_login_button(self):
url = reverse_lazy('passbook_sources_oauth:oauth-client-login', url = reverse_lazy('passbook_sources_oauth:oauth-client-login',
kwargs={'source_slug': self.slug}) kwargs={'source_slug': self.slug})
return url, self.provider_type, self.name return url, self.provider_type, self.name