Skip to content

Commit 6a1f549

Browse files
committed
Clean up docs
1 parent 748a9f4 commit 6a1f549

File tree

2 files changed

+50
-112
lines changed

2 files changed

+50
-112
lines changed

docs/customizing.md

Lines changed: 46 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ class SMSChannel(BaseChannel):
1212
supports_realtime = True
1313
supports_digest = False
1414

15+
def should_send(self, notification):
16+
return bool(getattr(notification.recipient, "phone_number", None))
17+
1518
def send_now(self, notification):
1619
# Send SMS using your preferred service
1720
send_sms(
@@ -20,131 +23,82 @@ class SMSChannel(BaseChannel):
2023
)
2124
```
2225

23-
## Channel Defaults
26+
## Required Channels
27+
28+
Make certain channels mandatory for critical notifications:
29+
30+
```python
31+
from generic_notifications.types import NotificationType
32+
from generic_notifications.channels import EmailChannel
33+
34+
@register
35+
class SecurityAlert(NotificationType):
36+
key = "security_alert"
37+
name = "Security Alerts"
38+
description = "Important security notifications"
39+
required_channels = [EmailChannel] # Cannot be disabled
40+
```
41+
42+
## Forbidden Channels
43+
44+
Prevent certain channels from being used for specific notification types:
45+
46+
```python
47+
from generic_notifications.types import NotificationType
48+
from generic_notifications.channels import SMSChannel
49+
50+
@register
51+
class CommentReceivedNotification(NotificationType):
52+
key = "comment_received"
53+
name = "Comment received"
54+
description = "You received a comment"
55+
forbidden_channels = [SMSChannel] # Never send via SMS
56+
```
57+
58+
Forbidden channels take highest priority - they cannot be enabled even if specified in `default_channels`, `required_channels`, or user preferences.
59+
60+
## Defaults Channels
2461

25-
Control which channels are enabled by default for different notification types and channels.
62+
By default all channels are enabled for all users, and for all notifications types. Control which channels are enabled by default.
2663

2764
### Per-Channel Defaults
2865

29-
Set whether a channel is enabled by default across all notification types:
66+
Disable a channel by default across all notification types:
3067

3168
```python
3269
@register
3370
class SMSChannel(BaseChannel):
3471
key = "sms"
3572
name = "SMS"
36-
enabled_by_default = False # Opt-in only - users must explicitly enable
37-
supports_realtime = True
38-
39-
@register
40-
class PushChannel(BaseChannel):
41-
key = "push"
42-
name = "Push Notifications"
43-
enabled_by_default = True # Opt-out - enabled unless user disables
4473
supports_realtime = True
74+
supports_digest = False
75+
enabled_by_default = False # Opt-in only - users must explicitly enable
4576
```
4677

47-
The default value for `enabled_by_default` is `True`, maintaining backward compatibility.
48-
4978
### Per-NotificationType Defaults
5079

51-
Override channel defaults for specific notification types:
80+
By default all channels are enabled for every notification type. You can override channel defaults for specific notification types:
5281

5382
```python
5483
@register
5584
class MarketingEmail(NotificationType):
5685
key = "marketing"
5786
name = "Marketing Updates"
58-
# Only enable email by default, disable website notifications
87+
# Only enable email by default
88+
# (users can still opt-in to enable other channels)
5989
default_channels = [EmailChannel]
60-
61-
@register
62-
class UrgentAlert(NotificationType):
63-
key = "urgent_alert"
64-
name = "Urgent Alerts"
65-
# Enable all channels including normally opt-in ones
66-
default_channels = [EmailChannel, WebsiteChannel, SMSChannel, PushChannel]
6790
```
6891

69-
When `default_channels` is specified, it overrides the global `enabled_by_default` settings. If `default_channels` is `None` (the default), the system uses each channel's `enabled_by_default` setting.
70-
7192
### Priority Order
7293

7394
The system determines enabled channels in this priority order:
7495

7596
1. **Forbidden channels** - Always disabled (cannot be overridden)
7697
2. **Required channels** - Always enabled (cannot be disabled)
77-
3. **User preferences** - Explicit user enable/disable choices
98+
3. **User preferences** - Explicit user enable/disable choices (see [preferences.md](https://github.com/loopwerk/django-generic-notifications/tree/main/docs/preferences.md))
7899
4. **NotificationType.default_channels** - Per-type defaults (if specified)
79100
5. **BaseChannel.enabled_by_default** - Global channel defaults
80101

81-
### Examples
82-
83-
```python
84-
# Example: Marketing emails are opt-in only
85-
@register
86-
class MarketingEmail(NotificationType):
87-
key = "marketing"
88-
name = "Marketing Emails"
89-
default_channels = [] # No channels enabled by default
90-
91-
# Example: Critical alerts use all available channels
92-
@register
93-
class SecurityBreach(NotificationType):
94-
key = "security_breach"
95-
name = "Security Breach Alert"
96-
default_channels = [EmailChannel, SMSChannel, PushChannel]
97-
required_channels = [EmailChannel] # Email cannot be disabled
98-
99-
# Example: Social notifications only on website by default
100-
@register
101-
class SocialNotification(NotificationType):
102-
key = "social"
103-
name = "Social Updates"
104-
default_channels = [WebsiteChannel] # Only website, not email
105-
```
106-
107-
## Required Channels
108-
109-
Make certain channels mandatory for critical notifications:
110-
111-
```python
112-
from generic_notifications.channels import EmailChannel
113-
114-
@register
115-
class SecurityAlert(NotificationType):
116-
key = "security_alert"
117-
name = "Security Alerts"
118-
description = "Important security notifications"
119-
required_channels = [EmailChannel] # Cannot be disabled
120-
```
121-
122-
## Forbidden Channels
123-
124-
Prevent certain channels from being used for specific notification types:
125-
126-
```python
127-
from generic_notifications.channels import SMSChannel, WebsiteChannel
128-
129-
@register
130-
class InternalAuditLog(NotificationType):
131-
key = "audit_log"
132-
name = "Internal Audit Log"
133-
description = "Internal system audit events"
134-
forbidden_channels = [SMSChannel] # Never send audit logs via SMS
135-
default_channels = [WebsiteChannel] # Only show in web interface
136-
137-
@register
138-
class PrivacySensitiveNotification(NotificationType):
139-
key = "privacy_sensitive"
140-
name = "Privacy Sensitive Alert"
141-
description = "Contains sensitive personal information"
142-
forbidden_channels = [WebsiteChannel] # Don't show in UI where others might see
143-
required_channels = [EmailChannel] # Must go to private email
144-
```
145-
146-
Forbidden channels take highest priority - they cannot be enabled even if specified in `default_channels`, `required_channels`, or user preferences.
147-
148102
## Custom Frequencies
149103

150104
Add custom email frequencies:

docs/preferences.md

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## User Preferences
22

3-
By default, users receive notifications based on the channel defaults configured for each notification type and channel. Users can then customize their preferences by explicitly enabling or disabling specific channels for each notification type.
3+
By default, users receive notifications based on the channel defaults configured for each notification type and channel (see [customizing.md](https://github.com/loopwerk/django-generic-notifications/tree/main/docs/customizing.md)). Users can then customize their preferences by explicitly enabling or disabling specific channels for each notification type.
44

55
The system supports both:
66

@@ -47,22 +47,6 @@ CommentNotification.enable_channel(user=user, channel=EmailChannel)
4747
# Check which channels are enabled for a user
4848
enabled_channels = CommentNotification.get_enabled_channels(user)
4949

50-
# Set frequency preference directly in the database
51-
NotificationFrequencyPreference.objects.update_or_create(
52-
user=user,
53-
notification_type=CommentNotification.key,
54-
defaults={'frequency': RealtimeFrequency.key}
55-
)
56-
```
57-
58-
### How defaults work
59-
60-
The system determines which channels are enabled using this priority order:
61-
62-
1. **Forbidden channels** - Always disabled (defined in `NotificationType.forbidden_channels`)
63-
2. **Required channels** - Always enabled (defined in `NotificationType.required_channels`)
64-
3. **User preferences** - Explicit user choices stored in `NotificationTypeChannelPreference`
65-
4. **NotificationType defaults** - Per-type defaults (defined in `NotificationType.default_channels`)
66-
5. **Channel defaults** - Global defaults (defined in `BaseChannel.enabled_by_default`)
67-
68-
This allows for flexible configuration where notification types can have different default behaviors while still allowing user customization.
50+
# Change to realtime frequency for a notification type
51+
CommentNotification.set_frequency(user=user, frequency=RealtimeFrequency)
52+
```

0 commit comments

Comments
 (0)