-
Notifications
You must be signed in to change notification settings - Fork 12
Guia Notificações [EN US] [PT BR]
Felipe Bormann edited this page Dec 6, 2016
·
4 revisions
[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 the three 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 you only have to understand it's parameters:
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]