Merge branch 'notifications-pagination' into 'master'

feature: notifications pagination

Closes applications/hubl#549

See merge request djangoldp-packages/djangoldp-notification!31
This commit is contained in:
Jean-Baptiste Pasquier 2020-08-13 15:42:07 +00:00
commit 37dc728e0a
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 threading import Thread
from djangoldp_notification.middlewares import MODEL_MODIFICATION_USER_FIELD from djangoldp_notification.middlewares import MODEL_MODIFICATION_USER_FIELD
from djangoldp_notification.permissions import InboxPermissions, SubscriptionsPermissions from djangoldp_notification.permissions import InboxPermissions, SubscriptionsPermissions
from djangoldp_notification.views import LDPNotifcationsViewSet
class Notification(Model): class Notification(Model):
@ -32,6 +33,7 @@ class Notification(Model):
anonymous_perms = ['add'] anonymous_perms = ['add']
authenticated_perms = ['inherit'] authenticated_perms = ['inherit']
owner_perms = ['view', 'change', 'control'] owner_perms = ['view', 'change', 'control']
view_set = LDPNotifcationsViewSet
def __str__(self): def __str__(self):
return '{}'.format(self.type) return '{}'.format(self.type)
@ -160,7 +162,7 @@ def send_request(target, object_iri, instance, created):
@receiver(post_save, sender=Notification) @receiver(post_save, sender=Notification)
def send_email_on_notification(sender, instance, created, **kwargs): 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 # get author name, and store in who
try: try:
# local author # local author
@ -186,10 +188,12 @@ def send_email_on_notification(sender, instance, created, **kwargs):
else: else:
where = "t'a mentionné sur " + where where = "t'a mentionné sur " + where
on = (getattr(settings, 'INSTANCE_DEFAULT_CLIENT', False) or settings.JABBER_DEFAULT_HOST)
html_message = loader.render_to_string( html_message = loader.render_to_string(
'email.html', 'email.html',
{ {
'on': (settings.INSTANCE_DEFAULT_CLIENT or settings.JABBER_DEFAULT_HOST), 'on': on,
'instance': instance, 'instance': instance,
'author': who, 'author': who,
'object': where 'object': where
@ -197,9 +201,9 @@ def send_email_on_notification(sender, instance, created, **kwargs):
) )
send_mail( send_mail(
'Notification sur ' + (settings.INSTANCE_DEFAULT_CLIENT or settings.JABBER_DEFAULT_HOST), 'Notification sur ' + on,
instance.summary, 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], [instance.user.email],
fail_silently=True, fail_silently=True,
html_message=html_message 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