-
Notifications
You must be signed in to change notification settings - Fork 12
Guia Notificações [EN US] [PT BR]
[EN-US]
The notification system is mostly used to make the user able to perceive important information that is happening on the system. Teachers and students alike know when someone answers them on a forum, per example.
In order to add a notification in our system, we'll have to use one of these two ways:
- Import NotificationMixin from core.Mixins: This way you just have to inherit from NotificationMixin to be able to call it's method createNotification. Here is a screenshot of it's signature and how to call it from any part of your class.
createNotification Signature:
def createNotification(self, message='', actor=None, users = User.objects.all(), resource_slug='' ,action_slug = '',
resource_name='', resource_link=''): #the default will be a broadcast
- It's parameters:
- Message: A string that the system wants to deliver with the notification.
- actor = The user that is performing the action, so other users can know who did what.
- users = Those who are receiving the notification
- resource_slug = This is used to get a unique resource that the actor is acting upon.
- action_slug = This is used to get a unique action that the actor is doing (Example: "creating", "editing", "post"
- resource_name = This is used in case the resource is a brand new one, so the notification has to create it and thus a name has to be provided.
- resource_link = Here it's where we gave the url transformed from django to the resource, so when the user receives a notification, it can access the resource through the url in a quick way.
And to call createNotification:
Example:
super(CreateTopicView, self).createNotification("Topic "+ self.object.name + " was created",
resource_name=self.object.name, resource_link= reverse('course:view_topic',args=[self.object.slug]),
actor=self.request.user, users = self.object.subject.course.students.all() )
- Import notification_decorator from core.decorators
It's signature is similar from the mixin and does the same thing, as it is a decorator, it works for CBV (Class Based View) methods or FBVs (Function Based View). We haven't used decorators on notifications but the parameters are the same as the createNotification from Mixin. [PT-BR]
O sistema de notificação é usado para que o usuário possa receber informações importantes acerca do que está acontecendo em seu ambiente de aprendizagem. Tanto estudantes quanto professores podem saber quando alguém respondem eles no fórum, por exemplo.
Para adicionar uma notificação ao sistema, nós temos de usar uma das duas maneiras:
- Importar NotificationMixin do core.Mixins: A única coisa necessária à fazer é sua classe herdar de NotificationMixin para ser hábil de chamar o método createNotification, segue abaixo uma screenshot da sua assinatura e como chamar o método createNotification.
createNotification Signature:
def createNotification(self, message='', actor=None, users = User.objects.all(), resource_slug='' ,action_slug = '',
resource_name='', resource_link=''): #the default will be a broadcast
- It's parameters:
- Message: A string that the system wants to deliver with the notification.
- actor = The user that is performing the action, so other users can know who did what.
- users = Those who are receiving the notification
- resource_slug = This is used to get a unique resource that the actor is acting upon.
- action_slug = This is used to get a unique action that the actor is doing (Example: "creating", "editing", "post"
- resource_name = This is used in case the resource is a brand new one, so the notification has to create it and thus a name has to be provided.
- resource_link = Here it's where we gave the url transformed from django to the resource, so when the user receives a notification, it can access the resource through the url in a quick way.
And to call createNotification:
Example:
super(CreateTopicView, self).createNotification("Topic "+ self.object.name + " was created",
resource_name=self.object.name, resource_link= reverse('course:view_topic',args=[self.object.slug]),
actor=self.request.user, users = self.object.subject.course.students.all() )
- Import notification_decorator from core.decorators
It's signature is similar from the mixin and does the same thing, as it is a decorator, it works for CBV (Class Based View) methods or FBVs (Function Based View). We haven't used decorators on notifications but the parameters are the same as the createNotification from Mixin.