Browse Source

DRY: use channel.get_kind_display()

pull/114/merge
Pēteris Caune 8 years ago
parent
commit
d739d8ff62
3 changed files with 15 additions and 37 deletions
  1. +3
    -23
      hc/api/admin.py
  2. +11
    -2
      hc/api/tests/test_admin.py
  3. +1
    -12
      templates/front/channels.html

+ 3
- 23
hc/api/admin.py View File

@ -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":
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:
if 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


+ 11
- 2
hc/api/tests/test_admin.py View File

@ -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="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
ch = Channel(user=self.alice, kind="pushbullet", value="test-token")
ch.save()
Channel.objects.create(user=self.alice, kind="pushbullet",
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="[email protected]", password="password")
Channel.objects.create(user=self.alice, kind="email",
value="[email protected]")
r = self.client.get("/admin/api/channel/")
self.assertContains(r, "Email <i>(unverified)</i>")

+ 1
- 12
templates/front/channels.html View File

@ -26,18 +26,7 @@
</tr> </tr>
{% for ch in channels %} {% for ch in channels %}
<tr class="channel-row"> <tr class="channel-row">
<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>{{ ch.get_kind_display }}</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…
Cancel
Save