Skip to content

Commit 5b973d3

Browse files
committed
Clean up docs
1 parent 748a9f4 commit 5b973d3

File tree

2 files changed

+48
-112
lines changed

2 files changed

+48
-112
lines changed

docs/customizing.md

Lines changed: 44 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,80 @@ 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.channels import EmailChannel
32+
33+
@register
34+
class SecurityAlert(NotificationType):
35+
key = "security_alert"
36+
name = "Security Alerts"
37+
description = "Important security notifications"
38+
required_channels = [EmailChannel] # Cannot be disabled
39+
```
40+
41+
## Forbidden Channels
2442

25-
Control which channels are enabled by default for different notification types and channels.
43+
Prevent certain channels from being used for specific notification types:
44+
45+
```python
46+
from generic_notifications.channels import SMSChannel, WebsiteChannel
47+
48+
@register
49+
class CommentReceivedNotification(NotificationType):
50+
key = "comment_received"
51+
name = "Comment received"
52+
description = "You received a comment"
53+
forbidden_channels = [SMSChannel] # Never send via SMS
54+
```
55+
56+
Forbidden channels take highest priority - they cannot be enabled even if specified in `default_channels`, `required_channels`, or user preferences.
57+
58+
## Defaults Channels
59+
60+
By default all channels are enabled for all users, and for all notifications types. Control which channels are enabled by default.
2661

2762
### Per-Channel Defaults
2863

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

3166
```python
3267
@register
3368
class SMSChannel(BaseChannel):
3469
key = "sms"
3570
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
4471
supports_realtime = True
72+
supports_digest = False
73+
enabled_by_default = False # Opt-in only - users must explicitly enable
4574
```
4675

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

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

5380
```python
5481
@register
5582
class MarketingEmail(NotificationType):
5683
key = "marketing"
5784
name = "Marketing Updates"
58-
# Only enable email by default, disable website notifications
85+
# Only enable email by default
86+
# (users can still opt-in to enable other channels)
5987
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]
6788
```
6889

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-
7190
### Priority Order
7291

7392
The system determines enabled channels in this priority order:
7493

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

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-
148100
## Custom Frequencies
149101

150102
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)