-
Notifications
You must be signed in to change notification settings - Fork 395
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
149 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.contrib import admin | ||
|
||
|
||
class AbstractNotificationAdmin(admin.ModelAdmin): | ||
raw_id_fields = ('recipient',) | ||
list_display = ('recipient', 'actor', | ||
'level', 'target', 'unread', 'public') | ||
list_filter = ('level', 'unread', 'public', 'timestamp',) | ||
|
||
def get_queryset(self, request): | ||
qs = super(AbstractNotificationAdmin, self).get_queryset(request) | ||
return qs.prefetch_related('actor') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default_app_config = 'notifications.tests.sample_notifications.apps.SampleNotificationsConfig' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import swapper | ||
from django.contrib import admin | ||
from notifications.base.admin import AbstractNotificationAdmin | ||
|
||
Notification = swapper.load_model('notifications', 'Notification') | ||
|
||
|
||
@admin.register(Notification) | ||
class NotificationAdmin(AbstractNotificationAdmin): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from notifications.apps import Config as NotificationConfig | ||
|
||
|
||
class SampleNotificationsConfig(NotificationConfig): | ||
name = 'notifications.tests.sample_notifications' | ||
label = 'sample_notifications' |
48 changes: 48 additions & 0 deletions
48
notifications/tests/sample_notifications/migrations/0001_initial.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Generated by Django 3.0.5 on 2020-04-11 12:15 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
import jsonfield.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('contenttypes', '0002_remove_content_type_name'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Notification', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('level', models.CharField(choices=[('success', 'success'), ('info', 'info'), ('warning', 'warning'), ('error', 'error')], default='info', max_length=20)), | ||
('unread', models.BooleanField(db_index=True, default=True)), | ||
('actor_object_id', models.CharField(max_length=255)), | ||
('verb', models.CharField(max_length=255)), | ||
('description', models.TextField(blank=True, null=True)), | ||
('target_object_id', models.CharField(blank=True, max_length=255, null=True)), | ||
('action_object_object_id', models.CharField(blank=True, max_length=255, null=True)), | ||
('timestamp', models.DateTimeField(db_index=True, default=django.utils.timezone.now)), | ||
('public', models.BooleanField(db_index=True, default=True)), | ||
('deleted', models.BooleanField(db_index=True, default=False)), | ||
('emailed', models.BooleanField(db_index=True, default=False)), | ||
('data', jsonfield.fields.JSONField(blank=True, null=True)), | ||
('details', models.CharField(blank=True, max_length=64, null=True)), | ||
('action_object_content_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='notify_action_object', to='contenttypes.ContentType')), | ||
('actor_content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='notify_actor', to='contenttypes.ContentType')), | ||
('recipient', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='notifications', to=settings.AUTH_USER_MODEL)), | ||
('target_content_type', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='notify_target', to='contenttypes.ContentType')), | ||
], | ||
options={ | ||
'ordering': ('-timestamp',), | ||
'abstract': False, | ||
'index_together': {('recipient', 'unread')}, | ||
}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django.db import models | ||
from notifications.base.models import AbstractNotification | ||
|
||
|
||
class Notification(AbstractNotification): | ||
details = models.CharField(max_length=64, blank=True, null=True) | ||
|
||
class Meta(AbstractNotification.Meta): | ||
abstract = False |
Empty file.
1 change: 1 addition & 0 deletions
1
notifications/tests/sample_notifications/templatetags/notifications_tags.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from notifications.templatetags.notifications_tags import register |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import os | ||
from unittest import skipUnless | ||
|
||
import swapper | ||
from notifications.tests.tests import AdminTest as BaseAdminTest | ||
from notifications.tests.tests import NotificationTest as BaseNotificationTest | ||
|
||
Notification = swapper.load_model('notifications', 'Notification') | ||
|
||
|
||
@skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django-notifications models') | ||
class AdminTest(BaseAdminTest): | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
BaseAdminTest.app_name = 'sample_notifications' | ||
|
||
|
||
@skipUnless(os.environ.get('SAMPLE_APP', False), 'Running tests on standard django-notifications models') | ||
class NotificationTest(BaseNotificationTest): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters