Skip to content

Commit

Permalink
[models] Removed NotificationUser model
Browse files Browse the repository at this point in the history
Breaking Change
  • Loading branch information
pandafy committed Jul 25, 2020
1 parent 48d1057 commit e1df266
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 50 deletions.
7 changes: 0 additions & 7 deletions openwisp_notifications/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@
from openwisp_utils.admin import AlwaysHasChangedMixin

Notification = load_model('Notification')
NotificationUser = load_model('NotificationUser')
NotificationSetting = load_model('NotificationSetting')


class NotificationUserInline(AlwaysHasChangedMixin, admin.StackedInline):
model = NotificationUser
fields = ['receive', 'email']


@admin.register(NotificationSetting)
class NotificationSettingAdmin(
NotificationSettingAdminMixin, admin.ModelAdmin,
Expand Down Expand Up @@ -43,5 +37,4 @@ class NotificationSettingInline(
extra = 0


UserAdmin.inlines.insert(len(UserAdmin.inlines) - 1, NotificationUserInline)
UserAdmin.inlines.insert(len(UserAdmin.inlines) - 1, NotificationSettingInline)
27 changes: 1 addition & 26 deletions openwisp_notifications/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from openwisp_notifications.utils import NotificationException, _get_object_link
from swapper import get_model_name

from openwisp_utils.base import TimeStampedEditableModel, UUIDModel
from openwisp_utils.base import UUIDModel

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -146,31 +146,6 @@ def target(self):
return self._related_object('target')


class AbstractNotificationUser(TimeStampedEditableModel):
_RECEIVE_HELP = (
'note: non-superadmin users receive '
'notifications only for organizations '
'of which they are member of.'
)
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
receive = models.BooleanField(
_('receive notifications'), default=True, help_text=_(_RECEIVE_HELP)
)
email = models.BooleanField(
_('email notifications'), default=True, help_text=_(_RECEIVE_HELP)
)

class Meta:
abstract = True
verbose_name = _('user notification settings')
verbose_name_plural = verbose_name

def save(self, *args, **kwargs):
if not self.receive:
self.email = self.receive
return super(AbstractNotificationUser, self).save(*args, **kwargs)


class AbstractNotificationSetting(UUIDModel):
_RECEIVE_HELP = (
'Note: Non-superadmin users receive '
Expand Down
1 change: 0 additions & 1 deletion openwisp_notifications/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
EXTRA_DATA = app_settings.get_config()['USE_JSONFIELD']

Notification = load_model('Notification')
NotificationUser = load_model('NotificationUser')
NotificationSetting = load_model('NotificationSetting')

OrganizationUser = swapper_load_model('openwisp_users', 'OrganizationUser')
Expand Down
14 changes: 14 additions & 0 deletions openwisp_notifications/migrations/0005_delete_notificationuser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 3.0.8 on 2020-07-24 23:56

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('openwisp_notifications', '0004_notificationsetting'),
]

operations = [
migrations.DeleteModel(name='NotificationUser',),
]
7 changes: 0 additions & 7 deletions openwisp_notifications/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from openwisp_notifications.base.models import (
AbstractNotification,
AbstractNotificationSetting,
AbstractNotificationUser,
)
from swapper import swappable_setting

Expand All @@ -13,12 +12,6 @@ class Meta(AbstractNotification.Meta):
swappable = swappable_setting('openwisp_notifications', 'Notification')


class NotificationUser(AbstractNotificationUser):
class Meta(AbstractNotificationUser.Meta):
abstract = False
swappable = swappable_setting('openwisp_notifications', 'NotificationUser')


class NotificationSetting(AbstractNotificationSetting):
class Meta(AbstractNotificationSetting.Meta):
abstract = False
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generated by Django 3.0.8 on 2020-07-24 23:48

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('sample_notifications', '0003_notificationsetting'),
]

operations = [
migrations.DeleteModel(name='NotificationUser',),
]
6 changes: 0 additions & 6 deletions tests/openwisp2/sample_notifications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from django.db import models
from openwisp_notifications.base.models import (
AbstractNotification,
AbstractNotificationUser,
AbstractNotificationSetting,
)

Expand Down Expand Up @@ -30,11 +29,6 @@ class Meta(AbstractNotification.Meta):
app_label = 'sample_notifications'


class NotificationUser(DetailsModel, AbstractNotificationUser):
class Meta(AbstractNotificationUser.Meta):
abstract = False


class NotificationSetting(DetailsModel, AbstractNotificationSetting):
class Meta(AbstractNotificationSetting.Meta):
abstract = False
Expand Down
3 changes: 0 additions & 3 deletions tests/openwisp2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@
EXTENDED_APPS.append('openwisp_notifications')
INSTALLED_APPS.append('openwisp2.sample_notifications')
OPENWISP_NOTIFICATIONS_NOTIFICATION_MODEL = 'sample_notifications.Notification'
OPENWISP_NOTIFICATIONS_NOTIFICATIONUSER_MODEL = (
'sample_notifications.NotificationUser'
)
OPENWISP_NOTIFICATIONS_NOTIFICATIONSETTING_MODEL = (
'sample_notifications.NotificationSetting'
)
Expand Down

0 comments on commit e1df266

Please sign in to comment.