Permalink
Browse files

pluggable-backends: Implemented backend loading from settings.

  • Loading branch information...
1 parent b997164 commit 3df0787717a5d15bdcdd11878ea119943e879b0d @brosner brosner committed May 31, 2008
Showing with 25 additions and 3 deletions.
  1. +17 −0 notification/backends/__init__.py
  2. +8 −3 notification/models.py
@@ -1,2 +1,19 @@
+from django.conf import settings
+from django.core import exceptions
+
from base import BaseBackend
+
+def load_backends():
+ backends = []
+ for label, backend_path in getattr(settings, "NOTIFICATION_BACKENDS", tuple()):
+ dot = backend_path.rindex('.')
+ backend_mod, backend_class = backend_path[:dot], backend_path[dot+1:]
+ try:
+ mod = __import__(backend_mod, {}, {}, [""])
+ except ImportError, e:
+ raise exceptions.ImproperlyConfigured, 'Error importing notification backend %s: "%s"' % (backend_mod, e)
+ # add the backend label and an instaniated backend class to the
+ # backends list.
+ backends.append(label, getattr(backend_mod, "")())
+ return dict(backend_list)
View
@@ -11,6 +11,8 @@
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import ugettext
+from notification import backends
+
class NoticeType(models.Model):
@@ -31,12 +33,13 @@ class Meta:
verbose_name = _("notice type")
verbose_name_plural = _("notice types")
-# if this gets updated, the create() method below needs to be as well...
-NOTICE_MEDIA = (
- ("1", _("Email")),
+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
}
@@ -244,6 +247,8 @@ def send(users, notice_type_label, message_template, object_list=None, issue_not
This is intended to be how other apps create new notices.
"""
+ backends = NOTIFICATION_BACKENDS.values()
+
notice_type = NoticeType.objects.get(label=notice_type_label)
message = encode_message(message_template, object_list)

0 comments on commit 3df0787

Please sign in to comment.