endi.utils.notification package

Submodules

endi.utils.notification.abstract module

Abstract dataclasses for notifications

… code-block:: python

from endi.utils.notification import AbstractNotification, notify notif = AbstractNotification(

key=”task:status:valid”, title=”Votre facture a été validée”, body=”Voir votre facture <a href=”#”>Ici</a>”

) notify(request, notification, user_ids=[1,2,3], groups=[“manager”, “admin”])

class endi.utils.notification.abstract.AbstractNotification(key: str, title: str, body: str, check_query: Optional[str] = None, due_datetime: Optional[datetime] = None, context_tablename: Optional[str] = None, context_id: Optional[int] = None)

Bases : object

Abstract Notification object should be used by code firing notification

key

The endi key of notification

title

A title

body

The message body

check_query

An str query that should return at least en element, if not, planned notification should be cancelled

context_tablename

The name of the table this notification is related to

context_id

The id of the element this notification is related to

body: str
check_query: Optional[str] = None
context_id: Optional[int] = None
context_tablename: Optional[str] = None
due_datetime: Optional[datetime] = None
classmethod from_event(event: NotificationEvent)
key: str
title: str
to_event() NotificationEvent
to_model() Notification

endi.utils.notification.career_path module

Career Path related notification tools

endi.utils.notification.career_path.get_abstract_notification(user: User, career_path: CareerPath) AbstractNotification
endi.utils.notification.career_path.get_checkcareer_path_last_query(career_path: CareerPath) str

Build a string query to check if the given career_path is last one

endi.utils.notification.career_path.get_existing_notification_event(career_path: CareerPath) Optional[NotificationEvent]

Find an existing event referring to this specific career_path

endi.utils.notification.career_path.notify_career_path_end_date(request, user: User, career_path: CareerPath, update=False)

Notify the end of a career_path to a user’s follower

endi.utils.notification.career_path.should_notification_event_be_updated(career_path: CareerPath, event: NotificationEvent) bool

Check if the notification event should be updated

endi.utils.notification.career_path.update_notification_event(request, user: User, career_path: CareerPath, event: NotificationEvent)

Update an existing notification event if needed

endi.utils.notification.channels module

Base Channels implementations

Should not be used directly (only through the request object)

>>> factory = request.find_service_factory(INotificationChannel, name='mail')
>>> channel = factory()
>>> channel.send_user(....)
class endi.utils.notification.channels.AlertNotificationChannel(context, request)

Bases : MessageNotificationChannel

channel_name = 'alert'
class endi.utils.notification.channels.HeaderMessageNotificationChannel(context, request)

Bases : MessageNotificationChannel

channel_name = 'header_message'
class endi.utils.notification.channels.MailNotificationChannel(context, request)

Bases : object

send_to_company(notification: AbstractNotification, company: Company, **kw)

Send the notification

send_to_user(notification: AbstractNotification, user: User, **kw)
class endi.utils.notification.channels.MessageNotificationChannel(context, request)

Bases : object

channel_name = 'message'
send_to_company(notification: AbstractNotification, company: Company, **kw)

Send the notification

send_to_user(notification: AbstractNotification, user: User, **kw)
endi.utils.notification.channels.get_channel(request, user, notification_key, force_channel=None)

Return the Channel configured for this type of notification

endi.utils.notification.channels.get_notification_channel(request, channel_name: str)

Collect the INotficationChannel configured for channel_name

endi.utils.notification.notification module

Notification tools

A single function : notify()

Notifications can be published now or delayed

When notifications are published, they are sent to the appropriate channels

  • email

  • endi internal messages

  • endi alert

  • endi header

E.g : Send a notification 6 months later to the manager team

>>> abstract_notification = AbstractNotification(
        title="Notification",
        body="Le compte <a href='/users/23'>Jean Dupont</a> doit peut-être "
        "être désactivé, à vérifier",
        key='message:internal'
    )
>>> notify(request, abstract_notification, group_names=['manager'])
endi.utils.notification.notification.clean_notifications(request)

Clean outdated Notifications

endi.utils.notification.notification.notify(request, notification: AbstractNotification, group_names: Optional[list] = None, user_ids: Optional[list] = None, company_id: Optional[int] = None, follower_user_id: Optional[int] = None, force_channel: Optional[str] = None, **kw)

Handle user notifications in enDI, notify directly or program a future notification

endi.utils.notification.notification.notify_company(request, notification: AbstractNotification, company_id: int, force_channel: Optional[str] = None, **kw)

Notify a company

Paramètres:
  • notification – The notification object

  • company_id – Id of the destination company

  • force_channel – the name of the channel

endi.utils.notification.notification.notify_follower(request, notification: AbstractNotification, follower_user_id: int, force_channel: Optional[str] = None, **kw)

Notify a follower

Paramètres:
  • notification – The notification object

  • follower_user_id – Id of a user whose follower will get a notification

  • force_channel – the name of the channel

endi.utils.notification.notification.notify_group(request, notification: AbstractNotification, group_name: Optional[str], force_channel: Optional[str] = None, **kw)

Notify a group of users

Paramètres:
  • notification – The notification object

  • group_name – The name of a group

  • force_channel – the name of the channel

endi.utils.notification.notification.notify_later(request, notification: AbstractNotification, group_names: Optional[list] = None, user_ids: Optional[list] = None, company_id: Optional[int] = None, follower_user_id: Optional[int] = None, force_channel: Optional[str] = None, **kw)

Plan a notification for later on

endi.utils.notification.notification.notify_now(request, notification: AbstractNotification, group_names: Optional[list] = None, user_ids: Optional[list] = None, company_id: Optional[int] = None, follower_user_id: Optional[int] = None, force_channel: Optional[str] = None, **kw)

Send notification to the users

endi.utils.notification.notification.notify_users(request, notification: AbstractNotification, users: list, force_channel: Optional[str] = None, **kw)

Notify a list of users

Paramètres:
  • notification – The notification object

  • users – List of usernames

  • force_channel – the name of the channel

endi.utils.notification.notification.publish_event(request, event: NotificationEvent)

Publish notifications planned through the event object

Module contents

endi.utils.notification.includeme(config)