Skip to content

Commit

Permalink
Allow the user to define spam_sensitivity overrides for backends.
Browse files Browse the repository at this point in the history
  • Loading branch information
brosner committed Jan 7, 2009
1 parent 9504ea4 commit 94f0e39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 10 additions & 2 deletions notification/backends/__init__.py
Expand Up @@ -8,7 +8,14 @@

def load_backends():
backends = []
for label, backend_path in getattr(settings, "NOTIFICATION_BACKENDS", tuple()):
for bits in getattr(settings, "NOTIFICATION_BACKENDS", tuple()):
if len(bits) == 2:
label, backend_path = bits
spam_sensitivity = None
elif len(bits) == 3:
label, backend_path, spam_sensitivity = bits
else:
raise exceptions.ImproperlyConfigured, "NOTIFICATION_BACKENDS does not contain enough data."
dot = backend_path.rindex(".")
backend_mod, backend_class = backend_path[:dot], backend_path[dot+1:]
try:
Expand All @@ -19,5 +26,6 @@ def load_backends():
raise exceptions.ImproperlyConfigured, 'Error importing notification backend %s: "%s"' % (backend_mod, e)
# add the backend label and an instantiated backend class to the
# backends list.
backends.append(label, getattr(backend_mod, backend_class)(label))
backend_instance = getattr(backend_mod, backend_class)(label, spam_sensitivity)
backends.append(label, backend_instance)
return dict(backend_list)
4 changes: 3 additions & 1 deletion notification/backends/base.py
Expand Up @@ -5,8 +5,10 @@ class BaseBackend(object):
"""
The base backend.
"""
def __init__(self, label):
def __init__(self, label, spam_sensitivity=None):
self.label = label
if spam_sensitivity is not None:
self.spam_sensitivity = spam_sensitivity

def can_send(self, user, notice_type):
"""
Expand Down

0 comments on commit 94f0e39

Please sign in to comment.