readthedocs.org/readthedocs/notifications/__init__.py

27 lines
817 B
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2019-01-09 12:19:00 +00:00
"""
Extensions to Django messages to support notifications to users.
Notifications are important communications to users that need to be as visible
as possible. We support different backends to make notifications visible in
different ways. For example, they might be e-mailed to users as well as
displayed on the site.
This app builds on `django-messages-extends`_ to provide persistent messages
on the site.
.. _`django-messages-extends`: https://github.com
/AliLozano/django-messages-extends/
"""
Allow to hook the initial build from outside (#4033) * Allow to hook the initial build from outside Add a new attribute to `trigger_build` to do not execute the task but just return the immutable signature of it, so it can be chained into a bigger task from outside when it's needed to do something else before/after it's execution. * Remove unused basic attribute on trigger build * Split trigger_build to be able to prepare_build first Added a ``ImportWizard.trigger_initial_build`` method to be override from corporate site. Also, instead of using ``trigger_build`` to create the Celery task and call it immediately, split it to use ``prepare_build`` first to create the task and use ``trigger_build`` to effectively triggers it. * Remove now unused signal * Fix Celery signature creation * Fix testcases with basic on trigger_build * Fix mock calls in test cases * Fix test mock check * Use async task to attach webhook * Use proper context object * Make it compatible with newer Django versions * Py2 and Py3 compatible line * Dismiss the sticky message and stay in the same page * Use Context to render the template * Lint errors fixed * Call the task in a sync way properly * Update common submodule to latest * Define NonPersistentStorage for one-time notifications NonPersistentNotification backed together with SiteNotification class helps us to create one-time site notifications and attach it to a user without the needs of a request/session object. The message/notification is saved into the database as a PersistentMessage and it's marked as read while it's retrived the first time. This system is useful for notifications that need to be attached from a Celery task where we know the user but we don't have the request. * Make string translatable * Fix merge conflicts * Recover accidentally deleted line * Fixed linting errors * Replace message_key with reason to be clearer * Rename non persistent storage class * Remove old templates * Make SiteNotification more flexible - render strings messages as Django Templates - accept extra_context for the template - do not crash if the reason is incorrect * Adapt AttachWebhookNotification to the new features * Refactor the task to attach a webhook Instantiate only once the notification and adapt it depending the context. Also, if there are no connected services into our application do not show a message to the user, but log it as a warning. * Test cases for SiteNotification and NonPersistentStorage * Remove unnecessary lines * Show a persistent message for invalid project webhook If we can setup a valid webhook, we show a persistent message with an actionable link using our notifications abstraction. At this point, the message is duplicated because we have a "fixed template message" also which is planned to be removed soon. * Improve copy * Allow to hook the initial build from outside Add a new attribute to `trigger_build` to do not execute the task but just return the immutable signature of it, so it can be chained into a bigger task from outside when it's needed to do something else before/after it's execution. * Remove unused basic attribute on trigger build * Split trigger_build to be able to prepare_build first Added a ``ImportWizard.trigger_initial_build`` method to be override from corporate site. Also, instead of using ``trigger_build`` to create the Celery task and call it immediately, split it to use ``prepare_build`` first to create the task and use ``trigger_build`` to effectively triggers it. * Remove now unused signal * Fix Celery signature creation * Fix testcases with basic on trigger_build * Fix mock calls in test cases * Fix test mock check * Use proper context object * Make it compatible with newer Django versions * Py2 and Py3 compatible line * Dismiss the sticky message and stay in the same page * Use Context to render the template * Lint errors fixed * Call the task in a sync way properly * Update common submodule to latest * Define NonPersistentStorage for one-time notifications NonPersistentNotification backed together with SiteNotification class helps us to create one-time site notifications and attach it to a user without the needs of a request/session object. The message/notification is saved into the database as a PersistentMessage and it's marked as read while it's retrived the first time. This system is useful for notifications that need to be attached from a Celery task where we know the user but we don't have the request. * Make string translatable * Use async task to attach webhook * Fix merge conflicts * Recover accidentally deleted line * Fixed linting errors * Replace message_key with reason to be clearer * Rename non persistent storage class * Remove old templates * Make SiteNotification more flexible - render strings messages as Django Templates - accept extra_context for the template - do not crash if the reason is incorrect * Adapt AttachWebhookNotification to the new features * Refactor the task to attach a webhook Instantiate only once the notification and adapt it depending the context. Also, if there are no connected services into our application do not show a message to the user, but log it as a warning. * Test cases for SiteNotification and NonPersistentStorage * Remove unnecessary lines * Show a persistent message for invalid project webhook If we can setup a valid webhook, we show a persistent message with an actionable link using our notifications abstraction. At this point, the message is duplicated because we have a "fixed template message" also which is planned to be removed soon. * Improve copy * Remove fixed template notification about Project.has_valid_webhook
2018-06-14 18:29:08 +00:00
from .notification import Notification, SiteNotification
from .backends import send_notification
__all__ = (
'Notification',
Allow to hook the initial build from outside (#4033) * Allow to hook the initial build from outside Add a new attribute to `trigger_build` to do not execute the task but just return the immutable signature of it, so it can be chained into a bigger task from outside when it's needed to do something else before/after it's execution. * Remove unused basic attribute on trigger build * Split trigger_build to be able to prepare_build first Added a ``ImportWizard.trigger_initial_build`` method to be override from corporate site. Also, instead of using ``trigger_build`` to create the Celery task and call it immediately, split it to use ``prepare_build`` first to create the task and use ``trigger_build`` to effectively triggers it. * Remove now unused signal * Fix Celery signature creation * Fix testcases with basic on trigger_build * Fix mock calls in test cases * Fix test mock check * Use async task to attach webhook * Use proper context object * Make it compatible with newer Django versions * Py2 and Py3 compatible line * Dismiss the sticky message and stay in the same page * Use Context to render the template * Lint errors fixed * Call the task in a sync way properly * Update common submodule to latest * Define NonPersistentStorage for one-time notifications NonPersistentNotification backed together with SiteNotification class helps us to create one-time site notifications and attach it to a user without the needs of a request/session object. The message/notification is saved into the database as a PersistentMessage and it's marked as read while it's retrived the first time. This system is useful for notifications that need to be attached from a Celery task where we know the user but we don't have the request. * Make string translatable * Fix merge conflicts * Recover accidentally deleted line * Fixed linting errors * Replace message_key with reason to be clearer * Rename non persistent storage class * Remove old templates * Make SiteNotification more flexible - render strings messages as Django Templates - accept extra_context for the template - do not crash if the reason is incorrect * Adapt AttachWebhookNotification to the new features * Refactor the task to attach a webhook Instantiate only once the notification and adapt it depending the context. Also, if there are no connected services into our application do not show a message to the user, but log it as a warning. * Test cases for SiteNotification and NonPersistentStorage * Remove unnecessary lines * Show a persistent message for invalid project webhook If we can setup a valid webhook, we show a persistent message with an actionable link using our notifications abstraction. At this point, the message is duplicated because we have a "fixed template message" also which is planned to be removed soon. * Improve copy * Allow to hook the initial build from outside Add a new attribute to `trigger_build` to do not execute the task but just return the immutable signature of it, so it can be chained into a bigger task from outside when it's needed to do something else before/after it's execution. * Remove unused basic attribute on trigger build * Split trigger_build to be able to prepare_build first Added a ``ImportWizard.trigger_initial_build`` method to be override from corporate site. Also, instead of using ``trigger_build`` to create the Celery task and call it immediately, split it to use ``prepare_build`` first to create the task and use ``trigger_build`` to effectively triggers it. * Remove now unused signal * Fix Celery signature creation * Fix testcases with basic on trigger_build * Fix mock calls in test cases * Fix test mock check * Use proper context object * Make it compatible with newer Django versions * Py2 and Py3 compatible line * Dismiss the sticky message and stay in the same page * Use Context to render the template * Lint errors fixed * Call the task in a sync way properly * Update common submodule to latest * Define NonPersistentStorage for one-time notifications NonPersistentNotification backed together with SiteNotification class helps us to create one-time site notifications and attach it to a user without the needs of a request/session object. The message/notification is saved into the database as a PersistentMessage and it's marked as read while it's retrived the first time. This system is useful for notifications that need to be attached from a Celery task where we know the user but we don't have the request. * Make string translatable * Use async task to attach webhook * Fix merge conflicts * Recover accidentally deleted line * Fixed linting errors * Replace message_key with reason to be clearer * Rename non persistent storage class * Remove old templates * Make SiteNotification more flexible - render strings messages as Django Templates - accept extra_context for the template - do not crash if the reason is incorrect * Adapt AttachWebhookNotification to the new features * Refactor the task to attach a webhook Instantiate only once the notification and adapt it depending the context. Also, if there are no connected services into our application do not show a message to the user, but log it as a warning. * Test cases for SiteNotification and NonPersistentStorage * Remove unnecessary lines * Show a persistent message for invalid project webhook If we can setup a valid webhook, we show a persistent message with an actionable link using our notifications abstraction. At this point, the message is duplicated because we have a "fixed template message" also which is planned to be removed soon. * Improve copy * Remove fixed template notification about Project.has_valid_webhook
2018-06-14 18:29:08 +00:00
'SiteNotification',
'send_notification',
)
default_app_config = 'readthedocs.notifications.apps.NotificationsAppConfig'