forked from GithubBackups/healthchecks
DRY: use channel.get_kind_display()
This commit is contained in:
parent
4906a5247c
commit
d739d8ff62
@ -165,30 +165,10 @@ class ChannelsAdmin(admin.ModelAdmin):
|
|||||||
return obj.user.email if obj.user else None
|
return obj.user.email if obj.user else None
|
||||||
|
|
||||||
def formatted_kind(self, obj):
|
def formatted_kind(self, obj):
|
||||||
if obj.kind == "pd":
|
if obj.kind == "email" and not obj.email_verified:
|
||||||
return "PagerDuty"
|
|
||||||
elif obj.kind == "victorops":
|
|
||||||
return "VictorOps"
|
|
||||||
elif obj.kind == "pushbullet":
|
|
||||||
return "Pushbullet"
|
|
||||||
elif obj.kind == "discord":
|
|
||||||
return "Discord"
|
|
||||||
elif obj.kind == "po":
|
|
||||||
return "Pushover"
|
|
||||||
elif obj.kind == "webhook":
|
|
||||||
return "Webhook"
|
|
||||||
elif obj.kind == "slack":
|
|
||||||
return "Slack"
|
|
||||||
elif obj.kind == "hipchat":
|
|
||||||
return "HipChat"
|
|
||||||
elif obj.kind == "opsgenie":
|
|
||||||
return "OpsGenie"
|
|
||||||
elif obj.kind == "email" and obj.email_verified:
|
|
||||||
return "Email"
|
|
||||||
elif obj.kind == "email" and not obj.email_verified:
|
|
||||||
return "Email <i>(unverified)</i>"
|
return "Email <i>(unverified)</i>"
|
||||||
else:
|
|
||||||
raise NotImplementedError("Bad channel kind: %s" % obj.kind)
|
return obj.get_kind_display()
|
||||||
|
|
||||||
formatted_kind.short_description = "Kind"
|
formatted_kind.short_description = "Kind"
|
||||||
formatted_kind.allow_tags = True
|
formatted_kind.allow_tags = True
|
||||||
|
@ -15,8 +15,17 @@ class ApiAdminTestCase(BaseTestCase):
|
|||||||
def test_it_shows_channel_list_with_pushbullet(self):
|
def test_it_shows_channel_list_with_pushbullet(self):
|
||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
|
|
||||||
ch = Channel(user=self.alice, kind="pushbullet", value="test-token")
|
Channel.objects.create(user=self.alice, kind="pushbullet",
|
||||||
ch.save()
|
value="test-token")
|
||||||
|
|
||||||
r = self.client.get("/admin/api/channel/")
|
r = self.client.get("/admin/api/channel/")
|
||||||
self.assertContains(r, "Pushbullet")
|
self.assertContains(r, "Pushbullet")
|
||||||
|
|
||||||
|
def test_it_shows_channel_list_with_unverified_email(self):
|
||||||
|
self.client.login(username="alice@example.org", password="password")
|
||||||
|
|
||||||
|
Channel.objects.create(user=self.alice, kind="email",
|
||||||
|
value="foo@example.org")
|
||||||
|
|
||||||
|
r = self.client.get("/admin/api/channel/")
|
||||||
|
self.assertContains(r, "Email <i>(unverified)</i>")
|
||||||
|
@ -26,18 +26,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{% for ch in channels %}
|
{% for ch in channels %}
|
||||||
<tr class="channel-row">
|
<tr class="channel-row">
|
||||||
<td>
|
<td>{{ ch.get_kind_display }}</td>
|
||||||
{% if ch.kind == "email" %} Email
|
|
||||||
{% elif ch.kind == "webhook" %} Webhook
|
|
||||||
{% elif ch.kind == "slack" %} Slack
|
|
||||||
{% elif ch.kind == "hipchat" %} HipChat
|
|
||||||
{% elif ch.kind == "pd" %} PagerDuty
|
|
||||||
{% elif ch.kind == "po" %} Pushover
|
|
||||||
{% elif ch.kind == "victorops" %} VictorOps
|
|
||||||
{% elif ch.kind == "pushbullet" %} Pushbullet
|
|
||||||
{% elif ch.kind == "opsgenie" %} OpsGenie
|
|
||||||
{% elif ch.kind == "discord" %} Discord {% endif %}
|
|
||||||
</td>
|
|
||||||
<td class="value-cell">
|
<td class="value-cell">
|
||||||
{% if ch.kind == "email" %}
|
{% if ch.kind == "email" %}
|
||||||
<span class="preposition">to</span>
|
<span class="preposition">to</span>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user