:py:mod:`oioioi.base.notification` ================================== .. py:module:: oioioi.base.notification Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: oioioi.base.notification.NotificationHandler Attributes ~~~~~~~~~~ .. autoapisummary:: oioioi.base.notification.logger oioioi.base.notification.thread_data .. py:data:: logger .. py:data:: thread_data .. py:class:: NotificationHandler(stream=None) Bases: :py:obj:`logging.StreamHandler` This handler catches all logs and emits a notification if a notification type is set in the extra dictionary, in the log record. .. py:attribute:: loaded_notifications :annotation: = False .. py:attribute:: notification_functions .. py:attribute:: notification_queue_prefix :annotation: = _notifs_ .. py:attribute:: last_connection_check :annotation: = 0 .. py:attribute:: conn_try_interval :annotation: = 30 .. py:method:: _check_connection() :classmethod: .. py:method:: _send_notification_message(user, message, repeated=False) :classmethod: .. py:method:: send_notification(user, notification_type, notification_message, notification_message_arguments) :classmethod: This function sends a notification to the specified user by sending a message to RabbitMQ. :param user: User, to whom the notification will be sent. :param notification_type: A string which describes the notification type. :param notification_message: A message to show to the notified user, which will be translated by frontend to their language and interpolated using notification_message_arguments. Remember to mark this message to translate, passing it as argument to _() function, so that the message string will be caught to translate. :param notification_message_arguments: A map which contains strings to interpolate notification_message and special optional parameters: * "address" -- an absolute link (starting with http://) to a page related to the notification, where the user can check the details. * "details" -- a short information for the user about the event. * "popup" -- if set the related dropdown will be opened in ui. .. py:method:: register_notification(notification_type, notification_function) :classmethod: Register a specific notification handler function for the specified type of notification, that will be executed each time a log with this notification type is processed. .. py:method:: emit(record) This function is called each time a message is logged. In our design, it's role is to invoke a specific handler for corresponding notification type, registered before via :meth:`register` function by caller. Specific notification handler should prepare translated message string, split one event for particular users and execute :meth:`send_notification` function for each user who should be notified.