Skip to content

Guia Notificações [EN US] [PT BR]

Felipe Bormann edited this page Dec 7, 2016 · 4 revisions

[EN-US]

Notification Guide

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.

Dependencies

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]

Guia de Notificação

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.

Dependências

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
  • Parâmetros:

  • Message: Uma string que o sistema irá enviar sobre a notificação.

  • actor = O usuário que está realizando a ação, assim outros usuários saberão quem fez o que.

  • users = Aqueles que irão receber a notificação

  • resource_slug = Isto é usado para saber o Resource único que o actor está agindo sobre.

  • action_slug = Isto é usado para saber o Action único que o actor está realizando, (Exemploes: "criando", "editando", "postando").

  • resource_name = Resource_name é usado no caso de um novo recurso, assim não há problemas ao criar uma notificação.

  • resource_link = resource_link é a url formada pelo django para acessar o recurso da melhor forma possível, assim o usuário não tem problemas para achar onde(resource) a ação(Action) foi feita.

E para chamar 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

Sua assinatura é similar ao do mixing e faz a mesma coisa, é um decorator, então funciona para quando for subescrever métodos em CBV ou FBV ou em qualquer outra função onde o decorator da notificação seja importante. Segue o link para o uso de decorators: https://wiki.python.org/moin/PythonDecorators