diff --git a/openwisp_notifications/base/models.py b/openwisp_notifications/base/models.py index bbcf3793..f0a6c30b 100644 --- a/openwisp_notifications/base/models.py +++ b/openwisp_notifications/base/models.py @@ -20,7 +20,7 @@ from openwisp_notifications import settings as app_settings from openwisp_notifications.exceptions import NotificationRenderException from openwisp_notifications.types import ( - NOTIFICATION_CHOICES, + get_notification_choices, get_notification_configuration, ) from openwisp_notifications.utils import _get_absolute_url, _get_object_link @@ -31,7 +31,7 @@ class AbstractNotification(UUIDModel, BaseNotification): CACHE_KEY_PREFIX = 'ow-notifications-' - type = models.CharField(max_length=30, null=True, choices=NOTIFICATION_CHOICES) + type = models.CharField(max_length=30, null=True, choices=get_notification_choices) _actor = BaseNotification.actor _action_object = BaseNotification.action_object _target = BaseNotification.target @@ -212,7 +212,7 @@ class AbstractNotificationSetting(UUIDModel): type = models.CharField( max_length=30, null=True, - choices=NOTIFICATION_CHOICES, + choices=get_notification_choices, verbose_name='Notification Type', ) organization = models.ForeignKey( diff --git a/openwisp_notifications/tests/test_notification_setting.py b/openwisp_notifications/tests/test_notification_setting.py index 2bc8c8f4..53d1ed6d 100644 --- a/openwisp_notifications/tests/test_notification_setting.py +++ b/openwisp_notifications/tests/test_notification_setting.py @@ -65,7 +65,7 @@ def test_notification_type_registered(self): self._get_admin() self.assertEqual(queryset.count(), 1) - self.assertEquals( + self.assertEqual( queryset.first().__str__(), 'Test Notification Type - default' ) diff --git a/openwisp_notifications/types.py b/openwisp_notifications/types.py index 88a5f436..f19f8c3e 100644 --- a/openwisp_notifications/types.py +++ b/openwisp_notifications/types.py @@ -23,6 +23,15 @@ NOTIFICATION_ASSOCIATED_MODELS = set() +def get_notification_choices(): + """ + Return a list of notification choices. + This method used as a callable for 'choices' attribute in models + allowing the models to deal with the updated list. + """ + return NOTIFICATION_CHOICES + + def get_notification_configuration(notification_type): if not notification_type: return {}