Rafał Pitoń 10 years ago
parent
commit
dcad40c912

+ 3 - 3
misago/notifications/api.py

@@ -52,7 +52,7 @@ def read_user_notification(user, trigger, atomic=True):
 
 def _real_read_user_notification(user, trigger):
     trigger_hash = hash_trigger(trigger)
-    update_qs = user.notifications.filter(is_new=True)
+    update_qs = user.misago_notifications.filter(is_new=True)
     update_qs = update_qs.filter(trigger=trigger_hash)
     updated = update_qs.update(is_new=False)
 
@@ -70,12 +70,12 @@ def read_all_user_alerts(user):
     user.new_notifications = 0
     locked_user.new_notifications = 0
     locked_user.save(update_fields=['new_notifications'])
-    locked_user.notifications.update(is_new=False)
+    locked_user.misago_notifications.update(is_new=False)
 
 
 def assert_real_new_notifications_count(user):
     if user.new_notifications:
-        real_new_count = user.notifications.filter(is_new=True).count()
+        real_new_count = user.misago_notifications.filter(is_new=True).count()
         if real_new_count != user.new_notifications:
             user.new_notifications = real_new_count
             user.save(update_fields=['new_notifications'])

+ 0 - 0
misago/notifications/middleware.py


+ 2 - 2
misago/notifications/migrations/0001_initial.py

@@ -25,8 +25,8 @@ class Migration(migrations.Migration):
                 ('url', models.TextField()),
                 ('sender_username', models.CharField(max_length=255, null=True, blank=True)),
                 ('sender_slug', models.CharField(max_length=255, null=True, blank=True)),
-                ('sender', models.ForeignKey(related_name=b'notifications_by', on_delete=django.db.models.deletion.SET_NULL, blank=True, to=settings.AUTH_USER_MODEL, null=True)),
-                ('user', models.ForeignKey(related_name=b'notifications', to=settings.AUTH_USER_MODEL)),
+                ('sender', models.ForeignKey(related_name=b'misago_notifications_by', on_delete=django.db.models.deletion.SET_NULL, blank=True, to=settings.AUTH_USER_MODEL, null=True)),
+                ('user', models.ForeignKey(related_name=b'misago_notifications', to=settings.AUTH_USER_MODEL)),
             ],
             options={
             },

+ 2 - 2
misago/notifications/models.py

@@ -5,7 +5,7 @@ from django.utils import timezone
 
 class Notification(models.Model):
     user = models.ForeignKey(settings.AUTH_USER_MODEL,
-                             related_name='notifications')
+                             related_name='misago_notifications')
     is_new = models.BooleanField(default=True)
     date = models.DateTimeField(default=timezone.now, db_index=True)
     trigger = models.CharField(max_length=8)
@@ -13,7 +13,7 @@ class Notification(models.Model):
     url = models.TextField()
     sender = models.ForeignKey(settings.AUTH_USER_MODEL,
                                on_delete=models.SET_NULL,
-                               related_name='notifications_by',
+                               related_name='misago_notifications_by',
                                blank=True, null=True)
     sender_username = models.CharField(max_length=255, blank=True, null=True)
     sender_slug = models.CharField(max_length=255, blank=True, null=True)

+ 6 - 6
misago/notifications/tests/test_api.py

@@ -38,8 +38,8 @@ class NotificationsAPITests(TestCase):
         api.read_user_notification(self.test_user, "test")
 
         self.assertEqual(self.test_user.new_notifications, 0)
-        notifications_qs = self.test_user.notifications.filter(is_new=True)
-        self.assertEqual(notifications_qs.count(), 0)
+        queryset = self.test_user.misago_notifications.filter(is_new=True)
+        self.assertEqual(queryset.count(), 0)
 
     def test_read_all_user_alerts(self):
         """read_all_user_alerts marks user notifications as read"""
@@ -54,8 +54,8 @@ class NotificationsAPITests(TestCase):
         api.read_all_user_alerts(self.test_user)
         self.assertEqual(self.test_user.new_notifications, 0)
 
-        notifications_qs = self.test_user.notifications.filter(is_new=True)
-        self.assertEqual(notifications_qs.count(), 0)
+        queryset = self.test_user.misago_notifications.filter(is_new=True)
+        self.assertEqual(queryset.count(), 0)
 
     def test_assert_real_new_notifications_count(self):
         """assert_real_new_notifications_count syncs user notifications"""
@@ -74,8 +74,8 @@ class NotificationsAPITests(TestCase):
         self.reload_test_user()
         self.assertEqual(self.test_user.new_notifications, 42)
 
-        notifications_qs = self.test_user.notifications.filter(is_new=True)
-        self.assertEqual(notifications_qs.count(), 0)
+        queryset = self.test_user.misago_notifications.filter(is_new=True)
+        self.assertEqual(queryset.count(), 0)
 
         api.assert_real_new_notifications_count(self.test_user)
         self.reload_test_user()

+ 2 - 2
misago/notifications/tests/test_views.py

@@ -63,7 +63,7 @@ class NotificationViewsTests(AuthenticatedUserTestCase):
         self.reload_user()
         self.assertEqual(self.user.new_notifications, 2)
 
-        notification = self.user.notifications.get(id=notification.pk)
+        notification = self.user.misago_notifications.get(id=notification.pk)
         self.assertFalse(notification.is_new)
 
     def test_read_one_ajax(self):
@@ -83,7 +83,7 @@ class NotificationViewsTests(AuthenticatedUserTestCase):
         self.reload_user()
         self.assertEqual(self.user.new_notifications, 2)
 
-        notification = self.user.notifications.get(id=notification.pk)
+        notification = self.user.misago_notifications.get(id=notification.pk)
         self.assertFalse(notification.is_new)
 
     def test_read_all(self):

+ 5 - 5
misago/notifications/views.py

@@ -32,8 +32,8 @@ def notifications(request):
 
 def dropdown(request):
     template = render(request, 'misago/notifications/dropdown.html', {
-        'notifications_count': request.user.notifications.count(),
-        'items': request.user.notifications.order_by('-id')[:15],
+        'notifications_count': request.user.misago_notifications.count(),
+        'items': request.user.misago_notifications.order_by('-id')[:15],
     })
 
     return JsonResponse({
@@ -45,8 +45,8 @@ def dropdown(request):
 
 def full_page(request):
     return render(request, 'misago/notifications/full.html', {
-        'notifications_count': request.user.notifications.count(),
-        'items': request.user.notifications.order_by('-id'),
+        'notifications_count': request.user.misago_notifications.count(),
+        'items': request.user.misago_notifications.order_by('-id'),
     })
 
 
@@ -59,7 +59,7 @@ def read_all(request):
 
 def read_notification(request):
     try:
-        queryset = request.user.notifications
+        queryset = request.user.misago_notifications
         notification = queryset.get(id=request.POST['notification'])
 
         if notification.is_new: