feature: notifications pagination

This commit is contained in:
Calum Mackervoy 2020-08-13 15:42:07 +00:00 committed by Jean-Baptiste Pasquier
parent 00fd64cdc9
commit 5e616fc697
2 changed files with 19 additions and 4 deletions

View File

@ -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

View File

@ -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