2019-01-08 20:51:36 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2019-01-09 12:19:00 +00:00
|
|
|
|
2017-12-16 01:09:29 +00:00
|
|
|
"""
|
|
|
|
Extensions to Django messages to support notifications to users.
|
2017-05-23 17:54:00 +00:00
|
|
|
|
|
|
|
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
|
Integrate on-site messaging that is persistent, combine message transports (#2406)
* WIP for integrating persistent messaging for users
Combines notifications so that email/on site messaging will all be maintained in
the same place, and can extend from each other using normal template semantics.
* Add email support, clean up implementation
* Add reqs
* Drop unnecessary string conversion
* Change admin email form to look at templates, not ask for template source
* Add docs, tests, views for processing redirects
* Do the thing I meant to do
* Drop views, just use javascript instead
This adds javascript that intercepts link clicks in notifications,
hits the dismiss url defined on the dom object, and then redirects
to the correct url of the original link.
* Move classes around and rename module
* Drop unused notification for testing
* Clean up usage, drop test uses of the views/notifications
* Add example usage that will be used for notification on resource usage
* Fix mock module path
* Add more docs around implementation
2016-10-01 17:19:51 +00:00
|
|
|
from .backends import send_notification
|
|
|
|
|
2017-05-23 17:54:00 +00:00
|
|
|
__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',
|
2019-01-08 20:51:36 +00:00
|
|
|
'send_notification',
|
2017-05-23 17:54:00 +00:00
|
|
|
)
|
|
|
|
|
Integrate on-site messaging that is persistent, combine message transports (#2406)
* WIP for integrating persistent messaging for users
Combines notifications so that email/on site messaging will all be maintained in
the same place, and can extend from each other using normal template semantics.
* Add email support, clean up implementation
* Add reqs
* Drop unnecessary string conversion
* Change admin email form to look at templates, not ask for template source
* Add docs, tests, views for processing redirects
* Do the thing I meant to do
* Drop views, just use javascript instead
This adds javascript that intercepts link clicks in notifications,
hits the dismiss url defined on the dom object, and then redirects
to the correct url of the original link.
* Move classes around and rename module
* Drop unused notification for testing
* Clean up usage, drop test uses of the views/notifications
* Add example usage that will be used for notification on resource usage
* Fix mock module path
* Add more docs around implementation
2016-10-01 17:19:51 +00:00
|
|
|
default_app_config = 'readthedocs.notifications.apps.NotificationsAppConfig'
|