Skip to content

Commit a6cc270

Browse files
committed
fix issue with subscriptions without types
1 parent 5ef1089 commit a6cc270

2 files changed

Lines changed: 12 additions & 7 deletions

File tree

osf/admin.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,17 @@ class Media:
325325
js = ['admin/notification_subscription.js']
326326

327327
def preview_button(self, obj):
328-
url = reverse(
329-
'admin:notificationtype_preview',
330-
args=[obj.notification_type.id]
331-
)
328+
if obj.notification_type:
329+
url = reverse(
330+
'admin:notificationtype_preview',
331+
args=[obj.notification_type.id]
332+
)
333+
return format_html(
334+
'<a class="button" target="_blank" href="{}">Preview</a>',
335+
url
336+
)
332337
return format_html(
333-
'<a class="button" target="_blank" href="{}">Preview</a>',
334-
url
338+
'<a class="button">Missing Notification Type!</a>',
335339
)
336340

337341
def get_urls(self):

osf/models/notification_subscription.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ def clean(self):
4949
raise ValidationError(f'{self.message_frequency!r} is not allowed for {self.notification_type.name!r}.')
5050

5151
def __str__(self) -> str:
52-
return f'<{self.user} via {self.subscribed_object} subscribes to {self.notification_type.name} ({self.message_frequency})>'
52+
return (f'<{self.user} via {self.subscribed_object} subscribes to '
53+
f'{getattr(self.notification_type, 'name', 'MISSING')} ({self.message_frequency})>')
5354

5455
class Meta:
5556
verbose_name = 'Notification Subscription'

0 commit comments

Comments
 (0)