Permalink
Browse files

Restructured the code a little to allow backends to know their label …

…and handle their own spam_sensitivity.
  • Loading branch information...
1 parent 62e90a4 commit fac857ba494e5b75fe923f553e2318d814274723 @brosner brosner committed Jan 7, 2009
Showing with 14 additions and 11 deletions.
  1. +1 −1 notification/backends/__init__.py
  2. +3 −0 notification/backends/base.py
  3. +3 −1 notification/backends/email.py
  4. +7 −9 notification/models.py
View
2 notification/backends/__init__.py
@@ -19,5 +19,5 @@ 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)())
+ backends.append(label, getattr(backend_mod, backend_class)(label))
return dict(backend_list)
View
3 notification/backends/base.py
@@ -5,6 +5,9 @@ class BaseBackend(object):
"""
The base backend.
"""
+ def __init__(self, label):
+ self.label = label
+
def can_send(self, user, notice_type):
"""
Determines whether this backend is allowed to send a notification to
View
4 notification/backends/email.py
@@ -19,8 +19,10 @@
class EmailBackend(backends.BaseBackend):
+ spam_sensitivity = 2
+
def can_send(self, user, notice_type):
- if should_send(user, notice_type, "1") and user.email:
+ if should_send(user, notice_type, self.label) and user.email:
return True
return False
View
16 notification/models.py
@@ -56,15 +56,13 @@ class Meta:
verbose_name_plural = _("notice types")
NOTIFICATION_BACKENDS = backends.load_backends()
-NOTICE_MEDIA = tuple(
- ((i, backend_label) for i, backend_label in enumerate(NOTIFICATION_BACKENDS.keys()))
-)
-
-# how spam-sensitive is the medium
-# TODO: fix this with the backends
-NOTICE_MEDIA_DEFAULTS = {
- "1": 2 # email
-}
+
+NOTICE_MEDIA = []
+NOTICE_MEDIA_DEFAULTS = {}
+for i, items in enumerate(NOTIFICATION_BACKENDS.items()):
+ backend_label, backend = items
+ NOTICE_MEDIA.append((i, backend_label))
+ NOTICE_MEDIA_DEFAULTS[backend_label] = backend.spam_sensitivity
class NoticeSetting(models.Model):
"""

0 comments on commit fac857b

Please sign in to comment.