From 5e616fc697f16ef73bffad5bcf18740a4d14e26b Mon Sep 17 00:00:00 2001 From: Calum Mackervoy Date: Thu, 13 Aug 2020 15:42:07 +0000 Subject: [PATCH] feature: notifications pagination --- djangoldp_notification/models.py | 12 ++++++++---- djangoldp_notification/views.py | 11 +++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 djangoldp_notification/views.py diff --git a/djangoldp_notification/models.py b/djangoldp_notification/models.py index e776a44..37486f5 100644 --- a/djangoldp_notification/models.py +++ b/djangoldp_notification/models.py @@ -14,6 +14,7 @@ from djangoldp.models import Model from threading import Thread from djangoldp_notification.middlewares import MODEL_MODIFICATION_USER_FIELD from djangoldp_notification.permissions import InboxPermissions, SubscriptionsPermissions +from djangoldp_notification.views import LDPNotifcationsViewSet class Notification(Model): @@ -32,6 +33,7 @@ class Notification(Model): anonymous_perms = ['add'] authenticated_perms = ['inherit'] owner_perms = ['view', 'change', 'control'] + view_set = LDPNotifcationsViewSet def __str__(self): return '{}'.format(self.type) @@ -160,7 +162,7 @@ def send_request(target, object_iri, instance, created): @receiver(post_save, sender=Notification) def send_email_on_notification(sender, instance, created, **kwargs): - if created and instance.summary and settings.JABBER_DEFAULT_HOST and instance.user.email: + if created and instance.summary and getattr(settings,'JABBER_DEFAULT_HOST',False) and instance.user.email: # get author name, and store in who try: # local author @@ -186,10 +188,12 @@ def send_email_on_notification(sender, instance, created, **kwargs): else: where = "t'a mentionné sur " + where + on = (getattr(settings, 'INSTANCE_DEFAULT_CLIENT', False) or settings.JABBER_DEFAULT_HOST) + html_message = loader.render_to_string( 'email.html', { - 'on': (settings.INSTANCE_DEFAULT_CLIENT or settings.JABBER_DEFAULT_HOST), + 'on': on, 'instance': instance, 'author': who, 'object': where @@ -197,9 +201,9 @@ def send_email_on_notification(sender, instance, created, **kwargs): ) send_mail( - 'Notification sur ' + (settings.INSTANCE_DEFAULT_CLIENT or settings.JABBER_DEFAULT_HOST), + 'Notification sur ' + on, instance.summary, - settings.EMAIL_HOST_USER or "noreply@" + settings.JABBER_DEFAULT_HOST, + (getattr(settings, 'EMAIL_HOST_USER', False) or "noreply@" + settings.JABBER_DEFAULT_HOST), [instance.user.email], fail_silently=True, html_message=html_message diff --git a/djangoldp_notification/views.py b/djangoldp_notification/views.py new file mode 100644 index 0000000..3644ac7 --- /dev/null +++ b/djangoldp_notification/views.py @@ -0,0 +1,11 @@ +from djangoldp.views import LDPViewSet +from djangoldp.pagination import LDPPagination + + +class LDPNotificationsPagination(LDPPagination): + default_limit = 100 + + +class LDPNotifcationsViewSet(LDPViewSet): + '''overridden LDPViewSet to force pagination''' + pagination_class = LDPNotificationsPagination