# HG changeset patch # User Marcin Kuzminski # Date 2018-02-16 00:22:52 # Node ID ccf582796b72e977106b7715029c71cdef3790c7 # Parent e09d5d1bc9dceef495882eaf0ceb844693d95724 integrations: use classmethod for icon extraction for easier code readability. diff --git a/rhodecode/integrations/types/base.py b/rhodecode/integrations/types/base.py --- a/rhodecode/integrations/types/base.py +++ b/rhodecode/integrations/types/base.py @@ -26,67 +26,70 @@ class IntegrationTypeBase(object): """ Base class for IntegrationType plugins """ is_dummy = False description = '' - icon = ''' - - - - - - image/svg+xml - - - - - - - - - - -''' + + @classmethod + def icon(cls): + return ''' + + + + + + image/svg+xml + + + + + + + + + + + ''' def __init__(self, settings): """ diff --git a/rhodecode/integrations/types/email.py b/rhodecode/integrations/types/email.py --- a/rhodecode/integrations/types/email.py +++ b/rhodecode/integrations/types/email.py @@ -146,7 +146,36 @@ repo_push_template_html = Template(''' ''') -email_icon = ''' + + + +class EmailSettingsSchema(colander.Schema): + @colander.instantiate(validator=colander.Length(min=1)) + class recipients(colander.SequenceSchema): + title = _('Recipients') + description = _('Email addresses to send push events to') + widget = deform.widget.SequenceWidget(min_len=1) + + recipient = colander.SchemaNode( + colander.String(), + title=_('Email address'), + description=_('Email address'), + default='', + validator=colander.Email(), + widget=deform.widget.TextInputWidget( + placeholder='user@domain.com', + ), + ) + + +class EmailIntegrationType(IntegrationTypeBase): + key = 'email' + display_name = _('Email') + description = _('Send repo push summaries to a list of recipients via email') + + @classmethod + def icon(cls): + return ''' ''' - -class EmailSettingsSchema(colander.Schema): - @colander.instantiate(validator=colander.Length(min=1)) - class recipients(colander.SequenceSchema): - title = _('Recipients') - description = _('Email addresses to send push events to') - widget = deform.widget.SequenceWidget(min_len=1) - - recipient = colander.SchemaNode( - colander.String(), - title=_('Email address'), - description=_('Email address'), - default='', - validator=colander.Email(), - widget=deform.widget.TextInputWidget( - placeholder='user@domain.com', - ), - ) - - -class EmailIntegrationType(IntegrationTypeBase): - key = 'email' - display_name = _('Email') - description = _('Send repo push summaries to a list of recipients via email') - icon = email_icon - def settings_schema(self): schema = EmailSettingsSchema() return schema diff --git a/rhodecode/integrations/types/hipchat.py b/rhodecode/integrations/types/hipchat.py --- a/rhodecode/integrations/types/hipchat.py +++ b/rhodecode/integrations/types/hipchat.py @@ -97,7 +97,11 @@ class HipchatIntegrationType(Integration display_name = _('Hipchat') description = _('Send events such as repo pushes and pull requests to ' 'your hipchat channel.') - icon = '''''' + + @classmethod + def icon(cls): + return '''''' + valid_events = [ events.PullRequestCloseEvent, events.PullRequestMergeEvent, diff --git a/rhodecode/integrations/types/slack.py b/rhodecode/integrations/types/slack.py --- a/rhodecode/integrations/types/slack.py +++ b/rhodecode/integrations/types/slack.py @@ -92,7 +92,11 @@ class SlackIntegrationType(IntegrationTy display_name = _('Slack') description = _('Send events such as repo pushes and pull requests to ' 'your slack channel.') - icon = '''''' + + @classmethod + def icon(cls): + return '''''' + valid_events = [ events.PullRequestCloseEvent, events.PullRequestMergeEvent, diff --git a/rhodecode/integrations/types/webhook.py b/rhodecode/integrations/types/webhook.py --- a/rhodecode/integrations/types/webhook.py +++ b/rhodecode/integrations/types/webhook.py @@ -265,7 +265,10 @@ class WebhookIntegrationType(Integration key = 'webhook' display_name = _('Webhook') description = _('Post json events to a Webhook endpoint') - icon = '''''' + + @classmethod + def icon(cls): + return '''''' valid_events = [ events.PullRequestCloseEvent, diff --git a/rhodecode/templates/admin/integrations/list.mako b/rhodecode/templates/admin/integrations/list.mako --- a/rhodecode/templates/admin/integrations/list.mako +++ b/rhodecode/templates/admin/integrations/list.mako @@ -153,7 +153,7 @@ %if integration.integration_type in c.available_integrations:
- ${c.available_integrations[integration.integration_type].icon|n} + ${c.available_integrations[integration.integration_type].icon()|n}
%else: ? diff --git a/rhodecode/templates/admin/integrations/new.mako b/rhodecode/templates/admin/integrations/new.mako --- a/rhodecode/templates/admin/integrations/new.mako +++ b/rhodecode/templates/admin/integrations/new.mako @@ -56,7 +56,7 @@ <%widgets:panel>

- ${IntegrationObject.icon|n} + ${IntegrationObject.icon()|n}
${IntegrationObject.display_name}

diff --git a/rhodecode/tests/plugin.py b/rhodecode/tests/plugin.py --- a/rhodecode/tests/plugin.py +++ b/rhodecode/tests/plugin.py @@ -1706,7 +1706,10 @@ def StubIntegrationType(): key = 'test' display_name = 'Test integration type' description = 'A test integration type for testing' - icon = 'test_icon_html_image' + + @classmethod + def icon(cls): + return 'test_icon_html_image' def __init__(self, settings): super(_StubIntegrationType, self).__init__(settings)