Skip to content

Commit

Permalink
Add some docs on scoping notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
paltman committed Mar 4, 2015
1 parent 3fa49cf commit 34018c9
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 3 deletions.
12 changes: 11 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ includes:
* Notification messages on signing in
* Notification messages via email (configurable by user)
* Ability to supply your own backends notification channels
* Ability to scope notifications at the site level


!!! note "Originally django-notification"
Expand All @@ -30,7 +31,7 @@ includes:

## Quickstart

Install the development version:
Install the latest version:

pip install pinax-notifications

Expand All @@ -45,3 +46,12 @@ Add `pinax-notifications` to your `INSTALLED_APPS` setting:
Add entry to your `urls.py`:

url(r"^notifications/", include("pinax.notifications.urls"))

Create one or more notice types:

NoticeType.create(label, display, description)

In your code, send events;

from pinax.notifications.models import send
send([users], "label", {"extra": context})
67 changes: 67 additions & 0 deletions docs/scoping.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Scoping Notifications

Sometimes you have a site that has groups or teams. Perhaps you are using
[pinax-teams](https://github.com/pinax/pinax-teams/). If this is the case you
likely want users who might be members of multiple teams to be able to set
their notification preferences on a per team or group basis.

You will need to:

* Create a custom model for settings
* Override NoticeSettingsView


## Custom Model for Settings

First thing you need to do is subclass `pinax.notifications.models.NoticeSettingBase`
and add whatever attributes needed to provide the scoping. For example, to
scope by a `pinax-teams` team:

# models.py
from pinax.notifications.models import NoticeSettingsBase

class TeamNoticeSetting(NoticeSettingsBase):
team = models.ForeignKey(Team, null=True)
@classmethod
def get_lookup_kwargs(cls, user, notice_type, medium, scoping):
return {
"user": user,
"notice_type": notice_type,
"medium": medium,
"team": scoping
}

# settings.py
PINAX_NOTIFICATIONS_SETTING_MODEL = "mysite.TeamNoticeSetting"


## Override NoticeSettingsView

Next, let's override the method on `pinax.notifications.views.NoticeSettingsView`
that handles the lookup of the `setting` for each notice type and channel.

# views.py
from pinax.notifications.views import NoticeSettingsView

class TeamNoticeSettingsView(NoticeSettingsView):
def setting_for_user(self, notice_type, medium_id):
return self.SettingModel.for_user(
self.request.user,
notice_type,
medium_id,
scoping=self.request.team
)

# urls.py
from django.conf.urls import patterns, url

from .views import TeamNoticeSettingsView


urlpatterns = patterns(
"",
...
url(r"^notifications/settings/$", TeamNoticeSettingsView.as_view(), name="notification_notice_settings"),
)
18 changes: 16 additions & 2 deletions docs/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ file. A common use-case for overriding this default might be `https` for use on
more secure projects.


## PINAX_NOTIFICATIONS_LANGUAGE_MODULE
## PINAX_NOTIFICATIONS_LANGUAGE_MODEL

Formerly, this setting was `NOTIFICATION_LANGUAGE_MODULE`

Expand All @@ -49,7 +49,7 @@ Example model in a `languages` app::

Setting this value in `settings.py`::

PINAX_NOTIFICATIONS_LANGUAGE_MODULE = "languages.Language"
PINAX_NOTIFICATIONS_LANGUAGE_MODEL = "languages.Language"


DEFAULT_FROM_EMAIL
Expand Down Expand Up @@ -101,3 +101,17 @@ It defines how long to wait for the lock to become available. Default of -1
means to never wait for the lock to become available. This only applies when
using crontab setup to execute the `emit_notices` management command to send
queued messages rather than sending immediately.


## PINAX_NOTIFICATIONS_SETTING_MODEL

This defaults to `notifications.NoticeSetting`.

It exists so that you can supply your own subclass of
`pinax.notifications.models.NoticeSettingBase` in case you needed to scope
settings by some group or team in your site. For example, if you were using
`pinax-teams` and wanted people to be able to set/control notifications
differently for each team of which they were a member.

See [scoping your notifications](scoping.md) for more details on how this
works.
3 changes: 3 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ site_name: pinax-notifications
pages:
- [index.md, Home]
- [changelog.md, Change Log]
- [usage.md, Usage]
- [settings.md, Settings]
- [scoping.md, Scoping Notifications]
theme: readthedocs
repo_url: https://github.com/pinax/pinax-notifications
site_description: "an app"
Expand Down

0 comments on commit 34018c9

Please # to comment.