Skip to content

Commit

Permalink
[docs] Updated README
Browse files Browse the repository at this point in the history
- Added documentation for NotificationSetting
- Removed references of NotificationUser
  • Loading branch information
pandafy committed Aug 17, 2020
1 parent 5fcdeaf commit b5166f7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
62 changes: 47 additions & 15 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Available features
- Configurable email theme
- `Definition of notification types <#notification-types>`_
- `Possibility to register new notification types <#registering--unregistering-notification-types>`_
- `Preference for receiving notifications <#notification-preference>`_
- TODO: add more

Install development version
Expand Down Expand Up @@ -210,6 +211,14 @@ While development, you can configure it to localhost as shown below:
INTERNAL_IPS = ['127.0.0.1']
Run migrations

.. code-block:: shell
./manage.py migrate
**Note**: Running migrations is also required for creating `notification settings <#notification-preference>`_ apart from creating database schema.

Sending notifications
---------------------

Expand Down Expand Up @@ -343,6 +352,9 @@ from scratch. An example to extend default message template is shown below.
template as shown above. Additionally attributes ``actor_link``, ``action_link`` and ``target_link`` are
also available for providing hyperlinks to respective object.

**Note**: After writing code for registering or unregistering notification types, it is recommended to run
database migrations to create notification settlings for these notification types.

Registering / Unregistering Notification Types
----------------------------------------------

Expand Down Expand Up @@ -462,6 +474,25 @@ Then in the application code:
error=str(error)
)
Notification Preference
-----------------------

*openwisp-notifications* allows users to select their preferred way of receiving notifications.
Users can choose from web or email notifications. These settings have been categorized
over notification type and organization, therefore allowing users to only receive notifications
from selected organization or notification type.

.. image:: https://github.com/openwisp/openwisp-notifications/blob/master/docs/images/notification-settings.png

Notification settings are automatically created for all notification types and organizations for all users.
While superusers can add or delete notification settings for everyone, staff users can only modify their
preferred ways for receiving notifications. With provided functionality, users can choose to receive both
web and email notifications or only web notifications. Users can also stop receiving notifications
by disabling both web and email option for a notification setting.

**Note**: If a user has not configured their email preference for a particular notification setting,
then ``email_notification`` option of concerned notification type will be used.

Scheduled deletion of notifications
-----------------------------------

Expand Down Expand Up @@ -741,21 +772,21 @@ List user's notification setting

.. code-block:: text
GET /api/v1/notifications/setting/
GET /api/v1/notification/user-setting/
Get notification setting details
################################

.. code-block:: text
GET /api/v1/notifications/setting/{pk}/
GET /api/v1/notification/user-setting/{pk}/
Update notification setting details
###################################

.. code-block:: text
PATCH /api/v1/notifications/setting/{pk}/
PATCH /api/v1/notification/user-setting/{pk}/
Installing for development
--------------------------
Expand Down Expand Up @@ -984,7 +1015,7 @@ Add the following to your ``settings.py``:
# Setting models for swapper module
OPENWISP_NOTIFICATIONS_NOTIFICATION_MODEL = 'mynotifications.Notification'
OPENWISP_NOTIFICATIONS_NOTIFICATIONUSER_MODEL = 'mynotifications.NotificationUser'
OPENWISP_NOTIFICATIONS_NOTIFICATIONSETTING_MODEL = 'mynotifications.NotificationSetting'
9. Create database migrations
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -1016,7 +1047,7 @@ For example:

.. code-block:: python
from openwisp_notifications.admin import NotificationAdmin, NotificationUserInline
from openwisp_notifications.admin import NotificationAdmin, NotificationSettingInline
NotificationAdmin.list_display.insert(1, 'my_custom_field')
NotificationAdmin.ordering = ['-my_custom_field']
Expand All @@ -1030,27 +1061,28 @@ monkey patching, you can proceed as follows:
.. code-block:: python
from django.contrib import admin
from openwisp_notifications.admin import NotificationAdmin as BaseNotificationAdmin
from openwisp_notifications.admin import (
NotificationUserInline as BaseNotificationUserInline,
NotificationSettingAdmin as BaseNotificationSettingAdmin,
)
from openwisp_notifications.admin import (
NotificationSettingInline as BaseNotificationSettingInline,
)
from openwisp_notifications.swapper import load_model
Notification = load_model('Notification')
NotificationUser = load_model('NotificationUser')
NotificationSetting = load_model('NotificationSetting')
admin.site.unregister(Notification)
admin.site.unregister(NotificationUser)
admin.site.unregister(NotificationSettingAdmin)
admin.site.unregister(NotificationSettingInline)
@admin.register(Notification)
class NotificationAdmin(BaseNotificationAdmin):
@admin.register(NotificationSetting)
class NotificationSettingAdmin(BaseNotificationSettingAdmin):
# add your changes here
pass
@admin.register(NotificationUser)
class NotificationUserInline(BaseNotificationUserInline):
@admin.register(NotificationSetting)
class NotificationSettingInline(BaseNotificationSettingInline):
# add your changes here
pass
Expand Down
Binary file modified docs/images/api-docs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/notification-settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b5166f7

Please sign in to comment.